标签:i++ query algo upd cout namespace owb void 查询
例题:https://www.luogu.org/problem/show?pid=3374
程序:
#include<iostream> #include<cstdio> #include<algorithm> using namespace std; int n,m,x,y,ch,f[600000],a[600000]; int lowbit(int x) { return (x&-x); } //单点修改 void update(int x,int k) { while (x<=n) { f[x]+=k; x+=lowbit(x); } } //单点查询 int query(int x) { int ans; 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++) { cin>>a[i]; update(i,a[i]); } for (int i=1;i<=m;i++){ cin>>ch>>x>>y; if (ch==1) update(x,y); else cout<<query(y)-query(x-1)<<endl; } }
好啦好啦。。。
标签:i++ query algo upd cout namespace owb void 查询
原文地址:http://www.cnblogs.com/2014nhc/p/6367704.html