一直输出0,求调
查看原帖
一直输出0,求调
925129
lzdll楼主2023/10/3 18:52

#include<map>
#include<cmath>
#include<queue>
#include<stack>
#include<string>
#include<cstdio>
#include<vector>
#include<iomanip>
#include<cstring>
#include<iostream>
#include<algorithm>
#undef max
#undef min
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define CLOSE std::ios::sync_with_stdio(0);
using namespace std;
#define int long long
#define lo (nw<<1)
#define ro (nw<<1|1)
#define md ((l+r)>>1)
#define R(x) x=read()
inline int read() {
	int x=0,f=1;
	char ch=getchar();
	while (!isdigit(ch)) {
		if (ch=='-') f=-1;
		ch=getchar();
	}
	while (isdigit(ch)) {
		x=x*10+ch-48;
		ch=getchar();
	}
	return x*f;
}
struct st {
	int sm[500005];
	void bld(int nw,int l,int r) {
		if(l==r) {
			sm[nw]=0;
			return ;
		}
		bld(lo,l,md);
		bld(ro,md+1,r);
		upd(nw);
	}
	void upd(int nw) {
		sm[nw]=sm[lo]+sm[ro];
	}
	void chg(int nw,int l,int r,int x) {
		if(l==r) {
			sm[x]=sm[x]^1;
			return ;
		}
		if(x<=md) {
			chg(lo,l,md,x);
		} else {
			chg(ro,md+1,r,x);
		}
		upd(nw);
	}
	int qry(int nw,int l,int r,int x,int y) {
		if(x<=l&&r<=y) {
			cout<<sm[nw]<<endl;
			return sm[nw];
		}
		int as=0;
		if(x<=md)as+=qry(lo,l,md,x,y);
		if(y>md)as+=qry(ro,md+1,r,x,y);
		return as;
	}
} stx,sty;
int n,m,q;
int op;
signed main() {
	R(n),R(m),R(q);
	stx.bld(1,1,n);
	sty.bld(1,1,m);
	while(q--) {
		R(op);
		if(op==1) {
			int x,y;
			R(x),R(y);
			stx.chg(1,1,n,x);
			sty.chg(1,1,m,y);
		} else {
			int X1,X2,Y1,Y2;
			R(X1),R(Y1),R(X2),R(Y2);
			int t1=stx.qry(1,1,n,X1,X2),t2=sty.qry(1,1,m,Y1,Y2);
//			cout<<t1<<" "<<t2<<endl;
			int as=t1*(Y2-Y1+1)+t2*(X2-X1+1)-2ll*t1*t2;
			cout<<as<<endl;
		}
	}
	return 0;
}
2023/10/3 18:52
加载中...