QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#740314#5173. 染色wdnmdwrnmmp0 131ms120624kbC++141.4kb2024-11-13 08:51:392024-11-13 08:51:39

Judging History

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

  • [2024-11-13 08:51:39]
  • 评测
  • 测评结果:0
  • 用时:131ms
  • 内存:120624kb
  • [2024-11-13 08:51:39]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
// #define int long long
#define rep(i,j,k) for(int i=(j);i<=(k);i++)
#define per(i,j,k) for(int i=(j);i>=(k);i--)
#define pb emplace_back
#define mp make_pair
#define fi first
#define se second
typedef vector<int> vi;
typedef pair<int,int> pi;

namespace IO{
	char buf[1<<25], *iS=buf-1;
	
	void init(){
		fread(buf, 1, 1<<25, stdin);
	}
	#define getchar() (*++iS)
	int read(){
		int res=0;
		char ch=' ';
		do{
			ch=getchar();
		}while(!isdigit(ch));
		do{
			res=res*10+ch-48;
			ch=getchar();
		}while(isdigit(ch));
		return res;
	}
}
using IO::read;

void chmin(int &x,int y){
	if(y<x) x=y;
}

signed main(){
	ios::sync_with_stdio(0);
	
	IO::init();
	
	int n=read(), q=read();
	
	vi a(n+1), lst(n+1), nxt(n+2), mx(n+2);
	vector<vi> bz(__lg(n)+1, vi(n+2));
	
	rep(i,1,n){
		a[i]=read();
	}
	nxt[n]=nxt[n+1]=n+1;
	per(i,n,1){
		nxt[i]=nxt[i+1];
		if(lst[a[i]]){
			chmin(nxt[i], lst[a[i]]);
		}
		lst[a[i]]=i;
	}
	
	bz[0]=nxt;
	rep(i,1,(int)bz.size()-1){
		rep(j,1,n+1){
			bz[i][j]=bz[i-1][bz[i-1][j]];
		}
	}
	per(i,(int)bz.size()-1,0){
		rep(j,1,n+1){
			if(bz[i][j]<=n){
				mx[j]=i;
			}
		}
	}
	
	rep(_,1,q){
		int l=read(), r=read();
		if(l>r){
			swap(l, r);
		}
		int len=r-l;
		int ans=0;
		per(i,mx[l],0){
			if(bz[i][l]<=r){
				ans+= 1<<i;
				l=bz[i][l];
			}
		}
		cout<< len*2-ans <<'\n';
	}
}

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: 3964kb

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:

3823
4775
6233
8739
759
7315
191
7631
513
1189
263
2343
13791
6523
473
7839
2247
10937
1867
2783
5009
303
6253
655
6945
6445
11899
2835
3297
8169
18541
531
5721
18597
9979
6413
5207
15207
695
483
16285
13215
9255
8165
11455
6891
6673
5239
9495
8893
2273
10739
2805
13081
5169
2239
9179
1985
6749
2955...

result:

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

Subtask #2:

score: 0
Wrong Answer

Test #7:

score: 0
Wrong Answer
time: 6ms
memory: 13800kb

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:

154163
181147
74913
8811
12517
106671
127899
39689
53047
152015
90721
9855
89807
58301
60911
67155
15105
146747
97563
14515
6443
118745
63695
103161
36979
14915
16561
81157
25327
75139
15869
10701
7489
52673
91625
79373
23075
95629
95799
73179
70587
753
25201
163245
5455
58955
85111
46285
13447
3408...

result:

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

Subtask #3:

score: 0
Wrong Answer

Test #15:

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

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:

1353
2761
1781
2671
4873
5115
3027
1359
901
5187
7999
4971
957
943
825
7445
7843
5457
3901
3309
4579
1611
2595
40
925
309
4459
3975
3897
5867
4723
1693
445
1449
3705
5377
579
121
2089
7793
9329
2097
3191
3765
2953
431
741
4105
183
3307
1473
1637
7291
3075
6095
8271
1579
3891
369
4577
3373
1783
835
2...

result:

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

Subtask #4:

score: 0
Wrong Answer

Test #23:

score: 0
Wrong Answer
time: 131ms
memory: 120624kb

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:

1270943
310351
764373
79905
161251
580121
993789
1725755
1352645
216403
619441
549309
1393711
322515
1100469
52579
277679
228859
2491
148583
145595
670861
25567
225035
185385
1453329
1675689
550729
147243
974765
1112709
238877
821897
113131
85289
1195395
318457
722015
170481
562993
772115
414545
736...

result:

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