QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#805662#9325. Random PermutationpeimudaML 601ms26460kbC++232.0kb2024-12-08 17:50:522024-12-08 17:50:53

Judging History

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

  • [2024-12-08 17:50:53]
  • 评测
  • 测评结果:ML
  • 用时:601ms
  • 内存:26460kb
  • [2024-12-08 17:50:52]
  • 提交

answer

#include<set>
#include<map>
#include<queue>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#define pr pair
#define f first
#define s second
#define ll int
#define mp make_pair
#define pll pr<ll,ll>
#define pii pr<int,int>
#define piii pr<int,pii>
using namespace std;
const ll m=998244353;
int a[200005];
int w[200005];
int tr[18][200005];
int tl[18][200005];
int nd[300005];
map<pii,ll> lt;
int fx(int l,int r)
{
	int g=nd[r-l];
//	cout<<"F "<<l<<' '<<r<<"  "<<w[min(tr[g][l],tl[g][r])]<<endl;
	return w[min(tr[g][l],tl[g][r])];
}
ll al(int l,int r);
ll ar(int l,int r);
ll al(int l,int r)
{
	if(l==r-1) return 1;
	int fd=fx(l,r);
	if(fd==l) return ar(l,r);
	ll&g=lt[mp(l,r)];
	if(g>0) return g-1;
	g=al(l+1,r)+al(l,fd);
	g=g%m+1;
//	cout<<"L "<<l<<' '<<r<<' '<<g-1<<endl;
	return g-1;
}
ll ar(int l,int r)
{
	if(l==r-1) return 1;
	int fd=fx(l,r);
	if(fd==r-1) return al(l,r);
	ll&g=lt[mp(l,r)];
	if(g>0) return g-1;
	g=ar(l,r-1)+ar(fd+1,r);
	g=g%m+1;
//	cout<<"R "<<l<<' '<<r<<' '<<g-1<<endl;
	return g-1;
}
unsigned time_related_rand()
{
	return (chrono::high_resolution_clock::now().time_since_epoch().count());
}
mt19937 myrand(time_related_rand());
int ra(int l,int r)
{
	uniform_int_distribution<int> rng(l,r);
	return rng(myrand);
}
void sl()
{
	int n=100000;
	cin>>n;
	for(int i=0;i<n;i++) a[i]=i;
	for(int i=1;i<n;i++) swap(a[i],a[ra(0,i)]);
	for(int i=0;i<n;i++) cin>>a[i];
	for(int i=0;i<n;i++) w[--a[i]]=i;
	for(int i=0;i<n;i++) tr[0][i]=a[i],tl[0][i+1]=a[i];
	for(int i=1;i<18;i++) for(int j=0;j<n;j++)
	{
		if(n-j>=1<<i) tr[i][j]=min(tr[i-1][j],tr[i-1][j+(1<<(i-1))]);
	}
	for(int i=1;i<18;i++) for(int j=1;j<=n;j++)
	{
		if(j>=1<<i) tl[i][j]=min(tl[i-1][j],tl[i-1][j-(1<<(i-1))]);
	}
	lt.clear();
	cout<<al(0,n)<<endl;
}
int main()
{
	for(int i=0;i<18;i++) for(int j=1<<i;j<1<<(i+1);j++) nd[j]=i;
	ios_base::sync_with_stdio(0);
	int t=1;
	cin>>t;
	while(t--) sl();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 10208kb

input:

4
5
4 3 5 1 2
5
5 3 1 2 4
2
2 1
3
1 3 2

output:

8
7
2
4

result:

ok 4 number(s): "8 7 2 4"

Test #2:

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

input:

5
2
1 2
4
2 1 4 3
3
3 2 1
2
1 2
3
3 1 2

output:

2
5
4
2
3

result:

ok 5 number(s): "2 5 4 2 3"

Test #3:

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

input:

332
4
3 2 4 1
3
3 2 1
3
3 1 2
4
2 3 4 1
3
1 2 3
2
1 2
3
2 3 1
3
2 3 1
4
4 3 1 2
3
2 1 3
3
1 3 2
2
2 1
3
3 1 2
2
2 1
2
2 1
4
3 1 2 4
3
3 1 2
3
1 3 2
3
2 3 1
2
2 1
3
1 2 3
3
1 3 2
3
1 3 2
4
3 1 4 2
3
3 2 1
3
1 3 2
2
2 1
2
1 2
3
2 1 3
2
1 2
2
2 1
4
2 1 3 4
2
1 2
2
2 1
3
3 1 2
2
2 1
3
3 2 1
2
2 1
4
2 4 ...

output:

7
4
3
8
4
2
4
4
5
3
4
2
3
2
2
5
3
4
4
2
4
4
4
5
4
4
2
2
3
2
2
5
2
2
3
2
4
2
5
4
5
3
5
8
4
2
2
3
4
5
2
4
5
5
4
4
4
2
4
2
4
5
8
2
8
4
8
2
4
2
2
8
7
2
4
4
4
8
4
4
2
5
4
2
2
2
7
7
2
4
5
2
5
4
8
3
3
2
3
8
5
2
8
2
2
3
5
2
2
8
2
8
3
2
2
8
4
7
4
5
2
3
5
2
8
3
2
4
4
2
2
8
2
2
2
4
5
8
7
3
2
2
7
2
5
2
4
2
4
3
...

result:

ok 332 numbers

Test #4:

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

input:

166
8
1 4 6 3 2 8 5 7
9
6 3 2 1 9 4 7 5 8
6
5 3 1 6 2 4
2
1 2
3
3 2 1
7
7 6 1 3 4 5 2
3
1 2 3
10
9 6 1 10 2 8 3 4 7 5
2
1 2
5
2 1 5 4 3
6
3 2 4 6 5 1
4
3 4 2 1
6
6 3 4 2 5 1
7
3 5 7 4 2 6 1
5
2 4 1 5 3
7
5 6 7 3 4 1 2
10
10 2 8 3 9 1 7 6 4 5
9
9 5 7 1 8 2 4 6 3
6
3 4 5 2 6 1
8
3 4 1 2 7 6 5 8
3
3 2 ...

output:

50
27
10
2
4
19
4
58
2
9
25
8
20
38
7
22
34
27
21
32
4
17
3
8
44
47
14
14
32
33
5
3
19
40
47
23
26
5
59
29
19
4
19
72
20
21
161
8
2
4
31
4
14
98
5
11
5
23
9
58
22
36
39
48
7
23
9
8
10
3
9
2
32
12
13
3
133
33
27
8
17
8
13
36
15
30
79
4
118
20
3
2
78
2
277
58
4
2
15
55
7
8
39
51
4
5
19
72
28
3
5
4
7
6...

result:

ok 166 numbers

Test #5:

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

input:

92
3
1 2 3
13
1 7 12 5 10 8 13 11 9 4 6 3 2
8
7 6 2 5 8 1 3 4
6
6 2 5 1 3 4
5
2 1 5 4 3
20
16 19 18 2 20 14 3 9 11 8 5 1 10 15 4 12 13 17 7 6
17
13 3 2 1 14 5 15 12 10 9 17 11 8 6 4 16 7
10
7 1 10 6 8 9 5 4 2 3
15
2 11 8 9 7 5 4 12 13 15 14 6 3 1 10
16
3 1 14 6 4 2 10 16 9 15 13 8 11 12 7 5
5
4 1 3 ...

output:

4
1241
23
10
9
363
1783
178
1579
824
8
16
34
467
382
392
1960
680
46
490
2812
45
144
99
116
965
99
1710
83
18
392
163
277
142
3
2
199
4
56
2
476
188
44
17
28
552
41
2
2
32
200
37
5
2
746
3
770
57
1006
9
21
11
1387
99
21
55
1421
730
15
7
103
2
2
93
47
96
72
2464
828
279
27
30
45
39
15
49
3110
93
10
3...

result:

ok 92 numbers

Test #6:

score: 0
Accepted
time: 29ms
memory: 12828kb

input:

28548
5
4 2 5 3 1
2
1 2
3
1 3 2
5
4 2 3 1 5
2
1 2
4
4 1 2 3
3
1 2 3
3
3 1 2
4
1 4 3 2
3
3 1 2
4
4 3 2 1
4
2 3 1 4
5
2 1 3 4 5
3
1 2 3
2
2 1
2
1 2
2
2 1
4
3 2 4 1
2
1 2
3
2 1 3
3
1 3 2
5
5 3 1 4 2
5
4 3 5 2 1
4
2 1 3 4
5
3 4 5 2 1
3
2 1 3
5
3 1 2 5 4
5
1 3 5 2 4
5
1 2 5 4 3
5
4 1 2 5 3
3
2 1 3
5
1 5 ...

output:

13
2
4
8
2
5
4
3
8
3
8
5
9
4
2
2
2
7
2
3
4
7
15
5
16
3
9
13
16
9
3
12
3
4
16
7
7
3
2
3
7
2
4
3
7
4
4
4
8
13
16
4
4
4
7
4
5
7
7
16
7
4
5
12
3
12
2
5
9
2
7
8
9
2
5
2
5
4
8
2
3
2
4
8
3
3
2
2
3
2
5
4
5
2
2
2
5
2
3
5
2
7
4
2
7
4
2
7
8
2
3
5
2
2
5
4
2
8
5
2
3
5
7
2
2
3
4
7
7
3
2
2
5
5
2
3
9
2
13
8
5
9
4
8...

result:

ok 28548 numbers

Test #7:

score: 0
Accepted
time: 18ms
memory: 12848kb

input:

13361
9
9 6 7 8 2 5 1 4 3
8
4 8 5 7 6 2 3 1
7
1 2 4 3 5 6 7
7
4 6 7 1 3 5 2
9
9 5 3 8 7 4 6 2 1
8
4 3 6 2 7 8 5 1
6
2 1 3 6 4 5
8
7 3 4 2 5 1 8 6
8
6 2 5 1 8 4 3 7
7
3 2 5 1 6 4 7
5
3 4 2 5 1
7
3 5 1 2 7 4 6
8
8 4 5 1 2 7 3 6
7
1 3 7 5 2 6 4
9
3 2 7 9 5 8 6 4 1
5
2 5 4 1 3
9
9 3 1 2 7 6 4 5 8
10
1 8...

output:

38
61
48
15
146
50
16
23
19
13
12
18
21
36
130
9
52
143
67
17
45
74
11
21
70
38
15
53
11
26
35
31
8
52
34
16
27
40
11
23
32
12
32
38
64
23
79
15
21
69
17
17
15
28
159
61
50
65
35
51
32
46
8
82
46
214
32
50
36
91
70
33
23
28
20
15
54
32
35
24
31
26
21
17
16
9
7
21
30
58
19
99
9
14
115
61
19
71
13
223...

result:

ok 13361 numbers

Test #8:

score: 0
Accepted
time: 177ms
memory: 16644kb

input:

667
173
161 83 56 53 140 121 5 136 39 9 48 122 171 67 123 79 8 78 92 130 145 85 103 153 168 70 165 166 30 62 11 96 14 100 66 13 133 32 18 20 25 132 87 126 69 142 55 120 60 105 22 101 26 45 33 80 128 127 107 82 81 172 169 167 135 41 71 89 40 119 59 154 129 114 93 139 27 162 31 63 118 157 117 38 52 95...

output:

583596139
584020170
471598730
739812209
116431625
722912939
184047388
12959806
37590670
167680609
87355140
961692527
903322137
248925145
650084912
914516987
289517842
300879479
207183975
262390037
225944732
134224253
740449198
768041290
17348915
726661844
733916897
358513219
471853816
755322624
1164...

result:

ok 667 numbers

Test #9:

score: 0
Accepted
time: 321ms
memory: 24276kb

input:

209
619
83 21 64 495 220 9 560 88 553 585 284 342 337 158 98 597 4 437 251 210 165 385 61 74 22 2 137 470 270 8 536 351 375 376 177 366 101 490 576 231 16 217 310 614 399 491 149 362 230 126 15 410 546 363 300 539 80 603 235 404 562 368 442 371 258 377 429 354 505 424 14 62 157 475 214 182 131 569 5...

output:

855992658
367026702
431800434
142191123
391617963
485308070
122398054
776250649
894154628
903985773
256203323
391558634
139075151
462471709
524355604
354340488
966695180
3933957
780375111
5768
678820611
61518971
112453740
104852252
171591774
202816532
240147595
437398882
879685262
484
930889179
9055...

result:

ok 209 numbers

Test #10:

score: 0
Accepted
time: 601ms
memory: 26460kb

input:

396
605
239 221 33 196 164 452 291 411 211 298 558 578 62 43 141 84 247 47 220 13 559 444 330 552 254 71 362 97 167 481 206 424 74 119 203 111 413 171 351 6 288 195 135 434 91 581 226 599 576 526 42 312 23 95 24 9 11 563 73 170 498 592 334 485 81 546 27 159 453 58 587 96 229 535 594 15 225 569 156 3...

output:

851397519
14197112
93073453
245922039
607161943
346953197
1941681
636713992
275782906
919582671
414981911
80334661
171750972
615441593
226220372
591309040
585300324
938611752
696956754
55894365
439181693
60695373
907628533
895768785
899204917
21272207
964271104
188914371
787802798
451701420
12269012...

result:

ok 396 numbers

Test #11:

score: -100
Memory Limit Exceeded

input:

1
200000
22615 127709 117908 176454 85854 188189 130909 22945 89774 111769 171103 149965 33152 105768 138968 118006 131227 25021 70289 190599 189803 161484 143425 155923 150567 161783 4292 15618 138979 154825 74802 100143 174639 151972 74186 108745 91114 198721 77415 52988 154864 53550 120930 92176 ...

output:

802841307

result: