QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#85563#5173. 染色crashed0 362ms98764kbC++141.7kb2023-03-07 21:08:572023-03-07 21:08:59

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-07 21:08:59]
  • 评测
  • 测评结果:0
  • 用时:362ms
  • 内存:98764kb
  • [2023-03-07 21:08:57]
  • 提交

answer

#include <cstdio>
#include <algorithm>

#define rep( i, a, b ) for( int i = (a) ; i <= (b) ; i ++ )
#define per( i, a, b ) for( int i = (a) ; i >= (b) ; i -- )

const int MAXN = 1e6 + 5, MAXLOG = 25;

template<typename _T>
inline void Read( _T &x ) {
	x = 0; char s = getchar(); bool f = false;
	while( ! ( '0' <= s && s <= '9' ) ) { f = s == '-', s = getchar(); }
	while( '0' <= s && s <= '9' ) { x = ( x << 3 ) + ( x << 1 ) + ( s - '0' ), s = getchar(); }
	if( f ) x = -x;
}

template<typename _T>
inline void Write( _T x ) {
	if( x < 0 ) putchar( '-' ), x = -x;
	if( 9 < x ) Write( x / 10 );
	putchar( x % 10 + '0' );
}

template<typename _T>
inline _T Min( const _T &a, const _T &b ) {
	return a < b ? a : b;
}

int nxt[MAXLOG][MAXN], pos[MAXN];
int lg2[MAXN];

int qL[MAXN], qR[MAXN];
int ans[MAXN];

int col[MAXN];

int N, Q;

inline void Work() {
	rep( i, 1, N ) pos[i] = N + 1;
	nxt[0][N + 1] = N + 1;
	per( i, N, 1 ) {
		nxt[0][i] = Min( nxt[0][i + 1], pos[col[i]] );
		pos[col[i]] = i;
	}
	for( int j = 1 ; j <= lg2[N] ; j ++ )
		for( int i = 1 ; i + ( 1 << j ) <= N ; i ++ )
			nxt[j][i] = nxt[j - 1][nxt[j - 1][i]];
	rep( i, 1, Q ) {
		int l = qL[i], r = qR[i];
		if( l > r ) continue;
		ans[i] = 2 * ( r - l );
		for( int k = lg2[r - l] ; k >= 0 ; k -- )
			if( l + ( 1 << k ) <= r && nxt[k][l] <= r )
				ans[i] -= 1 << k, l = nxt[k][l];
	}
}

int main() {
	Read( N ), Read( Q );
	rep( i, 1, N ) Read( col[i] );
	rep( i, 1, Q ) Read( qL[i] ), Read( qR[i] );
	lg2[0] = -1; rep( i, 1, N ) lg2[i] = lg2[i >> 1] + 1;
	Work();
	std :: reverse( col + 1, col + 1 + N );
	rep( i, 1, Q ) qL[i] = N - qL[i] + 1, qR[i] = N - qR[i] + 1;
	Work();
	rep( i, 1, Q ) Write( ans[i] ), putchar( '\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: 1ms
memory: 4036kb

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:

1777
681
2139
549
729
3221
183
3537
3
167
253
297
5601
2429
219
3745
201
2747
1791
737
915
293
2159
627
2851
2351
3709
789
1251
4075
2159
21
1627
2215
1789
2319
1113
7017
185
463
8095
5025
1065
4071
3265
2797
2579
1145
1305
703
227
2549
759
4891
1075
193
989
963
2655
909
959
2863
1733
3079
395
4473
...

result:

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

Subtask #2:

score: 0
Wrong Answer

Test #7:

score: 0
Wrong Answer
time: 30ms
memory: 9876kb

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:

23093
50077
54921
621
9199
78290
93920
29192
38941
20945
66619
7226
24273
42776
44640
49274
11102
15677
71676
10708
4735
87161
46860
75805
27270
10951
12237
59513
18641
9605
11626
7850
5521
38727
26091
13839
16941
70130
30265
7645
5053
551
18481
32175
4016
43296
62515
33972
9870
24982
33222
72215
20...

result:

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

Subtask #3:

score: 0
Wrong Answer

Test #15:

score: 0
Wrong Answer
time: 1ms
memory: 1748kb

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:

331
715
759
625
779
1021
981
337
391
1093
3905
877
447
433
315
3351
3749
1363
1855
1263
485
589
549
40
415
300
365
1929
1851
1773
629
671
191
427
1659
1283
69
119
43
3699
1139
51
1145
1719
907
420
231
11
179
1261
451
615
3197
1029
2001
81
557
1845
363
483
1327
761
325
451
291
475
741
795
21
1799
399...

result:

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

Subtask #4:

score: 0
Wrong Answer

Test #23:

score: 0
Wrong Answer
time: 362ms
memory: 98764kb

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:

222369
48209
240087
14371
30181
55835
469503
677181
304071
85333
95155
25023
345137
60373
51895
19813
15537
97789
445
17513
14525
146575
9185
93965
54315
404755
627115
26443
16173
450479
64135
107807
297611
47597
19755
146821
56315
197729
39411
38707
247829
152403
8105
6215
23587
7
79493
49329
76859...

result:

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