QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#590124#8949. 赫露艾斯塔Xun_xiaoyao0 3795ms196704kbC++144.7kb2024-09-25 21:46:192024-09-25 21:46:20

Judging History

This is the latest submission verdict.

  • [2024-09-25 21:46:20]
  • Judged
  • Verdict: 0
  • Time: 3795ms
  • Memory: 196704kb
  • [2024-09-25 21:46:19]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
int Qread()
{
	int x=0;char ch=getchar();
	while(ch<'0'||ch>'9') ch=getchar();
	while(ch>='0'&&ch<='9') x=x*10+(ch^48),ch=getchar();
	return x;
}
int n,m;
#define ls (pos<<1)
#define rs (pos<<1|1)
#define mid (l+r>>1)
struct Sege{
	int num[4000010];bool laz[4000010];
	inline void update(int pos){num[pos]=num[ls]+num[rs];}
	inline void giv_laz(int pos){num[pos]=0,laz[pos]=true;}
	inline void pushdown(int pos){if(pos[laz]) giv_laz(ls),giv_laz(rs),laz[pos]=false;}
	void range_clr(int L,int R,int pos=1,int l=1,int r=n)
	{
		if(L<=l&&r<=R) return giv_laz(pos);
		if(r<L||R<l) return;
		pushdown(pos),range_clr(L,R,ls,l,mid),range_clr(L,R,rs,mid+1,r),update(pos);
	}
	void node_add(int x,int k,int pos=1,int l=1,int r=n)
	{
		if(l==r) return num[pos]+=k,void();
		pushdown(pos);
		if(x<=mid) node_add(x,k,ls,l,mid);
		else node_add(x,k,rs,mid+1,r);
		update(pos);
	}
	int range_sum(int L,int R,int pos=1,int l=1,int r=n)
	{
		if(L<=l&&r<=R) return num[pos];
		if(r<L||R<l) return 0;
		return pushdown(pos),range_sum(L,R,ls,l,mid)+range_sum(L,R,rs,mid+1,r);
	}
}S1,S2,D1,D2;

namespace NSege{
	vector<int> nd[1000010];
	pair<int,int> s[4000010];
	inline void update(int pos){s[pos]=min(s[ls],s[rs]);}
	inline void sst(int pos,int x){s[pos]=make_pair(((!nd[x].empty())?*nd[x].rbegin():n+1),x);}
	void init(int pos=1,int l=1,int r=n)
	{
		if(l==r) sort(nd[l].begin(),nd[l].end()),sst(pos,l);
		else init(ls,l,mid),init(rs,mid+1,r),update(pos);
	}
	void del(int x,int pos=1,int l=1,int r=n)
	{
		if(l==r) return nd[x].pop_back(),sst(pos,x);
		if(x<=mid) del(x,ls,l,mid),update(pos);
		else del(x,rs,mid+1,r),update(pos);
	}
	pair<int,int> range_mn(int L,int R,int pos=1,int l=1,int r=n)
	{
		if(L<=l&&r<=R) return s[pos];
		if(R<=mid) return range_mn(L,R,ls,l,mid);
		if(mid<L) return range_mn(L,R,rs,mid+1,r);
		return min(range_mn(L,R,ls,l,mid),range_mn(L,R,rs,mid+1,r));
	}
}
#undef ls
#undef rs
#undef mid

namespace BIT{
	int num[1000010];
	void add(int x){x=n-x+1;for(;x<=n;x+=(x&-x)) num[x]++;}
	int sum(int x){int ret=0;x=n-x+1;for(;x;x-=(x&-x)) ret+=num[x];return ret;}
}

typedef pair<int,int> pr;
bool o=true;
struct cmp{
	bool operator()(pr A,pr B){
		return o?A.first<B.first:A.second>B.second;
	}
};
set<pr,cmp> S;set<pr>::iterator it,it_;
int x[1000010],y[1000010],x_,y_,X,Y;
int ans[1000010],lst;pr tmp;

vector<pr> qry[1000010];
vector<int> nd[1000010];

