QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#722722#9465. 基础 01 练习题liujunyi1230 994ms236528kbC++144.4kb2024-11-07 20:02:202024-11-07 20:02:20

Judging History

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

  • [2024-11-07 20:02:20]
  • 评测
  • 测评结果:0
  • 用时:994ms
  • 内存:236528kb
  • [2024-11-07 20:02:20]
  • 提交

answer

#include<bits/stdc++.h>
#define ull unsigned long long
using namespace std;
const int N=2e5+5;
int read(){int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch==-1)f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+ch-'0',ch=getchar();
	return x*f;
}
void write(int x){
	if(x<10)return putchar(x^48),void();
	write(x/10),putchar((x%10)^48);
}
int n,q,ty,f[N],s[N],sz[N],sz2[N],id[N],rk[N],nxt[N],lst[N];
vector<pair<int,int> > g[N];
ull bs=131,pw[N],p1[N];
struct HSH{
	vector<pair<int,int> > g[N];	
	int rt[N],tot;
	struct node{bool tg;int ls,rs;ull sum;}tr[N*60];
	void nw(int &o,int p){o=++tot,tr[o]=tr[p];}
	void addtag(int o,int len){tr[o].sum=p1[len]-tr[o].sum,tr[o].tg^=1;}
	void downtag(int o,int l,int r,int mid){
		if(tr[o].tg)nw(tr[o].ls,tr[o].ls),nw(tr[o].rs,tr[o].rs),addtag(tr[o].ls,mid-l+1),addtag(tr[o].rs,r-mid),tr[o].tg=0; 
	}
	void update(int &o,int p,int l,int r,int x,int y){
		if(l!=r)downtag(p,l,r,(l+r)>>1);nw(o,p);
		if(x<=l&&r<=y)return addtag(o,r-l+1);
		int mid=(l+r)>>1;
		if(x<=mid)update(tr[o].ls,tr[p].ls,l,mid,x,y);
		if(y>mid)update(tr[o].rs,tr[p].rs,mid+1,r,x,y);
		tr[o].sum=tr[tr[o].ls].sum*pw[r-mid]+tr[tr[o].rs].sum;
	}
	bool query(int o,int p,int l,int r){
		if(l==r)return tr[o].sum>tr[p].sum;
		int mid=(l+r)>>1;downtag(o,l,r,mid),downtag(p,l,r,mid);
//		cout<<o<<" "<<p<<" "<<l<<" "<<r<<" "<<tr[tr[o].ls].sum<<" "<<tr[tr[p].ls].sum<<endl;
		if(tr[tr[o].ls].sum==tr[tr[p].ls].sum)return query(tr[o].rs,tr[p].rs,mid+1,r);
		return query(tr[o].ls,tr[p].ls,l,mid);
	}
	void init(){
		for(int i=1;i<=n;i++){rt[i]=rt[i-1];
			for(auto x:g[i])update(rt[i],rt[i],1,n,x.first,x.second);
		}
//		for(int i=2;i<=3;i++)
//		for(int j=2;j<=3;j++)cout<<i<<" "<<j<<" "<<endl,query(rt[i],rt[j],1,n);
	}
}T;
bool cmp(int x,int y){return T.query(T.rt[x],T.rt[y],1,n);}
struct tree{bool tg;struct node{int mx,mn;}s[2];
void addtag(){tg^=1,swap(s[0],s[1]);}
void merge(tree&x,tree&y){
	s[0].mx=max(x.s[0].mx,y.s[0].mx);
	s[1].mx=max(x.s[1].mx,y.s[1].mx);
	s[0].mn=min(x.s[0].mn,y.s[0].mn);
	s[1].mn=min(x.s[1].mn,y.s[1].mn);
}
}tr[N<<2];
void build(int o,int l,int r){
	if(l==r){
		tr[o].s[1].mx=0,tr[o].s[1].mn=N;
		tr[o].s[0].mx=tr[o].s[0].mn=rk[l];
		return ;
	}
	int mid=(l+r)>>1;
	build(o<<1,l,mid),build(o<<1|1,mid+1,r);
	tr[o].merge(tr[o<<1],tr[o<<1|1]);
//	cout<<l<<" "<<r<<" "<<tr[o].s[1].mn<<endl;
}
void downtag(int o){if(tr[o].tg)tr[o<<1].addtag(),tr[o<<1|1].addtag(),tr[o].tg=0;}
void update(int o,int l,int r,int x,int y){
	if(x<=l&&r<=y)return tr[o].addtag();
	int mid=(l+r)>>1;downtag(o);
	if(x<=mid)update(o<<1,l,mid,x,y);
	if(y>mid)update(o<<1|1,mid+1,r,x,y);
	tr[o].merge(tr[o<<1],tr[o<<1|1]); 
}
int find(int x){return x==f[x]?x:f[x]=find(f[x]);}
int d[1005][1005];
int main(){pw[0]=1,p1[0]=0;
	for(int i=1;i<N;i++)p1[i]=p1[i-1]+pw[i-1],pw[i]=pw[i-1]*bs;
//	freopen("1.in","r",stdin);
//	freopen("1.out","w",stdout);
	scanf("%d%d%d",&n,&q,&ty);
	for(int i=1;i<=n;i++)id[i]=i;
	for(int i=1,a,b,x,y;i<=q;i++){
		scanf("%d%d%d%d",&a,&b,&x,&y);
		T.g[a].push_back(make_pair(x,y));
		T.g[b+1].push_back(make_pair(x,y));
		g[x].push_back(make_pair(a,b));
		g[y+1].push_back(make_pair(a,b));
//		d[a][x]^=1,d[b+1][x]^=1,d[a][y+1]^=1,d[b+1][y+1]^=1;
	}
	/* 
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			d[i][j]^=d[i-1][j]^d[i][j-1]^d[i-1][j-1];
			cout<<d[i][j];
		}
		cout<<endl;
	} 
	for(int j=1;j<=n;j++){
		for(int i=1;i<=n;i++)if(d[i][j])cout<<i<<" "<<j+n<<endl;else cout<<j+n<<" "<<i<<endl;
		cout<<endl;
	}*/ 
	T.init(),sort(id+1,id+n+1,cmp);
	for(int i=1;i<=n;i++)rk[id[i]]=i,f[i]=i,sz[i]=1,lst[i]=i-1,nxt[i]=i+1,cout<<id[i]<<endl;
//	cout<<endl;
	build(1,1,n);
	long long ans=0;
	for(int i=1,ct=0;i<=n;i++){
		for(auto x:g[i])update(1,1,n,x.first,x.second);
		int mn=tr[1].s[0].mn,mx=tr[1].s[1].mx;
//		cout<<mn<<" "<<mx<<endl;
		if(mn<=n&&mx>0){	
			mn=find(mn),mx=find(mx);
			if(mx>=mn){
				int s1=0,s2=0;
	//			cout<<mn<<" "<<mx<<endl;
				for(int p=mn;p<=mx;p=nxt[p]){
					ans-=1ll*sz[p]*sz2[p];
					s1+=sz[p];
					s2+=sz2[p];
					ct-=sz[p]>1;
					if(p!=mn)s2+=s[p];
					f[p]=mn;
				}
				s2++,ct++;
				sz[mn]=s1,sz2[mn]=s2;
	//			cout<<sz[mn]<<" "<<sz2[mn]<<endl;
				ans+=1ll*sz[mn]*sz2[mn];
				nxt[mn]=nxt[mx];
				lst[nxt[mx]]=mn;
			}else {
				mn=find(mn),s[mn]++;
			}
		} 
//		cout<<ct<<endl;
		if(ty||i==n)printf("%lld ",1ll*n*i-ans+ct);
	}
	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: 0ms
memory: 26552kb

input:

4 1000 0
2 3 1 2
1 3 1 3
1 2 1 2
1 2 3 4
1 4 2 4
1 3 1 2
1 4 1 2
1 3 1 4
3 3 2 3
1 2 2 4
4 4 1 3
3 3 3 4
3 4 3 4
2 3 1 1
1 2 2 4
1 4 3 4
3 4 1 2
1 2 2 3
3 4 3 3
1 2 4 4
4 4 2 4
1 4 1 1
1 1 1 3
2 3 2 3
1 1 2 4
2 3 2 4
3 3 1 4
3 3 3 3
1 3 3 3
2 3 2 4
3 3 2 2
1 3 2 4
1 3 1 2
3 4 1 2
2 3 1 3
1 1 1 2
1 2...

output:

1
3
2
4
1 

result:

wrong answer Output contains longer sequence [length = 5], but answer contains 1 elements

Subtask #2:

score: 0
Wrong Answer

Test #4:

score: 0
Wrong Answer
time: 144ms
memory: 193792kb

input:

50 200000 0
1 45 2 6
29 44 2 6
31 37 2 50
2 37 1 19
7 13 8 38
38 46 19 38
10 30 30 46
22 42 1 45
5 35 24 27
10 36 19 31
20 47 17 35
7 9 23 42
15 26 31 42
7 8 7 42
1 26 33 48
2 5 30 36
17 44 21 44
5 44 24 36
19 47 15 17
29 36 2 42
31 34 11 41
9 24 12 30
30 43 8 20
2 12 13 20
11 12 10 15
14 22 3 29
2 ...

output:

4
14
11
17
8
28
2
42
34
39
19
1
24
20
27
3
25
33
29
18
37
46
12
43
9
41
21
10
30
6
47
44
5
38
13
35
49
40
7
23
48
31
16
45
15
32
50
22
26
36
1 

result:

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

Subtask #3:

score: 0
Runtime Error

Test #8:

score: 0
Runtime Error

input:

5000 200000 0
1438 2561 3478 4930
1740 4634 87 3003
590 3275 1376 1681
2035 2793 2004 4945
567 3159 550 4470
61 3039 3431 3519
2654 3834 3460 4960
591 3560 409 443
345 2599 746 2891
1288 4570 1577 4402
249 377 1951 4534
2411 2455 294 1192
1679 3153 1645 4259
1735 1856 601 668
477 4881 411 2094
424 1...

output:


result:


Subtask #4:

score: 0
Runtime Error

Test #14:

score: 0
Runtime Error

input:

5000 200000 1
565 4401 1659 1826
429 1640 2999 3495
572 3994 9 3863
3844 4284 2307 3144
1054 1943 358 2592
727 4248 29 1171
1685 2392 4559 4929
1149 2787 1204 1947
2349 2619 405 998
1910 2786 25 1275
912 3475 4384 4387
3822 4895 1849 4548
3082 4749 3457 4220
3174 4885 117 1085
2517 3919 4325 4869
17...

output:


result:


Subtask #5:

score: 0
Wrong Answer

Test #21:

score: 0
Wrong Answer
time: 994ms
memory: 236528kb

input:

200000 200000 1
1 2 1 6
3 4 1 1
5 6 1 5
7 8 1 3
9 10 1 3
11 12 1 6
13 14 1 5
15 16 1 6
17 18 1 6
19 20 1 1
21 22 1 4
23 24 1 5
25 26 1 2
27 28 1 4
29 30 1 3
31 32 1 2
33 34 1 6
35 36 1 3
37 38 1 2
39 40 1 2
41 42 1 3
43 44 1 1
45 46 1 2
47 48 1 3
49 50 1 4
51 52 1 5
53 54 1 1
55 56 1 5
57 58 1 5
59 ...

output:

147942
177833
19473
12431
55151
117957
175483
159065
49607
149101
63363
55070
41521
182151
56646
22087
2043
120054
195908
89338
46787
99126
40173
104022
79710
7837
54127
4835
105927
10102
77747
136548
197376
188154
79613
131453
50016
121264
113321
4725
123249
60991
74611
159062
12721
11767
120242
19...

result:

wrong answer 1st numbers differ - expected: '200000', found: '147942'

Subtask #6:

score: 0
Runtime Error

Test #28:

score: 0
Runtime Error

input:

200000 200000 0
91264 123676 6826 154505
121351 188051 108158 131448
65413 163961 26771 116304
93852 110556 34929 187363
31794 142162 33578 38712
26574 67763 178013 197235
46436 146042 95 122860
11683 50463 60177 195245
60862 194711 37817 97212
144366 176271 113551 171098
120095 170517 73555 167299
...

output:


result:


Subtask #7:

score: 0
Runtime Error

Test #37:

score: 0
Runtime Error

input:

100000 200000 1
1 22878 1 2
1 7957 3 4
1 21779 5 6
1 34321 7 8
1 41692 9 10
1 49473 11 12
1 10254 13 14
1 43995 15 16
1 46975 17 18
1 668 19 20
1 25996 21 22
1 24975 23 24
1 43259 25 26
1 4174 27 28
1 39330 29 30
1 35462 31 32
1 27523 33 34
1 5574 35 36
1 47955 37 38
1 47013 39 40
1 3846 41 42
1 276...

output:


result: