QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#875005#2016. 贪吃蛇Damofeilang100 ✓135ms16056kbC++232.4kb2025-01-28 23:40:312025-01-28 23:40:32

Judging History

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

  • [2025-01-28 23:40:32]
  • 评测
  • 测评结果:100
  • 用时:135ms
  • 内存:16056kb
  • [2025-01-28 23:40:31]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
//#define int long long
const int N = 1e6+10;
const int INF = 0x3f3f3f3f; 
const int mod = 1e9+7;
#define reg register 
#define rep(i,j,k) for(int i=j;i<=k;i++)
#define Rep(i,j,k) for(int i=j;i>=k;i--)
inline int read(){
	int x = 0,f = 1;
	char ch = getchar();
	while(!isdigit(ch)) { if(ch == '-') f = -1; ch = getchar(); }
	while(isdigit(ch)) { x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar(); }
	return x * f;
}
int a[N];
int T, n, k;
int main(){
	std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cin >> T;
    rep(i,1,T){
    	if(i == 1){
    		cin >> n;
			rep(i,1,n){
				cin >> a[i];
			}
		}
		else{
			cin >> k;
			rep(i,1,k){
				int x, y;
				cin >> x >> y;
				a[x] = y;
			}
		}
		deque<pair<int,int>> q1, q2;
		rep(i,1,n){
			q1.push_back({a[i],i});
		}
		int res;
		while(1){
			if(q1.size() + q2.size() == 2){
				res = 1;
				break;
			}
			int x, y, id;
			y = q1.front().first, q1.pop_front();
			if(q2.empty() || !q1.empty() && q1.back() > q2.back()){
                x = q1.back().first, id = q1.back().second, q1.pop_back();
            } 
            else {
                x = q2.back().first, id = q2.back().second, q2.pop_back();
            }
            auto now = make_pair(x - y, id);
            if (q1.empty() || q1.front() > now) {
                res = q1.size() + q2.size() + 2;
                int cnt = 0;
                while (1) {
                    cnt++;
                    if (q1.size() + q2.size() == 1) {
                        if (cnt % 2 == 0) res--;
                        break;
                    }
                    int x, id;
                    if (q2.empty() || !q1.empty() && q1.back() > q2.back()) {
                        x = q1.back().first, id = q1.back().second, q1.pop_back();
                    } 
                    else {
                        x = q2.back().first, id = q2.back().second, q2.pop_back();
                    }
                    now = {x - now.first, id};
                    if (!((q1.empty() || now < q1.front()) && (q2.empty() || now < q2.front()))) {
                        if (cnt % 2 == 0) res--;
                        break;
                    } 
                }
                break;
            } 
            else {
                q2.push_front(now);
            }
		}
		cout << res << "\n";
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Pretests


Final Tests

Test #1:

score: 5
Accepted
time: 0ms
memory: 3712kb

input:

10
3
29 46 67
3
1 15 2 34 3 114
3
1 120 2 168 3 224
3
1 65 2 132 3 293
3
1 79 2 192 3 474
3
1 24 2 64 3 562
3
1 396 2 458 3 595
3
1 44 2 317 3 592
3
1 138 2 145 3 572
3
1 602 2 726 3 831

output:

3
1
3
1
1
1
3
1
1
3

result:

ok 10 lines

Test #2:

score: 5
Accepted
time: 0ms
memory: 3712kb

input:

10
3
21 73 85
3
1 53 2 69 3 126
3
1 90 2 244 3 259
3
1 67 2 288 3 320
3
1 247 2 351 3 445
3
1 150 2 483 3 568
3
1 534 2 583 3 590
3
1 114 2 226 3 745
3
1 199 2 436 3 513
3
1 147 2 324 3 555

output:

3
1
3
3
3
3
3
1
3
1

result:

ok 10 lines

Test #3:

score: 5
Accepted
time: 0ms
memory: 3712kb

input:

10
3
31 64 74
3
1 68 2 83 3 98
3
1 1 2 81 3 102
3
1 98 2 140 3 247
3
1 20 2 76 3 276
3
1 276 2 384 3 592
3
1 25 2 275 3 361
3
1 597 2 632 3 764
3
1 72 2 151 3 455
3
1 224 2 546 3 834

output:

3
3
1
1
1
3
1
3
1
1

result:

ok 10 lines

Test #4:

score: 5
Accepted
time: 1ms
memory: 3712kb

input:

10
3
24 62 82
3
1 19 2 28 3 145
3
1 98 2 198 3 278
3
1 25 2 67 3 278
3
1 20 2 254 3 262
3
1 110 2 175 3 585
3
1 87 2 369 3 584
3
1 222 2 524 3 604
3
1 11 2 27 3 420
3
1 241 2 495 3 838

output:

3
1
3
1
3
1
1
3
1
1

result:

ok 10 lines

Test #5:

score: 5
Accepted
time: 1ms
memory: 3712kb

input:

10
10
3 9 37 42 43 55 55 67 69 95
10
1 10 2 15 3 75 4 121 5 129 6 140 7 157 8 158 9 165 10 172
10
1 2 2 34 3 44 4 48 5 129 6 166 7 169 8 170 9 253 10 295
10
1 29 2 65 3 147 4 177 5 208 6 267 7 295 8 306 9 360 10 386
10
1 64 2 131 3 133 4 151 5 186 6 245 7 259 8 324 9 347 10 422
10
1 32 2 52 3 101 4 ...

output:

7
7
5
7
7
5
7
7
5
7

result:

ok 10 lines

Test #6:

score: 5
Accepted
time: 0ms
memory: 3712kb

input:

10
10
1 11 17 21 40 51 54 75 83 91
10
1 27 2 44 3 46 4 52 5 72 6 81 7 125 8 130 9 167 10 175
10
1 14 2 56 3 66 4 68 5 95 6 133 7 164 8 269 9 271 10 274
10
1 60 2 64 3 78 4 111 5 123 6 176 7 210 8 311 9 353 10 354
10
1 25 2 89 3 149 4 172 5 281 6 283 7 338 8 437 9 463 10 470
10
1 129 2 168 3 201 4 34...

output:

5
5
5
5
7
7
5
7
7
5

result:

ok 10 lines

Test #7:

score: 5
Accepted
time: 1ms
memory: 3712kb

input:

10
10
4 13 20 58 62 67 74 77 93 93
10
1 10 2 34 3 58 4 67 5 81 6 87 7 98 8 143 9 152 10 193
10
1 35 2 80 3 100 4 106 5 171 6 173 7 184 8 240 9 278 10 297
10
1 17 2 46 3 48 4 317 5 328 6 364 7 378 8 383 9 384 10 399
10
1 22 2 34 3 58 4 96 5 99 6 100 7 156 8 190 9 414 10 443
10
1 57 2 63 3 78 4 170 5 ...

output:

7
5
7
7
3
7
7
7
7
7

result:

ok 10 lines

Test #8:

score: 5
Accepted
time: 1ms
memory: 3712kb

input:

10
10
4 18 36 41 50 58 59 78 84 92
10
1 42 2 43 3 54 4 54 5 67 6 152 7 153 8 161 9 182 10 190
10
1 9 2 49 3 58 4 64 5 82 6 185 7 258 8 272 9 277 10 286
10
1 10 2 141 3 151 4 169 5 198 6 240 7 282 8 284 9 353 10 387
10
1 3 2 73 3 158 4 196 5 245 6 265 7 311 8 324 9 378 10 448
10
1 26 2 45 3 156 4 157...

output:

7
5
5
7
7
5
5
7
3
5

result:

ok 10 lines

Test #9:

score: 5
Accepted
time: 1ms
memory: 3712kb

input:

10
2000
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 7 7 7 7 8 ...

output:

1226
1222
1227
1231
1245
1189
1237
1219
1224
1255

result:

ok 10 lines

Test #10:

score: 5
Accepted
time: 1ms
memory: 3712kb

input:

10
2000
0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 8 8 8 8 ...

output:

1231
1239
1228
1233
1213
1233
1242
1255
1223
1261

result:

ok 10 lines

Test #11:

score: 5
Accepted
time: 0ms
memory: 3712kb

input:

10
2000
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 8 ...

output:

1236
1236
1201
1213
1232
1235
1214
1243
1257
1229

result:

ok 10 lines

Test #12:

score: 5
Accepted
time: 34ms
memory: 4224kb

input:

10
50000
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 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...

output:

30512
30779
30949
30796
30946
30847
30807
30937
30867
30808

result:

ok 10 lines

Test #13:

score: 5
Accepted
time: 31ms
memory: 4352kb

input:

10
50000
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 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...

output:

30619
30660
30793
30727
30877
30771
30846
30589
30800
30975

result:

ok 10 lines

Test #14:

score: 5
Accepted
time: 32ms
memory: 4352kb

input:

10
50000
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 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...

output:

30435
30814
30682
30922
30855
30868
30851
31023
30968
30951

result:

ok 10 lines

Test #15:

score: 5
Accepted
time: 125ms
memory: 15912kb

input:

10
1000000
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 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...

output:

609762
609762
609762
613003
613003
613003
613003
613003
613003
609165

result:

ok 10 lines

Test #16:

score: 5
Accepted
time: 127ms
memory: 15668kb

input:

10
1000000
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 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...

output:

609891
609892
609892
609892
609892
609892
609892
618092
618092
618092

result:

ok 10 lines

Test #17:

score: 5
Accepted
time: 129ms
memory: 16056kb

input:

10
1000000
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 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...

output:

609983
609983
609983
609984
609984
609984
609984
609070
609070
609071

result:

ok 10 lines

Test #18:

score: 5
Accepted
time: 132ms
memory: 15644kb

input:

10
1000000
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 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...

output:

610259
610259
610259
613586
613586
613586
613586
616676
616676
616677

result:

ok 10 lines

Test #19:

score: 5
Accepted
time: 127ms
memory: 15696kb

input:

10
1000000
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 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...

output:

610386
610386
610386
613680
613680
613680
613680
618492
618492
618493

result:

ok 10 lines

Test #20:

score: 5
Accepted
time: 135ms
memory: 15688kb

input:

10
1000000
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 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...

output:

610138
610138
610138
613036
613036
613036
613036
613036
613036
609198

result:

ok 10 lines

Extra Test:

score: 0
Extra Test Passed