QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#740681#5173. 染色posvii0 518ms106280kbC++14682b2024-11-13 11:05:572024-11-13 11:05:57

Judging History

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

  • [2024-11-13 11:05:57]
  • 评测
  • 测评结果:0
  • 用时:518ms
  • 内存:106280kb
  • [2024-11-13 11:05:57]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAXN=1e6+5;
int n,q,a[MAXN],las[MAXN],f[MAXN][25];
signed main() {
	#ifndef ONLINE_JUDGE
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
	#endif
	ios::sync_with_stdio(0),cin.tie(0);
	cin>>n>>q;
	for(int i=1;i<=n;++i) {
		cin>>a[i];
		f[i][0]=max(las[a[i]],f[i-1][0]),las[a[i]]=i;
	}
	for(int j=1;j<=19;++j) {
		for(int i=n;f[i][j-1];--i) {
			f[i][j]=f[f[i][j-1]-1][j-1];
		}
	}
	while(q--) {
		int l,r;
		cin>>l>>r;
		if(l>r) swap(l,r);
		int ans=(r-l)*2;
		for(int j=19;j>=0;--j) {
			if(f[r][j]>l) r=f[r][j]-1,ans-=1<<j;
		}
		printf("%d\n",ans);
	}
	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: 2ms
memory: 8860kb

input:

10000 100
84 85 52 2 78 53 20 21 23 76 37 44 18 5 37 8 81 65 46 58 69 1 69 37 53 46 37 35 35 89 1 77 35 6 46 59 89 46 25 55 50 38 61 67 44 23 29 24 46 4 42 15 34 77 20 34 83 79 12 50 69 26 38 14 9 66 80 72 22 26 9 68 35 38 19 84 92 30 83 62 100 71 81 60 7 37 64 50 33 60 86 75 45 78 32 53 3 48 87 60 ...

output:

3673
4594
5997
8409
730
7033
184
7346
495
1146
255
2260
13275
6279
457
7540
2168
10523
1799
2687
4821
294
6023
629
6678
6199
11452
2722
3172
7862
17849
512
5511
17904
9598
6168
5008
14634
671
466
15672
12715
8904
7860
11024
6624
6418
5040
9134
8559
2184
10334
2704
12583
4982
2153
8839
1913
6499
2844...

result:

wrong answer 1st words differ - expected: '3668', found: '3673'

Subtask #2:

score: 0
Wrong Answer

Test #7:

score: 0
Wrong Answer
time: 34ms
memory: 17040kb

input:

100000 100000
3 2 3 3 3 3 2 3 2 1 3 1 1 1 3 2 1 3 1 2 2 1 3 1 2 2 1 1 1 3 2 1 3 3 3 3 1 1 1 2 3 3 2 1 1 1 3 1 3 1 3 2 1 3 2 3 3 2 3 3 2 3 3 3 3 3 2 3 2 3 1 3 3 3 3 3 3 3 1 2 3 3 1 3 1 1 2 2 3 1 1 2 3 2 3 1 3 2 1 3 2 3 2 1 1 3 3 1 3 1 2 2 2 3 2 3 2 3 2 1 1 3 1 3 2 2 3 3 3 1 2 2 3 3 2 1 3 1 2 2 2 3 2 ...

output:

127438
149759
61893
7277
10354
88155
105722
32845
43833
125648
75004
8151
74260
48170
50332
55498
12489
121294
80657
12012
5326
98148
52662
85277
30587
12331
13703
67056
20931
62091
13115
8834
6202
43574
75737
65630
19083
79004
79197
60487
58360
624
20829
134953
4519
48756
70364
38259
11130
28170
37...

result:

wrong answer 1st words differ - expected: '113194', found: '127438'

Subtask #3:

score: 0
Wrong Answer

Test #15:

score: 0
Wrong Answer
time: 2ms
memory: 6328kb

input:

5000 5000
256 63 197 36 75 66 33 72 27 75 66 248 29 166 209 252 141 95 84 226 147 249 116 94 192 256 199 273 182 166 116 274 27 211 154 144 283 23 53 110 215 11 164 284 161 221 251 96 43 47 18 115 12 51 156 61 116 209 93 98 47 165 174 106 83 67 184 75 12 290 183 197 112 240 67 56 215 148 104 5 141 2...

output:

1323
2699
1746
2615
4765
5002
2954
1327
881
5081
7820
4865
936
926
809
7279
7671
5332
3816
3229
4483
1579
2542
40
901
301
4355
3887
3818
5744
4616
1660
438
1416
3628
5262
565
119
2046
7623
9121
2049
3126
3688
2886
420
727
4011
180
3234
1444
1604
7135
3011
5962
8091
1539
3812
363
4481
3303
1742
819
2...

result:

wrong answer 1st words differ - expected: '1322', found: '1323'

Subtask #4:

score: 0
Wrong Answer

Test #23:

score: 0
Wrong Answer
time: 518ms
memory: 106280kb

input:

1000000 1000000
1105 3246 1880 3554 818 2331 2576 4140 149 4562 3498 3536 3400 4788 4363 4742 1216 4218 4032 1701 1489 4889 1761 3022 3145 4945 3067 4304 5016 4624 1612 13 1335 3613 1086 2210 386 3464 1156 3352 4341 5006 3465 3900 622 654 1826 2983 1250 4164 3335 4308 2995 1982 1347 4335 2535 5054 4...

output:

1263867
308628
760159
79458
160359
576934
988266
1716183
1345178
215193
615986
546285
1385971
320728
1094322
52291
276170
227575
2476
147758
144811
667163
25418
223792
184331
1445290
1666388
547662
146413
969361
1106554
237565
817334
112496
84815
1188750
316711
717986
169539
559891
767825
412222
732...

result:

wrong answer 1st words differ - expected: '1263815', found: '1263867'