QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#690850#2016. 贪吃蛇hos_lyric100 ✓1901ms36972kbC++142.8kb2024-10-31 05:46:322024-10-31 05:46:33

Judging History

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

  • [2024-10-31 05:46:33]
  • 评测
  • 测评结果:100
  • 用时:1901ms
  • 内存:36972kb
  • [2024-10-31 05:46:32]
  • 提交

answer

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")



int N;
vector<int> A;

int solve() {
// cerr<<"[solve] N = "<<N<<", A = "<<A<<endl;
  using Pair = pair<int, int>;
  priority_queue<Pair, vector<Pair>, greater<Pair>> queMin;
  priority_queue<Pair> queMax;
  auto as = A;
  for (int i = 0; i < N; ++i) {
    queMin.emplace(A[i], i);
    queMax.emplace(A[i], i);
  }
  vector<int> js(N - 1, -1);
  vector<int> eaten(N, N - 1);
  for (int t = 0; t < N - 1; ++t) {
    int i = -1, j = -1;
    for (; ; ) {
      const int a = queMin.top().first;
      i = queMin.top().second;
      queMin.pop();
      if (a == as[i]) break;
    }
    for (; ; ) {
      const int a = queMax.top().first;
      j = queMax.top().second;
      queMax.pop();
      if (a == as[j]) break;
    }
    js[t] = j;
    eaten[i] = t;
    as[j] -= as[i];
    queMin.emplace(as[j], j);
    queMax.emplace(as[j], j);
  }
  // i: alive if eaten[i] >= alive
  int alive = N - 1;
  for (int t = N - 1; --t >= 0; ) {
    if (eaten[js[t]] < alive) {
      // resurrect all
      alive = t;
    }
  }
  return N - alive;
}

int main() {
  int T;
  for (; ~scanf("%d", &T); ) {
    scanf("%d", &N);
    A.resize(N);
    for (int i = 0; i < N; ++i) {
      scanf("%d", &A[i]);
    }
    for (int t = 0; t < T; ++t) {
      if (t) {
        int K;
        scanf("%d", &K);
        for (; K--; ) {
          int X, Y;
          scanf("%d%d", &X, &Y);
          --X;
          A[X] = Y;
        }
      }
      const int ans = solve();
      printf("%d\n", ans);
    }
  }
  return 0;
}

詳細信息


Pretests


Final Tests

Test #1:

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

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

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

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: 0ms
memory: 4056kb

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: 0ms
memory: 3764kb

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

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: 0ms
memory: 3864kb

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: 0ms
memory: 4060kb

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: 5ms
memory: 4128kb

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: 5ms
memory: 3860kb

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: 2ms
memory: 3844kb

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: 115ms
memory: 5040kb

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: 118ms
memory: 5116kb

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: 127ms
memory: 5240kb

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: 1867ms
memory: 36648kb

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: 1901ms
memory: 36528kb

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: 1886ms
memory: 36344kb

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: 1884ms
memory: 36528kb

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: 1860ms
memory: 36972kb

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: 1848ms
memory: 36708kb

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