QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#322243#7436. Optimal Ordered Problem SolverWinResearcher0 14ms47000kbC++144.1kb2024-02-06 16:39:022024-02-06 16:39:07

Judging History

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

  • [2024-02-06 16:39:07]
  • 评测
  • 测评结果:0
  • 用时:14ms
  • 内存:47000kb
  • [2024-02-06 16:39:02]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REPG(i,h,x) for(int i=h[x];~i;i=edge[i].next)
#define CLR(a,x) memset(a,x,sizeof(a))
#define pii pair<int,int>
const int INF=0x3f3f3f3f;

const int N=1e6+5;
int n,q,P[N],ans[N];
pii a[N];
vector<int> vec[N];
struct ask{int op,x,y,X,Y;}Q[N];
namespace FHQ{
	int root,cnt;
	mt19937 rnd(chrono::system_clock::now().time_since_epoch().count());
	struct node{int lc,rc,x,y,xlazy,ylazy,siz;unsigned key;}t[N];
	inline int& lc(int p){return t[p].lc;}
	inline int& rc(int p){return t[p].rc;}
	inline int newnode(int x,int y){t[++cnt]={0,0,x,y,-1,-1,1,rnd()};return cnt;}
	inline void pushup(int p){t[p].siz=t[lc(p)].siz+t[rc(p)].siz+1;}
	inline void pushX(int p,int v){t[p].x=t[p].xlazy=v;}
	inline void pushY(int p,int v){t[p].y=t[p].ylazy=v;}
	inline void pushdown(int p){
		if(t[p].xlazy!=-1) pushX(lc(p),t[p].xlazy),pushX(rc(p),t[p].xlazy);
		if(t[p].ylazy!=-1) pushY(lc(p),t[p].ylazy),pushY(rc(p),t[p].ylazy);
		t[p].xlazy=t[p].ylazy=-1;
	}
	void splitX(int p,int v,int &l,int &r){
		if(!p) return (void)(l=r=0);
		pushdown(p);
		if(t[p].x<=v) splitX(rc(l=p),v,rc(p),r);
		else splitX(lc(r=p),v,l,lc(p));
		pushup(p);
	}	
	void splitY(int p,int v,int &l,int &r){
		if(!p) return (void)(l=r=0);
		pushdown(p);
		if(t[p].y>=v) splitY(rc(l=p),v,rc(p),r);
		else splitY(lc(r=p),v,l,lc(p));
		pushup(p);
	}
	int merge(int l,int r){
		if(!l||!r) return l|r;
		pushdown(l),pushdown(r);
		if(t[l].key<t[r].key) return rc(l)=merge(rc(l),r),pushup(l),l;
		else return lc(r)=merge(l,lc(r)),pushup(r),r;
	}
	inline void add(int id){
		t[id].x=a[id].first,t[id].y=a[id].second;
		int l,mid,r;
		splitX(root,Q[id].x,l,r),splitY(l,Q[id].y,l,mid);
		root=merge(merge(l,id),merge(mid,r));
	}
};
inline int lowbit(int x){return x&(-x);}
struct BIT{
	int bit[N];
	inline void add(int x,int v){for(;x<=n;x+=lowbit(x)) bit[x]+=v;}
	inline int ask(int x){int ans=0;for(;x;x-=lowbit(x)) ans+=bit[x];return ans;}
}bit2,bit1;
struct BIT2{
	int bit[N];
	BIT2(){CLR(bit,0x3f);}
	inline void add(int x,int v){for(;x;x-=lowbit(x)) bit[x]=min(bit[x],v);}
	inline int ask(int x){int ans=INF;for(;x<=n;x+=lowbit(x)) ans=min(ans,bit[x]);return ans;}
}bitmn;
struct BIT3{
	int bit[N];
	inline void add(int x,int v){for(;x;x-=lowbit(x)) bit[x]=max(bit[x],v);}
	inline int ask(int x){int ans=0;for(;x<=n;x+=lowbit(x)) ans=max(ans,bit[x]);return ans;}
}bitmx;
int main(){
//	ios::sync_with_stdio(false);
//	cin.tie(0);
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	scanf("%d%d",&n,&q);
	for(int i=1;i<=n;i++) scanf("%d%d",&a[i].first,&a[i].second);
	for(int i=1;i<=q;i++) scanf("%d%d%d%d%d",&Q[i].op,&Q[i].x,&Q[i].y,&Q[i].X,&Q[i].Y),P[i]=i;
	sort(a+1,a+1+n),sort(P+1,P+1+q,[](int a,int b){return Q[a].x>Q[b].x;});
	for(int i=n,j=1;i>=1;i--){
		for(;j<=n&&Q[P[j]].x>=a[i].first;j++) bitmn.add(Q[P[j]].y,P[j]);
		int ret=bitmn.ask(a[i].second);
		if(ret!=INF) vec[ret].push_back(i);
	}
	sort(P+1,P+1+q,[](int a,int b){return Q[a].X>Q[b].X;});
	for(int i=1,j=n;i<=q;i++){
		for(;j>=1&&a[j].first>Q[P[i]].X;j--) bit1.add(a[j].second,1);
		ans[P[i]]=n-j-bit1.ask(Q[P[i]].Y);
	}
	CLR(bit1.bit,0);
	for(int i=1;i<=n;i++) bit1.add(a[i].first,1),bit2.add(a[i].second,1);
	for(int i=1;i<=q;i++){
		if(bitmx.ask(Q[i].x+1)<=Q[i].y){
			int l,mid,r;
			FHQ::splitX(FHQ::root,Q[i].x,l,r);//[1,x]][1,n] [x+1][1,n]
			FHQ::splitY(l,Q[i].y+1,l,mid);//[1,x][y+1,n] [1,x][1,y]
			if(Q[i].op==1) FHQ::pushY(mid,Q[i].y);
			else FHQ::pushX(mid,Q[i].x);
			FHQ::root=FHQ::merge(FHQ::merge(l,mid),r);
			bitmx.add(Q[i].x,Q[i].y);
		}
		for(auto j:vec[i]){
			bit1.add(a[j].first,-1),bit2.add(a[j].second,-1);
			if(Q[i].op==1) a[j].second=Q[i].y;
			else a[j].first=Q[i].x;
			FHQ::add(j);
		}
		if(bitmx.ask(Q[i].X+1)>Q[i].Y) ans[i]=0;
		else{
			int l,mid,r;
			FHQ::splitX(FHQ::root,Q[i].X,l,r);
			FHQ::splitY(l,Q[i].Y+1,l,mid);
			ans[i]+=bit1.ask(Q[i].X)+bit2.ask(Q[i].Y)+FHQ::t[mid].siz-n;
			FHQ::root=FHQ::merge(FHQ::merge(l,mid),r);	
			ans[i]+=FHQ::t[FHQ::root].siz;
		}
		printf("%d\n",ans[i]);
	}	
	return 0;
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 14ms
memory: 47000kb

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
3
2
319
313
498
218
828
433
623
981
700
120
55
70
499
375
283
387
128
317
139
220
410
22
547
3
385
430
168
23
0
178
625
677
561
488
672
577
64
144
537
235
45...

result:

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

Subtask #2:

score: 0
Time Limit Exceeded

Test #9:

score: 0
Time Limit Exceeded

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:


result:


Subtask #3:

score: 0
Time Limit Exceeded

Test #17:

score: 0
Time Limit Exceeded

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:

160635
633543
123519
313576
450015
383636
574186
2373
203701
326075
117994
567273
652822
199775
380316
380372
105872
373849
788346
703168
609793
648153
367055
497971
57977
478851
745046
75932
543056
251831
769828
436483
480960
235829
509617
757178
763478
396833
262674
2238
267164
165785
558953
16523...

result:


Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Skipped

Dependency #1:

0%