几乎就是纯树状数组(区域间修改,单点查询)模板了(详细分析看上一篇发布的文章,就在上一条,有空就看一下吧~)
话不多说,上!
ACcode:
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e7+10;
int n,m,q,in[N],tr[N];
int lowbit(int num) {
return num&-num;
}
void add(int s,int num) {
for(int i=s; i<=n; i+=lowbit(i))tr[i]+=num;
}
int ask(int s) {
int ans=0;
for(int i=s; i>=1; i-=lowbit(i))ans+=tr[i];
return ans;
}
void solve() {
cin>>n>>q;
//for(int i=1; i<=n; i++) cin>>in[i];
while(q--) {
int op;
cin>>op;
if(op==0) {
int x,y;
cin>>x>>y;
add(x,1);//差分
add(y+1,-1);
} else {
int x;
cin>>x;
cout<<ask(x)<<"\n";
}
}
}
signed main() {
ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
int t=1;
// cin>>t;
while(t--) {
solve();
}
return 0;
}
over~