的Ikbal有两个数组a和长度为N B,最初所有的值等于零。有的、数组、长度为、最初

2023-09-11 07:27:19 作者:°心凉不过一瞬间#

我试图来解决这个问题,下面code。但答案是不准确的所有输入。 问题陈述

I was trying to solve this problem with the following code. But the answers aren't accurate for all inputs. Problem Statement

的Ikbal有两个数组a和长度为N B,最初所有的值等于零。我们有●在使用。让我们定义这个阵列三种类型的操作:

Ikbal has two arrays a and b of length N, initially all values equals to zero. We have Q operation. Let's define three types of operations on this arrays:

1 L Rç增加人,人+ 1,...,AR为c。

1 l r c Increase al,al+1,...,ar by c.

2升R C增加BL,BL + 1,...,BR为c。

2 l r c Increase bl,bl+1,...,br by c.

3 LR打印(人* BL)+(人+ 1 * BL + 1)+ ... +(AR * BR)的模1000000007 输入格式

3 l r Print (al∗bl)+(al+1∗bl+1)+...+(ar∗br) in modulo 1000000007 Input Format

输入的第一行包含N和Q:接下来Q行包含三种类型的操作之一。

First line of the input consists of N and Q. Next Q lines contain one of the three types of operations.

限制

1≤N≤109 1≤Q≤200000 1≤c≤10000 1≤l≤r≤N 输出格式

1≤N≤109 1≤Q≤200000 1≤c≤10000 1≤l≤r≤N Output Format

每当你得到一个类型3的操作,你应该在一个新行打印了答案。

Whenever you get a type 3 operation, you should print the answer in a new line.

采样输入

5 3 1 1 5 5 2 2 4 2 3 3 4 示例输出

5 3 1 1 5 5 2 2 4 2 3 3 4 Sample Output

20 说明

在第一次手术阵列是这样的:

After first operation arrays look like this:

A = 5,5,5,5,5

a=5,5,5,5,5

B = 0,0,0,0,0 第二次手术后阵列是这样的:

b=0,0,0,0,0 After second operation arrays look like this:

A = 5,5,5,5,5

a=5,5,5,5,5

B = 0,2,2,2,0

b=0,2,2,2,0

第三操作的答案:5 * 2 + 5 * 2 = 20

Answer of the third operation: 5∗2+5∗2=20

** MY code **

**MY code **

    #include <cmath>
    #include <cstdio>
    #include <vector>
    #include <iostream>
    #include <algorithm>
    using namespace std;
    int main() {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT */
        vector<int> a,b,c;
        int n,q,r,p;
        cin >> n;
        cin >> q;
        for(int i=0;i<q;i++) {
            cin >> r;
            a.push_back(r);
            if(r==3) {
                p = 3;
            } else {
                p = 4;
            }
                for(int j=1;j<p;j++) {
                    cin >> r;
                    a.push_back(r);
                }
        }
        vector<int> aa(n,0),bb(n,0);
        int g,start,endd,val,anss=0;
        for(int i=0;i<a.size();) {
            if(a[i]==3) {
                start = a[i+1]-1;
                endd = a[i+2]-1;
                if(start==endd) {
                  anss = (aa[start]*bb[start])%1000000007;
                } else {
                anss = (aa[start]*bb[start] + aa[endd]*bb[endd])%1000000007;
                }
                cout << anss << endl;
                i+= 3;
            } else {
                start = a[i+1] - 1;
                endd = a[i+2];
                val = a[i+3];
                if(a[i]==1) {
                    for(int j=start;j<endd;j++) {
                        aa[j] += val;
                    }
                } else {
                        for(int j=start;j<endd;j++) {
                        bb[j] += val;
                    }
                }
                i+= 4;
            }
        }
    /*
        for(int i=0;i<n;i++) {
            cout << aa[i] << " " ;
            cout << bb[i] << endl;
        }
        for(int i=0;i<a.size();i++) {
            cout << a[i] << endl;
        } */
        return 0;
    }

预计输出给定输入: https://m.xsw88.com/allimgs/daicuo/20230911/3331.png.jpg

Expected output for given input : https://m.xsw88.com/allimgs/daicuo/20230911/3331.png.jpg

推荐答案

这不是一个溢出的问题。这:

It's not an overflow problem. This:

if(start==endd)
  anss = (aa[start]*bb[start])%1000000007;
else
  anss = (aa[start]*bb[start] + aa[endd]*bb[endd])%1000000007;

是平的错误。你看错了说明。

is flat wrong. You misread the instructions.