QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#64750#21403. 文艺平衡树Crysfly#AC ✓190ms5060kbC++113.0kb2022-11-25 14:54:042022-11-25 14:54:05

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-11-25 14:54:05]
  • 评测
  • 测评结果:AC
  • 用时:190ms
  • 内存:5060kb
  • [2022-11-25 14:54:04]
  • 提交

answer

#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
using namespace std;
inline int read()
{
	char c=getchar();int x=0;bool f=0;
	for(;!isdigit(c);c=getchar())f^=!(c^45);
	for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
	if(f)x=-x;return x;
}
 
#define mod 998244353
struct modint{
	int x;
	modint(int o=0){x=o;}
	modint &operator = (int o){return x=o,*this;}
	modint &operator +=(modint o){return x=x+o.x>=mod?x+o.x-mod:x+o.x,*this;}
	modint &operator -=(modint o){return x=x-o.x<0?x-o.x+mod:x-o.x,*this;}
	modint &operator *=(modint o){return x=1ll*x*o.x%mod,*this;}
	modint &operator ^=(int b){
		modint a=*this,c=1;
		for(;b;b>>=1,a*=a)if(b&1)c*=a;
		return x=c.x,*this;
	}
	modint &operator /=(modint o){return *this *=o^=mod-2;}
	friend modint operator +(modint a,modint b){return a+=b;}
	friend modint operator -(modint a,modint b){return a-=b;}
	friend modint operator *(modint a,modint b){return a*=b;}
	friend modint operator /(modint a,modint b){return a/=b;}
	friend modint operator ^(modint a,int b){return a^=b;}
	friend bool operator ==(modint a,int b){return a.x==b;}
	friend bool operator !=(modint a,int b){return a.x!=b;}
	bool operator ! () {return !x;}
	modint operator - () {return x?mod-x:0;}
	bool operator <(const modint&b)const{return x<b.x;}
};
inline modint qpow(modint x,int y){return x^y;}

vector<modint> fac,ifac,iv;
inline void initC(int n)
{
	if(iv.empty())fac=ifac=iv=vector<modint>(2,1);
	int m=iv.size(); ++n;
	if(m>=n)return;
	iv.resize(n),fac.resize(n),ifac.resize(n);
	For(i,m,n-1){
		iv[i]=iv[mod%i]*(mod-mod/i);
		fac[i]=fac[i-1]*i,ifac[i]=ifac[i-1]*iv[i];
	}
}
inline modint C(int n,int m){
	if(m<0||n<m)return 0;
	return initC(n),fac[n]*ifac[m]*ifac[n-m];
}
inline modint sign(int n){return (n&1)?(mod-1):(1);}

#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;

#define maxn 100005
#define inf 0x3f3f3f3f

int n,m,rt;
mt19937 rng(1231231);

bool rev[maxn];
int ls[maxn],rs[maxn],sz[maxn];
unsigned int rnd[maxn];

void up(int p){
	sz[p]=sz[ls[p]]+sz[rs[p]]+1;
}
void pr(int p){
	rev[p]^=1;
	swap(ls[p],rs[p]);
}
void down(int p){
	if(p&&rev[p]){
		pr(ls[p]),pr(rs[p]);
		rev[p]=0;
	}
}
void split(int p,int k,int&x,int&y){
	if(!p)return x=y=0,void();
	down(p);
	if(sz[ls[p]]<k)x=p,split(rs[p],k-sz[ls[p]]-1,rs[p],y);
	else y=p,split(ls[p],k,x,ls[p]);
	up(p); 
}
int merge(int x,int y){
	if(!x||!y)return x|y;
	down(x),down(y);
	if(rnd[x]<rnd[y])return rs[x]=merge(rs[x],y),up(x),x;
	return ls[y]=merge(x,ls[y]),up(y),y;
}
void dfs(int u){
	down(u);
	if(ls[u])dfs(ls[u]);
	cout<<u<<" ";
	if(rs[u])dfs(rs[u]);
}

