QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#870043#7436. Optimal Ordered Problem SolverMirasycle0 2932ms125220kbC++144.8kb2025-01-25 14:32:522025-01-25 14:33:54

Judging History

你现在查看的是最新测评结果

  • [2025-01-25 14:33:54]
  • 评测
  • 测评结果:0
  • 用时:2932ms
  • 内存:125220kb
  • [2025-01-25 14:32:52]
  • 提交

answer

#include<bits/stdc++.h>
#define pb emplace_back
#define fi first
#define se second
#define mp make_pair
using namespace std;
typedef long long ll;
const int maxn=1e6+10;
const int V=1e6;
void cmax(int &x,int y){ x=x>y?x:y; }
void cmin(int &x,int y){ x=x<y?x:y; }
struct BST{
	struct node{
		int r,s,ls,rs,tx,ty; pair<int,int> val;
		#define val(x) tree[x].val
		#define s(x) tree[x].s
		#define ls(x) tree[x].ls
		#define rs(x) tree[x].rs
		#define r(x) tree[x].r
		#define tx(x) tree[x].tx
		#define ty(x) tree[x].ty
	}tree[maxn]; int tot,root;
	void init(){ tot=root=0; val(0)=mp(0,0); }
	void pushup(int p){ s(p)=s(ls(p))+s(rs(p)); }
	int New(pair<int,int> v){
		int p=++tot; s(p)=1; 
		ls(p)=rs(p)=0; val(p)=v; 
		r(p)=rand(); return p;
	}
	void pushdown(int p){
		if(tx(p)){
			if(ls(p)) val(ls(p)).fi=tx(ls(p))=tx(p);
			if(rs(p)) val(rs(p)).fi=tx(rs(p))=tx(p);
		}
		if(ty(p)){
			if(ls(p)) val(ls(p)).se=ty(ls(p))=ty(p);
			if(rs(p)) val(rs(p)).se=ty(rs(p))=ty(p);
		}
		tx(p)=ty(p)=0;
	}
	void split(int p,pair<int,int> k,int& x,int& y){
		if(!p){ x=y=0; return ;	 }
		pushdown(p);
		if(val(p)<=k) x=p,split(rs(p),k,rs(p),y); 
		else y=p,split(ls(p),k,x,ls(p));
		pushup(p);
	}
	void splitY(int p,int k,int &x,int& y){
		if(!p){ x=y=0; return ;	 }
		pushdown(p);
		if(val(p).se<=k) x=p,splitY(rs(p),k,rs(p),y); 
		else y=p,splitY(ls(p),k,x,ls(p));
		pushup(p);		
	}
	int merge(int p,int q){
		if(!p||!q) return p+q;
		pushdown(p); pushdown(q);
		if(r(p)<r(q)){
			ls(q)=merge(p,ls(q)); 
			pushup(q); return q;
		}else{
			rs(p)=merge(rs(p),q);
			pushup(p); return p;
		}
	}
	void ins(pair<int,int> v){
		int x=0,y=0; split(root,v,x,y);
		root=merge(merge(x,New(v)),y);
	}
	void upd(int o,int X,int Y){
		int x=0,y=0,z=0;
		split(root,mp(X,0),x,z);
		splitY(x,-(Y+1),x,y);
		if(o==1) val(y).se=Y,ty(y)=Y;
		else val(y).fi=X,tx(y)=X;
		root=merge(x,merge(y,z));
	}
}t;
int n,m,tim[maxn],c[maxn],ans[maxn],b[maxn<<1];
struct BIT{
	int c[maxn];
	void init(int z){ for(int i=1;i<=V;i++) c[i]=z; }
	int lowbit(int x){ return x&-x; }
	void modify(int x,int v){ for(;x;x-=lowbit(x)) cmin(c[x],v); }
	void modify2(int x,int v){ for(;x;x-=lowbit(x)) cmax(c[x],v); }
	int sufmin(int x){ int res=m+1; for(;x<=V;x+=lowbit(x)) cmin(res,c[x]); return res; }
	int sufmax(int x){ int res=0; for(;x<=V;x+=lowbit(x)) cmax(res,c[x]); return res; }
	void add(int x,int v){ for(;x;x-=lowbit(x)) c[x]+=v; }
	int query(int x){ int res=0; for(;x<=V;x+=lowbit(x)) res+=c[x]; return res; }
}t1,t2;
struct node{
	int x,y;
}a[maxn]; vector<int> vec[maxn]; 
struct Q{
	int o,x,y,X,Y;
}q[maxn];
int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin>>n>>m; t.init();
	for(int i=1;i<=n;i++) cin>>a[i].x>>a[i].y,c[a[i].x]++;
	for(int i=1;i<=m;i++) cin>>q[i].o>>q[i].x>>q[i].y>>q[i].X>>q[i].Y,c[q[i].x]++;
	//计算进入时间 tim
	for(int i=1;i<=V;i++) c[i]+=c[i-1]; t1.init(m+1);
	for(int i=1;i<=m;i++) b[c[q[i].x]--]=i;
	for(int i=1;i<=n;i++) b[c[a[i].x]--]=i+m;
	for(int i=n+m;i>=1;i--){
		if(b[i]<=m) t1.modify(q[b[i]].y,b[i]);
		else tim[b[i]-m]=t1.sufmin(a[b[i]-m].y);
	}
	//二维偏序 (x,t) (y,t) 注意 t,x,y 需要严格大于 
	memset(c,0,sizeof(c));
	for(int i=1;i<=n;i++) c[tim[i]]++;
	for(int i=1;i<=m;i++) c[i]+=c[i-1]+1; c[m+1]+=c[m];
	for(int i=1;i<=m;i++) b[c[i]--]=i;
	for(int i=1;i<=n;i++) b[c[tim[i]]--]=i+m;
	t1.init(0); t2.init(0);
	for(int i=n+m;i>=1;i--){
		if(b[i]<=m) ans[b[i]]-=t1.query(q[b[i]].X+1),ans[b[i]]-=t2.query(q[b[i]].Y+1);
		else t1.add(a[b[i]-m].x,1),t2.add(a[b[i]-m].y,1);
	}
