# 10113 "one through 4.1 Example 1" sequence operation

1535: [Example 1] sequence operation


Time limit: 1000 ms Memory Limit: 262144 KB
Submissions: 690 number by: 446 

Description [title]

Given n number n columns, a predetermined operation there are two, one is a modifying element, the second is the number of columns Praying [ A , B ] [A, B] and continuous. Sequence number of elements up to 10 100 000, asks the operator maximum of 10 100 000 times.

[Enter]

The first line 2 two integers n , m n, m ( n n represents the input n number n, m m represents m m operation)

The second line n- n-integers

Subsequently m m rows, each row of three numbers K , A , B K, A, B ( K = 0 K = 0, represents the number of columns Qiuzi [ A , B A, B] and continuous; K = . 1 K = 1, represents A A plus the number of B B).

 

[Output]

Several lines represents K = 0 K = 0, the corresponding number of sub-columns [ A , B A, B] and continuous.

[Sample input]

10 5
1 2 3 4 5 6 7 8 9 10
1 1 5
0 1 3
0 4 8
1 7 5
0 4 8

[Sample Output]

11
30
35

【source】


no

 

#include<bits/stdc++.h>
using namespace std;
int s[100005];
int lowbit(int x){return x&(-x);}
int sum(int x){
    int res=0;
    while(x>0){res+=s[x];x-=lowbit(x);}
    return res;
}
int main(){
    //freopen("test.in","r",stdin);
    int n,m,k,a,b;
    scanf("%d%d",&n,&m);
    for(a=1;a<=n;a++){
        scanf("%d",&k);
        for(b=a;b<=n;b+=lowbit(b))s[b]+=k;
    }
    while(m--){
        scanf("%d%d%d",&k,&a,&b);
        if(k)
            for(;a<=n;a+=lowbit(a))s[a]+=b;
        else
            printf("%d\n",sum(b)-sum(a-1));
    }
}

 

 

 

 

Guess you like

Origin www.cnblogs.com/fdezlsq/p/11432264.html