signed main()
{
	n=read(),m=read();
	For(i,1,n)rnd[i]=rng(),sz[i]=1,rt=merge(rt,i);
	For(i,1,m){
		int l=read(),r=read();
		int x,y,z;
		split(rt,l-1,x,y);
		split(y,r-l+1,y,z);
		pr(y);
		rt=merge(x,merge(y,z));
	}
	dfs(rt);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3480kb

input:

30 5
7 26
7 18
5 9
4 15
3 15

output:

1 2 4 17 16 15 6 5 18 19 20 21 22 23 3 24 25 26 14 13 12 11 10 9 8 7 27 28 29 30 

result:

ok single line: '1 2 4 17 16 15 6 5 18 19 20 21... 13 12 11 10 9 8 7 27 28 29 30 '

Test #2:

score: 0
Accepted
time: 2ms
memory: 3416kb

input:

100 10
9 29
10 68
7 72
15 73
57 79
4 39
11 69
45 61
1 42
15 21

output:

5 4 47 46 45 44 43 42 41 40 39 38 37 36 78 79 31 32 33 34 35 77 76 75 74 24 23 22 21 20 19 18 54 53 52 51 50 49 48 3 2 1 6 72 63 64 65 66 67 68 29 8 7 73 25 26 27 28 69 70 71 62 61 60 59 58 57 56 55 17 16 15 14 13 12 11 10 9 30 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 

result:

ok single line: '5 4 47 46 45 44 43 42 41 40 39...91 92 93 94 95 96 97 98 99 100 '

Test #3:

score: 0
Accepted
time: 0ms
memory: 3416kb

input:

200 50
49 166
53 181
17 136
38 105
39 120
17 132
24 148
51 178
35 166
37 128
22 145
33 158
43 150
41 49
59 130
59 188
57 124
25 113
15 136
55 178
47 162
45 175
101 159
51 168
11 90
45 124
61 172
15 134
37 148
3 86
57 130
81 129
59 159
31 128
8 119
1 53
1 128
9 88
35 160
41 200
40 127
47 165
39 112
1...

output:

105 104 72 71 14 13 12 11 162 182 183 184 185 186 97 48 33 118 10 9 8 7 6 17 18 19 20 117 173 172 159 45 89 90 73 74 75 76 77 78 79 187 58 119 120 121 64 65 178 200 199 198 197 196 195 194 193 192 191 190 189 135 134 133 132 131 47 46 88 87 86 85 116 174 175 176 114 144 41 42 43 31 30 29 28 130 96 9...

result:

ok single line: '105 104 72 71 14 13 12 11 162 ...32 166 165 164 163 181 180 179 '

Test #4:

score: 0
Accepted
time: 2ms
memory: 3348kb

input:

200 50
57 184
29 105
1 100
4 76
9 104
19 87
25 118
37 136
39 166
55 170
133 169
23 154
25 102
47 136
17 37
43 122
31 116
12 113
35 146
29 143
53 140
39 160
5 104
157 193
5 57
55 65
11 136
55 122
53 138
15 84
49 95
3 127
56 149
35 104
71 159
23 96
37 120
6 95
28 107
63 181
3 30
57 105
27 96
29 154
12...

output:

34 35 107 108 45 177 41 70 18 87 88 89 92 168 144 158 159 123 124 125 126 127 171 170 64 65 66 67 149 148 147 146 145 154 6 134 105 23 141 122 121 120 119 118 117 116 115 46 47 48 49 50 51 52 53 10 9 8 7 153 152 151 150 97 98 99 100 194 143 157 156 33 167 166 165 164 163 162 161 160 142 79 80 81 82 ...

result:

ok single line: '34 35 107 108 45 177 41 70 18 ... 77 78 195 196 197 198 199 200 '

Test #5:

score: 0
Accepted
time: 3ms
memory: 3508kb

input:

10000 3000
2766 8161
802 5794
623 6126
2879 8058
2011 8169
2017 9893
237 4761
3032 7817
838 4475
400 4961
241 1478
1957 6725
2245 5631
1519 5260
2189 5951
1585 7664
3098 8044
1809 6484
3127 8674
3126 6755
873 5942
105 5541
1685 5556
78 4452
3255 8289
537 5681
3 6305
4404 9793
548 5182
1000 5611
1821...

output:

8694 1445 8229 8230 8231 2838 2837 2836 2835 7220 7221 7222 7223 584 285 2924 515 739 740 741 742 743 9340 6210 6211 6212 8914 8913 8912 1994 5690 5691 5692 5693 5435 4580 4581 4582 4583 4584 4585 4586 4587 2028 4038 4037 4036 4181 9954 9955 3287 6066 6653 6652 6651 5031 5030 5029 5028 6582 6581 585...

result:

ok single line: '8694 1445 8229 8230 8231 2838 ...9995 9996 9997 9998 9999 10000 '

Test #6:

score: 0
Accepted
time: 79ms
memory: 4256kb

input:

50000 50000
5351 22924
23569 31837
10321 34305
24821 31124
7255 36650
9801 30062
27465 36441
6799 39256
12861 36908
19999 49816
38177 49281
4887 27918
13810 33483
8219 31074
1231 32512
12811 30950
31705 38376
12517 36898
9193 41418
6640 28721
3319 35161
14859 35985
8787 32188
81 18433
2859 28749
472...

output:

48014 26930 36546 1261 19039 41093 41094 9017 30509 14540 42177 3620 48562 34139 49910 28964 29701 9016 17610 49590 36985 17667 35860 18397 49199 39712 15509 24957 4982 453 454 455 9061 20463 38246 49225 29795 18827 18828 5060 13133 33917 30100 39575 20799 48246 48245 21475 38732 21765 29762 23049 5...

result:

ok single line: '48014 26930 36546 1261 19039 4...614 8615 15358 2597 2598 50000 '

Test #7:

score: 0
Accepted
time: 116ms
memory: 4852kb

input:

80000 70000
5639 33189
58689 76401
22323 63782
9379 60566
24044 65425
26023 71449
7993 61134
19089 64394
11624 49545
54470 72393
15679 50852
12239 42684
18293 57292
6893 44628
19100 61605
6111 38496
7615 60504
4047 38342
8735 60458
11602 61623
4837 51608
56131 66851
44401 75157
14135 42318
15677 510...

output:

60666 41986 49896 20550 5704 5705 5706 10915 35225 23036 23037 67036 67037 36041 11205 31611 76382 21038 29429 70674 70673 35560 36629 36628 34587 51651 21187 29365 22356 27638 68982 68983 68984 33197 53012 13558 21168 79338 79339 79340 71899 5753 54124 59519 15893 2101 61797 77780 14668 60916 44254...

result:

ok single line: '60666 41986 49896 20550 5704 5... 52749 78001 61574 79999 80000 '

Test #8:

score: 0
Accepted
time: 182ms
memory: 5060kb

input:

100000 100000
26201 76499
2133 49270
16969 54134
20129 81465
30309 95715
16450 75674
31087 95302
25186 63359
28653 85166
33110 72970
2773 55409
10286 68395
53815 86337
304 61183
27663 88134
17939 66827
28395 88990
17457 98881
958 55658
17527 57075
19575 69265
4019 47133
48549 59998
16148 54577
12091...

output:

48382 82046 57881 9235 76677 33462 84995 83053 8060 82151 82152 63534 63535 48529 61112 7695 22575 31032 52215 39360 6022 33089 3260 42656 58062 79509 83713 19526 18576 21796 28655 28654 84107 8663 68055 24698 24697 29016 29017 52336 23602 4974 32300 89077 82078 65138 71972 59397 56986 69328 26439 5...

result:

ok single line: '48382 82046 57881 9235 76677 3...98311 26991 26992 58731 100000 '

Test #9:

score: 0
Accepted
time: 186ms
memory: 5004kb

input:

100000 100000
89003 90209
46083 96417
23507 88692
24354 68519
14791 58309
937 56827
8485 74848
25853 79517
5262 70656
4118 54651
980 52207
25265 70914
31713 90674
545 40408
29188 77333
10967 69263
15841 57641
5223 46419
23905 70366
383 59463
28161 94766
26005 68202
15775 59971
32578 92749
24170 6505...

output:

44538 59025 59600 24875 87550 32120 32121 96880 35553 23105 46839 71441 65830 87344 67098 25193 10833 34147 35461 56271 88328 52956 39722 52742 71452 63088 63089 46633 46632 46631 33087 32623 32622 32621 90948 10909 87520 4356 25063 61766 89391 99065 34630 28669 94972 99221 31212 35311 89976 34897 6...

result:

ok single line: '44538 59025 59600 24875 87550 ...45224 75512 99998 99999 100000 '

Test #10:

score: 0
Accepted
time: 190ms
memory: 5008kb

input:

100000 100000
4087 54523
35889 83701
29237 63069
13324 54160
66297 71875
2063 82484
24510 85797
17796 40115
6656 67026
30611 64488
75085 82245
4003 58692
62333 88273
4706 42110
18680 73012
9242 67838
2497 35928
27556 78883
27622 85762
33271 94733
27115 79171
5601 52585
10950 74087
22029 81150
90337 ...

output:

99318 20129 52948 52947 4068 47045 82589 82588 57020 57021 65919 32841 88592 3956 9346 72561 54657 37672 99925 48134 93660 88805 88806 70239 43192 84763 57016 57015 57014 2249 70962 68269 99523 99522 99521 92142 92143 51961 47914 92784 34096 34097 40316 30416 87491 87492 30115 72921 3506 3507 29634 ...

result:

ok single line: '99318 20129 52948 52947 4068 4...22295 22294 22293 99999 100000 '