I need help!!!!!

P3374 【模板】树状数组 1

@[xun0](/space/show?uid=73733) 使用scanf
by Lstdo @ 2018-08-18 13:10:58


@[luositing](/space/show?uid=53930) 谢谢大佬,虽然不太懂原理
by xun0 @ 2018-08-18 22:24:40


#include <iostream> using namespace std; int n,m,f[2000010]; int lowbit(int i) { return i&-i; } void he(int x,int i) { while(x<=n) { f[x]+=i; x+=lowbit(x); } } int sum(int x) { int ans=0; while(x!=0) { ans+=f[x]; x-=lowbit(x); } return ans; } int main() { cin>>n>>m; for(int i=1;i<=n;i++) { int a; cin>>a; he(i,a); } for(int i=1;i<=m;i++) { int a,b,c; cin>>a>>b>>c; if(a==1) he(b,c); if(a==2) cout<<sum(c)-sum(b-1)<<endl; } }
by outofstrait @ 2018-09-16 11:31:38


其实cin也可以
by outofstrait @ 2018-09-16 11:32:12


你看看
by outofstrait @ 2018-09-16 11:32:31


|