QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#741850#5173. 染色dyj1334460 502ms91416kbC++141.0kb2024-11-13 15:21:102024-11-13 15:21:37

Judging History

This is the latest submission verdict.

  • [2024-11-13 15:21:37]
  • Judged
  • Verdict: 0
  • Time: 502ms
  • Memory: 91416kb
  • [2024-11-13 15:21:10]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5;
int n,q,a[N],lst[N],b[N],f[20][N];
inline int read()
{
	int x=0;
	char ch=getchar();
	while(ch<'0'||ch>'9')ch=getchar();
	while(ch>='0'&&ch<='9')
	{
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
	return x;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
//	freopen("color.in","r",stdin);
//	freopen("color.out","w",stdout);
	n=read(),q=read();
	for(int i=1;i<=n;i++)a[i]=read(),b[i]=1e9;
	int l=1;
	for(int i=1;i<=n;i++)
	{
		if(a[i]==a[i-1])l=i;
		if(lst[a[i]]&&(lst[a[i]]==i-1||l<=i))b[lst[a[i]]]=min(b[lst[a[i]]],i);
		lst[a[i]]=i;
	}
	for(int i=n-1;i;i--)b[i]=min(b[i],b[i+1]),f[0][i]=b[i];
	f[0][n]=b[n];
	for(int i=1;i<20;i++)
	{
		for(int j=1;j<=n;j++)
		{
			if(f[i-1][j]<=n)f[i][j]=f[i-1][f[i-1][j]];
			else f[i][j]=1e9;
		}
	}
	for(int i=1;i<=q;i++)
	{
		int l,r,ans;
		cin>>l>>r;
		if(l>r)swap(l,r);
		ans=2*(r-l);
		for(int j=__lg(r-l);j>=0;j--)if(f[j][l]<=r)ans-=1<<j,l=f[j][l];
		cout<<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: 46760kb

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:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

result:

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

Subtask #2:

score: 0
Wrong Answer

Test #7:

score: 0
Wrong Answer
time: 45ms
memory: 55228kb

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:

19442
52928
95258
49004
111534
64715
41994
3979
36292
56417
3784
72430
75734
111384
40278
52199
54780
32704
58044
92218
95154
4832
64791
71702
41349
23555
61945
61267
58615
73749
1502
15199
78145
64740
6449
2287
47447
52933
137635
11348
31637
15658
40731
13610
71517
21327
47334
35632
23368
52732
861...

result:

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

Subtask #3:

score: 0
Wrong Answer

Test #15:

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

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:

465
172
374
92
4311
255
4309
4693
5201
4548
2260
6634
7383
5968
96
1533
5419
2705
4450
7492
8353
1882
377
2209
4608
4081
4491
932
3705
2675
657
6299
1940
8166
5061
3935
4474
1142
2431
3812
8278
2258
7128
4779
1738
904
1486
4107
3169
990
6178
4748
2511
441
434
756
3623
282
2486
3877
5233
1439
7257
59...

result:

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

Subtask #4:

score: 0
Wrong Answer

Test #23:

score: 0
Wrong Answer
time: 502ms
memory: 91416kb

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:

27119
978155
275292
298052
271363
136309
1301634
1593511
75563
10627
58619
189800
690544
1428068
248188
871485
641242
423938
240714
1040177
748409
1207928
1510774
400458
393837
538818
879063
1349645
1437391
651650
469033
1780812
158366
498256
228666
792974
397428
167167
20038
683100
298893
223889
11...

result:

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