QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#741952#5173. 染色tuxuanming20240 638ms82772kbC++14823b2024-11-13 15:32:052024-11-13 15:32:08

Judging History

This is the latest submission verdict.

  • [2024-11-13 15:32:08]
  • Judged
  • Verdict: 0
  • Time: 638ms
  • Memory: 82772kb
  • [2024-11-13 15:32:05]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+5,INF=0x3f3f3f3f;
int n,q,lst[N],f[21][N];
int main()
{
#ifdef LOCAL
	freopen("1.in","r",stdin);
	freopen("1.out","w",stdout);
	freopen("1.err","w",stderr);
#endif
	ios::sync_with_stdio(0),cin.tie(0);
	cin>>n>>q;
	int mx=0;
	for(int i=1;i<=n;i++) f[0][i]=INF;
	for(int i=1,a;i<=n;i++)
	{
		cin>>a;
		if(lst[a]>mx) f[0][lst[a]]=i-1,mx=lst[a];
		lst[a]=i;
	}
	for(int i=n-1;i>=1;i--) f[0][i]=min(f[0][i],f[0][i+1]);
	for(int j=1;1<<j<=n;j++)
		for(int i=1;i<=n;i++)
			f[j][i]=f[j-1][i]==INF?INF:f[j-1][f[j-1][i]+1];
	int l,r;
	while(q--)
	{
		cin>>l>>r; int ans=0;
		if(l>r) swap(l,r);
		int x=l;
		for(int i=__lg(n);i>=0;i--) if(f[i][x]<r) x=f[i][x],ans|=1<<i;
		cout<<2*(r-l)-ans<<"\n";
	}
	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: 32380kb

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:

3667
4575
5976
8382
729
7013
183
7320
492
1140
253
2249
13225
6254
456
7505
2162
10480
1790
2675
4801
292
5997
625
6654
6179
11412
2712
3157
7836
17782
511
5484
17833
9564
6147
4995
14577
669
461
15613
12668
8872
7833
10987
6603
6399
5022
9102
8527
2172
10298
2693
12537
4957
2144
8808
1907
6475
2828...

result:

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

Subtask #2:

score: 0
Wrong Answer

Test #7:

score: 0
Wrong Answer
time: 51ms
memory: 45000kb

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:

113189
133092
54915
6478
9191
78287
93917
29191
38937
111582
66611
7224
66013
42770
44633
49269
11095
107717
71674
10703
4729
87155
46856
75800
27263
10947
12234
59509
18640
55101
11623
7846
5517
38723
67271
58321
16933
70127
70333
53669
51861
548
18477
119879
4011
43291
62510
33969
9865
24977
33217...

result:

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

Subtask #3:

score: 0
Wrong Answer

Test #15:

score: 0
Wrong Answer
time: 0ms
memory: 28232kb

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:

1322
2696
1743
2611
4759
4995
2949
1327
880
5076
7811
4860
935
925
808
7268
7662
5325
3813
3224
4477
1577
2538
40
901
300
4351
3881
3813
5739
4609
1658
437
1415
3623
5257
565
119
2044
7615
9111
2047
3121
3683
2883
420
727
4006
179
3231
1443
1601
7127
3008
5953
8083
1539
3807
363
4476
3300
1740
818
2...

result:

wrong answer 7th words differ - expected: '2950', found: '2949'

Subtask #4:

score: 0
Wrong Answer

Test #23:

score: 0
Wrong Answer
time: 638ms
memory: 82772kb

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:

1263815
308608
760115
79452
160350
576908
988222
1716103
1345117
215185
615960
546263
1385910
320710
1094276
52291
276158
227555
2476
147750
144805
667128
25418
223778
184324
1445226
1666310
547639
146406
969316
1106498
237554
817297
112491
84810
1188701
316694
717959
169528
559867
767792
412202
732...

result:

wrong answer 9th words differ - expected: '1345118', found: '1345117'