树状数组15pts求助
  • 板块P4939 Agent2
  • 楼主BlachSnake
  • 当前回复3
  • 已保存回复3
  • 发布时间2021/1/22 19:34
  • 上次更新2023/11/5 04:32:45
查看原帖
树状数组15pts求助
285373
BlachSnake楼主2021/1/22 19:34
#include<bits/stdc++.h>
using namespace std;
int n,m,t[10000001],c,l,r;
int lowbit(int x){return x&-x;}
void Change(int x,int k){while(x<=n)t[x]+=k,x+=lowbit(x);}
int Query(int x){int s=0;while(x>0)s+=t[x],x-=lowbit(x);return s;}
int main(){
	ios::sync_with_stdio(0),cin.tie(0);
	cin>>n>>m;
	while(m--){
		cin>>c>>l;
		if(c==1)cout<<Query(l)<<endl;
		else cin>>r,Change(l,1);Change(r+1,-1);
	}
	return 0;
}

RT

2021/1/22 19:34
加载中...