编程介的小学生 2019-06-03 14:58 采纳率: 0.4%
浏览 148

公式计算推导出2333333,怎么使用C语言的程序的代码编写的过程步骤去实现的问题解决

Problem Description
You are given a strange problem. First you have got a sequence contains N integers A1,A2,A3,...AN.Then you should perform a sequence of M operations. An operation can be one of the following:

  1. Print operation l,r . Print the value of ∑i=lrAi.
  2. Modify operation x. Modify Ax to 2Ax
  3. Add operation l,r,x. Add xtoAi(l≤i≤r).

As the value of print operation can be rather large, print the remainder after dividing the number by 2333333.

Input
There are several test cases.
In each test case:
The first line contains two integers N,M(1≤N,M≤50000).
The second line contains N integers A1,A2,A3,...AN(1≤Ai≤109,1≤i≤N)
Each of the next M lines begin with a number type(1≤type≤3).
If type=1, there will be two integers more in the line: l,r(1≤l≤r≤N), which correspond the operation 1.
If type=2, there will be one integer more in the line: x(1≤x≤N), which correspond the operation 2.
If type=3, there will be three integers more in the line: l,r,x(1≤l≤r≤N,1≤x≤109), which correspond the operation 3.

Output
For each Print operation, output the remainder of division of the value by 2333333.

Sample Input
3 4
1 2 3
2 3
1 2 3
3 1 3 2
1 1 3
2 2
5 2
2 1
1 1 2

Sample Output
10
17
34

  • 写回答

1条回答 默认 最新

  • 你知我知皆知 2024-08-10 01:29
    关注

    以下回答参考 皆我百晓生券券喵儿 等免费微信小程序相关内容作答,并由本人整理回复。

    这是一个典型的动态规划问题。我们可以将每个操作看作是前缀和的一个更新,即在操作之后,我们可以在前缀和的基础上加上或减去当前的操作值。

    首先,我们需要定义一个数组dp来存储答案。对于每一个操作,如果操作是1,则我们要考虑前缀和的变化;如果是2或者3,则直接对当前的操作值进行更新。

    接下来,我们需要遍历所有的测试用例,并根据不同的类型进行相应的处理:

    • 如果type为1,则我们需要先更新前缀和,然后根据操作值来进行求余。
    • 如果type为2,则我们需要直接对当前的操作值进行更新。
    • 如果type为3,则我们需要先更新前缀和,然后根据操作值来进行求余。

    最后,我们将答案输出即可。

    以下是可能的C++代码实现:

    #include <iostream>
    using namespace std;
    
    long long dp[10001][2333334];
    int n,m;
    long long ans;
    
    void solve(int type,int l,int r,long long val){
        if(type==1){
            for(long long i=l;i<=r;i++){
                dp[i][val%2333334]++;
            }
        }else{
            dp[l][val%2333334]++;
        }
    }
    
    int main(){
        cin>>n>>m;
        for(int i=1;i<=n;i++)cin>>ans;
        
        while(m--){
            int t;
            cin>>t;
            if(t==1){
                int l,r;
                cin>>l>>r;
                solve(1,l,r,ans);
            }else if(t==2){
                long long v;
                cin>>v;
                ans+=v;
            }else{
                long long l,r,x;
                cin>>l>>r>>x;
                solve(3,l,r,x);
            }
        }
    
        cout<<ans%2333334;
    }
    

    这个代码的时间复杂度为O(nm),空间复杂度为O(N2333334),其中N是输入中的元素个数,而2333334是题目中要求的结果。

    评论

报告相同问题?