//	for(int i=1;i<=n;i++) cout<<"A "<<ans[i]<<endl;
	//二维偏序 (x,y) 还是需要严格大于 
	memset(c,0,sizeof(c));
	for(int i=1;i<=n;i++) c[a[i].x]++;
	for(int i=1;i<=m;i++) c[q[i].X]++;
	for(int i=1;i<=V;i++) c[i]+=c[i-1]; t1.init(0); 
	for(int i=1;i<=m;i++) b[c[q[i].X]--]=i;
	for(int i=1;i<=n;i++) b[c[a[i].x]--]=i+m;
	for(int i=n+m;i>=1;i--){
		if(b[i]<=m) ans[b[i]]+=n+t1.query(q[b[i]].Y+1);
		else t1.add(a[b[i]-m].y,1);
	}
//	for(int i=1;i<=n;i++) cout<<"A "<<ans[i]<<endl;
	//按照时间序维护轮廓线 查询 
	//同时需要维护当前轮廓线的范围,树状数组维护每个 x 对应的 y 即可 就是后缀max 
	for(int i=1;i<=n;i++) vec[tim[i]].pb(i); t1.init(0);
	for(int i=1;i<=m;i++){
		//加入平衡树中
		t1.modify2(q[i].x,q[i].y);
		t.upd(q[i].o,q[i].x,q[i].y);//修改
		for(auto z:vec[i]){
			if(q[i].o==1) t.ins(mp(a[z].x,q[i].y)); 
			else t.ins(mp(q[i].x,a[z].x)); 
		}
		//查询
		if(q[i].Y<t1.sufmax(q[i].X)){ ans[i]=0; continue; }
		int x=0,y=0;
		t.splitY(t.root,-(q[i].Y+1),x,y);
		ans[i]-=t.s(x);
		t.root=t.merge(x,y); x=y=0;
		t.split(t.root,mp(q[i].X+1,0),x,y);
		ans[i]-=t.s(y);
		t.root=t.merge(x,y); 
	}
	for(int i=1;i<=m;i++) cout<<ans[i]<<"\n"; 
	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: 7ms
memory: 76780kb

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
370
872
782
734
174
660
467
76
754
77
5
144
974
526
415
439
694
507
577
258
120
243
9
8
319
313
498
218
828
433
623
981
700
120
55
70
499
375
283
387
128
317
139
220
410
22
547
20
385
430
168
38
0
178
625
677
561
488
672
577
64
144
537
235
6...

result:

wrong answer 26th numbers differ - expected: '3', found: '5'

Subtask #2:

score: 0
Wrong Answer

Test #9:

score: 0
Wrong Answer
time: 1461ms
memory: 118288kb

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
953730
0
0
859562
0
0
0
0
776333
0
0
0
0
883717
0
0
0
0
0
0
899232
0
0
0
0
0
0
0
0
0
0
0
896479
0
0
892545
0
0
0
0
907449
0
0
0
892956
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
898541
788810
0
0
0
0
0
0
891526
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
903499
0
0
0
0
0
0
0
914433
0
0
...

result:

wrong answer 6th numbers differ - expected: '512663', found: '859562'

Subtask #3:

score: 0
Wrong Answer

Test #17:

score: 0
Wrong Answer
time: 2932ms
memory: 125220kb

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
633545
123521
313579
450015
383638
574188
2378
203701
326075
117994
567277
652826
199783
380319
380379
105882
373861
788346
703180
609805
648165
367068
497984
57990
478851
745058
75946
543070
251847
769828
436497
480976
235845
509633
757192
763494
396852
262690
2262
267186
165800
558973
16525...

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%