Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int N,M,K,a,b,c;
- long long BIT[200001],Auxiliary[200001];
- void Update(long long* Tree,int Index,int Value)
- {
- for(;Index<=N;Index+=Index&-Index)
- cout<<Index<<endl,Tree[Index]+=Value;
- return;
- }
- long long CumulativeSum(long long* Tree,int Index)
- {
- long long ret=0;
- for(;Index>0;Index-=Index&-Index)
- ret+=Tree[Index];
- return ret;
- }
- long long RangeQuery(int Index)
- {
- return CumulativeSum(BIT,Index)*Index-CumulativeSum(Auxiliary,Index);
- }
- /// Trying to implement the idea of http://kartikkukreja.wordpress.com/2013/12/02/range-updates-with-bit-fenwick-tree/
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin>>N>>M>>K;
- for(int i=1;i<=N;i++)
- {
- cin>>c;
- Update(BIT,i,c); // Maybe I have Mistaken Here
- }
- for(int i=1;i<=M;i++)
- {
- cin>>a>>b>>c;
- Update(BIT,a,c);
- Update(BIT,b+1,-c);
- Update(Auxiliary,a,c*(a-1));
- Update(Auxiliary,b+1,-c*b);
- }
- for(int i=0;i<K;i++)
- {
- cin>>a>>b;
- cout<<RangeQuery(b)-RangeQuery(a-1)<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement