QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#645499#8949. 赫露艾斯塔DaiRuiChen0070 3772ms148840kbC++174.7kb2024-10-16 18:45:092024-10-16 18:45:10

Judging History

This is the latest submission verdict.

  • [2024-10-16 18:45:10]
  • Judged
  • Verdict: 0
  • Time: 3772ms
  • Memory: 148840kb
  • [2024-10-16 18:45:09]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
namespace IO {
int ow,olim=(1<<23)-100;
char buf[1<<21],*p1=buf,*p2=buf,obuf[1<<23];
#define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
int read() {
	int x=0; char c=gc();
	while(!isdigit(c)) c=gc();
	while(isdigit(c)) x=x*10+(c^48),c=gc();
	return x;
}
void flush() {
	fwrite(obuf,ow,1,stdout),ow=0;
}
void write(int x) {
	if(!x) obuf[ow++]='0';
	else {
		int t=ow;
		for(;x;x/=10) obuf[ow++]=(x%10)^48;
		reverse(obuf+t,obuf+ow);
	}
	if(ow>=olim) flush();
}
void putc(char c) {
	obuf[ow++]=c;
	if(ow>=olim) flush();
}
#undef gc
}
const int MAXN=1e6+5;
inline void chkmin(int &x,const int &y) { x=x<y?x:y; }
inline void chkmax(int &x,const int &y) { x=x>y?x:y; }
mt19937 rnd(time(0));
struct Treap {
	int x[MAXN],y[MAXN],tx[MAXN],ty[MAXN],pri[MAXN],ls[MAXN],rs[MAXN],siz[MAXN];
	inline void psd(const int &p) {
		if(tx[p]) x[ls[p]]=tx[ls[p]]=x[rs[p]]=tx[rs[p]]=tx[p],tx[p]=0;
		if(ty[p]) y[ls[p]]=ty[ls[p]]=y[rs[p]]=ty[rs[p]]=ty[p],ty[p]=0;
	}
	void splix(int p,const int &k,int &u,int &v) {
		if(!p) return u=v=0,void();
		psd(p);
		if(x[p]<=k) u=p,splix(rs[p],k,rs[p],v);
		else v=p,splix(ls[p],k,u,ls[p]);
		siz[p]=siz[ls[p]]+siz[rs[p]]+1;
	}
	void spliy(int p,const int &k,int &u,int &v) {
		if(!p) return u=v=0,void();
		psd(p);
		if(y[p]>=k) u=p,spliy(rs[p],k,rs[p],v);
		else v=p,spliy(ls[p],k,u,ls[p]);
		siz[p]=siz[ls[p]]+siz[rs[p]]+1;
	}
	void spliz(int p,const int &k,int &u,int &v) {
		if(!p) return u=v=0,void();
		psd(p);
		if(x[p]-y[p]<=k) u=p,spliz(rs[p],k,rs[p],v);
		else v=p,spliz(ls[p],k,u,ls[p]);
		siz[p]=siz[ls[p]]+siz[rs[p]]+1;
	}
	int merge(int u,int v) {
		if(!u||!v) return u|v;
		psd(u),psd(v);
		if(pri[u]<pri[v]) return siz[u]+=siz[v],rs[u]=merge(rs[u],v),u;
		else return siz[v]+=siz[u],ls[v]=merge(u,ls[v]),v;
	}
	inline int szx(int p,const int &k) {
		if(!p) return 0;
		psd(p);
		if(x[p]<=k) return siz[ls[p]]+1+szx(rs[p],k);
		return szx(ls[p],k);
//		int ans=0;
//		while(p) {
//			psd(p);
//			if(x[p]>k) p=ls[p];
//			else ans+=siz[ls[p]]+1,p=rs[p];
//		}
//		return ans;
	}
	inline int szy(int p,const int &k) {
		if(!p) return 0;
		psd(p);
		if(y[p]>=k) return siz[ls[p]]+1+szy(rs[p],k);
		return szy(ls[p],k);
//		int ans=0;
//		while(p) {
//			psd(p);
//			if(y[p]<k) p=ls[p];
//			else ans+=siz[ls[p]]+1,p=rs[p];
//		}
//		return ans;
	}
}	T;
int n,m,ax[MAXN],ay[MAXN],ux[MAXN],uy[MAXN],qx[MAXN],qy[MAXN],op[MAXN],ans[MAXN];
struct poi {
	int x,y,id;
	inline friend bool operator <(const poi &u,const poi &v) {
		return u.x^v.x?u.x>v.x:u.id>v.id;
	}
};
vector <int> ins[MAXN];
struct Bit1 {
	int tr[MAXN],s;
	void init() { fill(tr+1,tr+n+1,m+1); }
	inline void upd(int x,const int &v) { for(;x;x&=x-1) chkmin(tr[x],v); }
	inline int qry(int x) { for(s=m+1;x<=n;x+=x&-x) chkmin(s,tr[x]); return s; }
}	Tmn;
struct Bit2 {
	int tr[MAXN],s;
	inline void upd(int x,const int &v) { for(;x;x&=x-1) chkmax(tr[x],v); }
	inline int qry(int x) { for(s=0;x<=n;x+=x&-x) chkmax(s,tr[x]); return s; }
}	Tmx;
struct Bit3 {
	int tr[MAXN],s;
	inline void add(int x,const int &v) { for(;x;x&=x-1) tr[x]+=v; }
	inline int qry(int x) { for(s=0;x<=n;x+=x&-x) s+=tr[x]; return s; }
}	To,Tx,Ty;
signed main() {
	n=IO::read(),m=IO::read();
	vector <poi> Q;
	for(int i=1;i<=n;++i) ax[i]=IO::read(),ay[i]=IO::read(),Q.push_back({ax[i],ay[i],i});
	for(int i=1;i<=m;++i) {
		op[i]=IO::read(),ux[i]=IO::read(),uy[i]=IO::read();
		qx[i]=IO::read(),qy[i]=IO::read();
		Q.push_back({ux[i],uy[i],i+n});
	}
	sort(Q.begin(),Q.end());
	Tmn.init();
	for(auto o:Q) {
		if(o.id>n) Tmn.upd(o.y,o.id-n);
		else ins[Tmn.qry(o.y)].push_back(o.id);
	}
	Q.clear();
	for(int i=1;i<=n;++i) Q.push_back({ax[i],ay[i],i});
	for(int i=1;i<=m;++i) Q.push_back({qx[i],qy[i],i+n});
	sort(Q.begin(),Q.end());
	for(auto o:Q) {
		if(o.id>n) ans[o.id-n]=To.qry(o.y+1);
		else To.add(o.y,1);
	}
	for(int i=1;i<=n;++i) Tx.add(ax[i],1),Ty.add(ay[i],1);
	int rt=0;
	for(int i=1,ot=n;i<=m;++i) {
		int u,o1,o2,o3;
		T.splix(rt,ux[i],o1,o2);
		T.spliy(o1,uy[i]+1,o3,u);
		if(op[i]==2) T.x[u]=T.tx[u]=ux[i];
		else T.y[u]=T.ty[u]=uy[i];
		rt=T.merge(T.merge(o3,u),o2);
		for(int j:ins[i]) {
			Tx.add(ax[j],-1),Ty.add(ay[j],-1),--ot;
			op[i]==2?ax[j]=ux[i]:ay[j]=uy[i];
			T.spliz(rt,ax[j]-ay[j],o1,o2);
			T.x[j]=ax[j],T.y[j]=ay[j],T.pri[j]=rnd(),T.siz[j]=1;
			rt=T.merge(T.merge(o1,j),o2);
		}
		Tmx.upd(ux[i],uy[i]);
		if(Tmx.qry(qx[i]+1)>qy[i]) { IO::putc('0'),IO::putc('\n'); continue; }
		ans[i]+=ot+T.szx(rt,ux[i])-T.szy(rt,uy[i]+1);
		ans[i]-=Tx.qry(qx[i]+1)+Ty.qry(qy[i]+1);
		IO::write(ans[i]),IO::putc('\n');
	}
	IO::flush();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 4ms
memory: 52968kb

input:

995 996
950 481
376 18
141 776
711 966
130 727
468 529
47 39
857 563
832 821
776 472
154 914
825 279
332 415
470 361
968 440
45 560
299 755
703 785
744 387
547 382
3 549
344 573
778 424
784 765
280 115
251 434
695 98
463 506
379 38
610 486
305 623
703 244
856 365
117 360
772 847
331 723
663 991
900 ...

output:

423
473
758
313
694
232
333
784
821
154
247
244
504
54
200
368
870
780
734
172
656
465
74
752
73
1
140
974
522
413
439
690
507
572
257
117
240
5
2
316
306
491
215
825
424
617
978
691
116
43
62
487
367
275
375
124
305
126
208
397
9
533
9
372
413
152
22
0
162
610
662
544
482
655
560
52
132
526
227
43
...

result:

wrong answer 16th numbers differ - expected: '370', found: '368'

Subtask #2:

score: 0
Wrong Answer

Test #9:

score: 0
Wrong Answer
time: 1729ms
memory: 144120kb

input:

999996 999996
921339 140126
955508 363759
958698 342406
280137 955674
907511 75721
189876 946586
152058 168837
541857 557702
84498 865987
185574 809224
704828 701026
815379 548000
989515 518951
335439 336866
745570 790616
766723 212893
926629 859003
51261 40866
592510 556235
324926 700261
320946 798...

output:

0
0
803382
0
0

result:

wrong answer 3rd numbers differ - expected: '953730', found: '803382'

Subtask #3:

score: 0
Wrong Answer

Test #17:

score: 0
Wrong Answer
time: 3772ms
memory: 148840kb

input:

999995 999997
261379 334440
985281 986034
549380 718157
670003 253925
533027 437989
326806 983213
965935 756259
229069 686789
331338 684961
957559 390618
937820 959719
338153 779814
582581 965418
634156 421264
308778 938878
913059 390904
481477 431492
739774 793015
901442 934600
256704 991485
366691...

output:

160637
633543
123518
313576
450012
383635
574183
2373
203699
326070
117989
567271
652818
199775
380311
380369
105873
373851
788335
703169
609791
648152
367053
497968
57977
478838
745044
75930
543052
251829
769810
436479
480958
235826
509615
757171
763474
396830
262671
2241
267163
165776
558946
16523...

result:

wrong answer 1st numbers differ - expected: '160635', found: '160637'

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Skipped

Dependency #1:

0%