The violent tree array is 30 points, what should I do?
Knowledge point review
in difference array
After the beginning and the end have changed the value
Find his prefix and find that all numbers in the interval change
Then we do differential tree array
#include<iostream> #include<cstdio> using namespace std; int n,m; int c[501010]; int lowbit(int x){ return x&-x; } void update(int i,int x){ while(i <= n){ c[i] += x; i += lowbit(i); } } int sum(int x) { int sum = 0; while(x){ sum += c[x]; x -= lowbit(x); } return sum; } intmain () { cin >> n >> m; int x, y, z, k; for(int i = 1;i <= n;++ i){ cin >> x; update(i,x),update(i+1,-x); } while(m-- ){ cin >> z; if(z == 2){ cin>>x; cout<<sum(x)<<"\n"; }else{ cin >> x >> y >> k; update(x, k);update(y+1, -k); } } return 0; }