玄关
  • 板块灌水区
  • 楼主Fu_xuan_
  • 当前回复1
  • 已保存回复1
  • 发布时间2024/8/9 20:28
  • 上次更新2024/8/9 20:38:24
查看原帖
玄关
1288007
Fu_xuan_楼主2024/8/9 20:28

玄不知道几关,但不少

全wa,不知道哪里错了 https://www.luogu.com.cn/problem/P2184

#include<bits/stdc++.h>
using namespace std;

const int maxn=3e5+30;

int tree1[maxn],tree2[maxn];
int n,m,N=1; 

void upd(int l,int r){
	for(l+=N;l;l>>=1){
		tree1[l]++;
	}
	for(r+=N;r;r>>=1){
		tree2[r]++;
	}
}

int que(int l,int r){
	
	int ans1=0,ans2=0,i;
	
	for(i=N,l+=N+1;l^i^1;l>>=1,i>>=1){
		if(i&1){
			ans1+=tree2[i^1];
		}
		if(l&1){
			ans1+=tree2[l^1];
		}
	}
	
	for(i=N,r+=N+1;r^i^1;r>>=1,i>>=1){
		if(i&1){
			ans2+=tree1[i^1];
		}
		if(r&1){
			ans2+=tree1[r^1];
		}
	}
	
	return ans2-ans1;
}

int main(){
	
	cin>>n>>m;
	
	while(N<=n+1)N<<=1;
	for(int i=1;i<=m;i++){
		int op,x,y;
		cin>>op>>x>>y;
		if(op==1)upd(x,y);
		if(op==2)cout<<que(x,y)<<endl;
	}
	
	return 0;
}
2024/8/9 20:28
加载中...