int main()
{
	n=Qread(),m=Qread();lst=n;
	for(int i=1;i<=n;i++)
	{
		x[i]=Qread(),y[i]=Qread();
		NSege::nd[x[i]].push_back(y[i]);nd[x[i]].push_back(y[i]);
		D1.node_add(x[i],1),D2.node_add(y[i],1);
	}
	NSege::init();
	S.insert(make_pair(-1,n+3)),S.insert(make_pair(n+3,-1));

	for(int i=1,tk;i<=m;i++)
	{
		o=Qread(),x_=Qread(),y_=Qread(),X=Qread(),Y=Qread();

		it=S.lower_bound(make_pair(x_,0));
		if(y_>= it->second)
		{
			if(it->first!=x_) it--;
			if(o==1)
			{
				while(it->second<=y_)
				{
					it_=it;it_++;
					tk=S2.range_sum(it->second,it_->second+1);
					S2.range_clr(it->second,it_->second+1);
					S1.node_add(it->first,tk);

					it--;
				}
				if(it->first>0)
				{
					it_=it;it_++;
					tk=S2.range_sum(y_,it_->second+1);
					S2.range_clr(y_,it_->second+1);
					S1.node_add(it->first,tk);
				}
			
				tmp=NSege::range_mn(1,x_);
				while(tmp.first<=y_)
				{
					lst--;
					NSege::del(tmp.second);
					S1.node_add(tmp.second,1);
					D1.node_add(tmp.second,-1),D2.node_add(tmp.first,-1);
					tmp=NSege::range_mn(1,x_);
				}
			}
			else
			{
				while(it->second<=y_)
				{
					it_=it;it_++;
					tk=S1.range_sum(it->first+1,min(x_,it_->first));
					S1.range_clr(it->first+1,min(x_,it_->first));
					S2.node_add(it->second,tk);
					it--;
				}

				tmp=NSege::range_mn(1,x_);
				while(tmp.first<=y_)
				{
					lst--;
					NSege::del(tmp.second);
					S2.node_add(tmp.first,1);
					D1.node_add(tmp.second,-1),D2.node_add(tmp.first,-1);
					tmp=NSege::range_mn(1,x_);
				}
			}

			it=S.upper_bound(make_pair(x_,y_));
			it--;
			while(it->second<=y_)
				it_=it,it--,S.erase(it_);
			S.insert(make_pair(x_,y_));
		}

		it=S.lower_bound(make_pair(X,0));
		if(Y<= it->second) continue;

		ans[i]=lst;
		ans[i]-=D1.range_sum(X+1,n)+D2.range_sum(Y+1,n);

		it=S.upper_bound(make_pair(X,0));
		o=false;
		it_=S.lower_bound(make_pair(0,Y));it_--;
		o=true;

		ans[i]+=S1.range_sum(it_->first+1,X)+S2.range_sum(it->second+1,Y);
	
		qry[X].push_back(make_pair(Y+1,i));
	}

	for(int i=n;i;i--)
	{
		for(pr g:qry[i]) ans[g.second]+=BIT::sum(g.first);
		for(int g:nd[i]) BIT::add(g);
	}

	for(int i=1;i<=m;i++)
		printf("%d\n",ans[i]);
	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: 12ms
memory: 85648kb

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

result:

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

Subtask #2:

score: 0
Wrong Answer

Test #9:

score: 0
Wrong Answer
time: 1887ms
memory: 176348kb

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
243995
0
0
0
0
109723
0
0
0
0
19132
0
0
0
0
0
0
229026
0
0
0
0
0
0
0
0
0
0
0
33808
0
0
31864
0
0
0
0
48712
0
0
0
17718
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
34881
56187
0
0
0
0
0
0
23198
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
29859
0
0
0
0
0
0
0
31802
0
0
0
0
0
0
0
...

result:

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

Subtask #3:

score: 0
Wrong Answer

Test #17:

score: 0
Wrong Answer
time: 3795ms
memory: 196704kb

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
633544
123520
313578
450015
383637
574187
2373
203701
326075
117994
567277
652825
199781
380318
380377
105878
373858
788346
703178
609803
648163
367061
497977
57980
478851
745056
75937
543065
251840
769828
436491
480969
235838
509627
757190
763489
396845
262683
2243
267174
165790
558966
16524...

result:

wrong answer 2nd numbers differ - expected: '633543', found: '633544'

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Skipped

Dependency #1:

0%