QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#743173#5173. 染色Augenstern0 7ms5836kbC++141.0kb2024-11-13 18:28:042024-11-13 18:28:06

Judging History

This is the latest submission verdict.

  • [2024-11-13 18:28:06]
  • Judged
  • Verdict: 0
  • Time: 7ms
  • Memory: 5836kb
  • [2024-11-13 18:28:04]
  • Submitted

answer

//#pragma GCC optimize(3)
//#pragma GCC optimize("Ofast,unroll-loops")
#include<bits/stdc++.h>
//#define int long long
//#define ull unsigned long long
#define lll __int128
//#define double long double
#define fi first
#define se second
using namespace std;
const long long INF=1e9+5;
const long long mod=998244353,orm=3;
//const long long mod=1000000007;
const int MAXN=2000005;
const double eps=1e-6;
bool ST;
int n,Q;
int a[MAXN];
int f[MAXN][2];
void solve() {
	cin>>n>>Q;
	for(int i=1;i<=n;i++) cin>>a[i];
	while(Q--) {
		int l,r;cin>>l>>r;
		if(l>r) cout<<"		";
		f[l][0]=0,f[l][1]=INF;
		for(int i=l+1;i<=r;i++) {
			f[i][0]=f[i-1][0]+(a[i-1]!=a[i]);
			if(i-2>=l) f[i][0]=min(f[i][0],f[i-1][1]+(a[i]!=a[i-2]));
			f[i][1]=f[i-1][0]+(a[i-1]!=a[i]);
		}
		cout<<min(f[r][0],f[r][1])+(r-l)<<"\n";
	}
}
bool ED;
signed main() {
//	cout<<(&ST-&ED)/1024.0/1024.0;
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	solve();
	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: 5836kb

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:

		-1912
		-2388
6171
8652
		3867
7242
		-96
7559
510
		1803
261
2321
		-6888
		-2628
471
		-1354
		-1124
		-4671
1849
		-848
4956
		-152
6196
646
		-834
6382
		-5950
2801
3266
8093
		-9271
528
5669
18419
		-3124
6353
5155
15052
690
478
16120
		-6608
9161
8085
		-5726
6823
6608
5194
		-4525
8808
2246...

result:

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

Subtask #2:

score: 0
Time Limit Exceeded

Test #7:

score: 0
Time Limit Exceeded

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:

		-77082
135785
		-18609
6606
9385
		-39049
		-54537
29778
39704
		-75565
67974
7358
		-44904
43650
		-23875
50287
11311
109879
		-29580
		35523
4820
88920
47801
		-39182
		-10298
		-149
12500
60713
19006
56212
11864
8021
5634
		-21026
		-45374
		-38674
17289
		-44228
		-45943
54741
		-33736
558
		-...

result:


Subtask #3:

score: 0
Wrong Answer

Test #15:

score: 0
Wrong Answer
time: 7ms
memory: 5684kb

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:

		-677
		-1381
1778
		-1336
		-2421
		-2558
3017
		-680
899
5176
		-3550
4961
		268
943
		259
		-3610
		-3922
		-1935
3892
		-39
4571
		-211
2590
40
922
		-133
		-659
3966
		-1633
5853
4710
		758
		77
		-275
		-1502
		-2278
577
		717
		602
7772
		-4565
		1646
3186
3759
2945
		514
741
4093
183
		-728...

result:

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

Subtask #4:

score: 0
Time Limit Exceeded

Test #23:

score: 0
Time Limit Exceeded

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:

1270717
		220689
764228
		148682
		127152
580024
993602
1725441
1352405
		397639
		106127
		-236807
1393460
322464
		-474052
52570
277626
228815
2492
		59682
		-68259
670740
25561
		307886
		411966
1453070
1675383
		49901
147214
974602
1112512
		105361
		-98497
		105793
85268
1195182
318399
721876
1...

result: