QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#719722#9606. PM 大师hos_lyric#40 1971ms166560kbC++147.3kb2024-11-07 08:27:132024-11-07 08:27:15

Judging History

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

  • [2024-11-07 08:27:15]
  • 评测
  • 测评结果:40
  • 用时:1971ms
  • 内存:166560kb
  • [2024-11-07 08:27:13]
  • 提交

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")


template <class T> void bAdd(vector<T> &bit, int pos, const T &val) {
  const int bitN = bit.size();
  for (int x = pos; x < bitN; x |= x + 1) bit[x] += val;
}
template <class T> T bSum(const vector<T> &bit, int pos) {
  T ret = 0;
  for (int x = pos; x > 0; x &= x - 1) ret += bit[x - 1];
  return ret;
}
template <class T> T bSum(const vector<T> &bit, int pos0, int pos1) {
  return bSum(bit, pos1) - bSum(bit, pos0);
}

// min pos s.t. pred(sum of [0, pos))
//   assume pred(sum of [0, pos)) is non-decreasing
template <class T, class Pred>
int bBinarySearch(const vector<T> &bit, Pred pred) {
  if (pred(T(0))) return 0;
  const int bitLen = bit.size();
  int pos = 0;
  T sum = 0;
  for (int e = 31 - __builtin_clz(bitLen); e >= 0; --e) {
    const int x = (pos | 1 << e) - 1;
    if (x < bitLen && !pred(sum + bit[x])) {
      pos |= 1 << e;
      sum += bit[x];
    }
  }
  return pos + 1;
}


struct Set {
  // max{ceil(log_64(n)), 1}
  int log64N, n;
  vector<unsigned long long> a[6];
  explicit Set(int n_ = 0) : n(n_) {
    assert(n >= 0);
    int m = n ? n : 1;
    for (int d = 0; ; ++d) {
      m = (m + 63) >> 6;
      a[d].assign(m, 0);
      if (m == 1) {
        log64N = d + 1;
        break;
      }
    }
  }
  bool empty() const {
    return !a[log64N - 1][0];
  }
  bool contains(int x) const {
    return (a[0][x >> 6] >> (x & 63)) & 1;
  }
  void insert(int x) {
    for (int d = 0; d < log64N; ++d) {
      const int q = x >> 6, r = x & 63;
      a[d][q] |= 1ULL << r;
      x = q;
    }
  }
  void erase(int x) {
    for (int d = 0; d < log64N; ++d) {
      const int q = x >> 6, r = x & 63;
      if ((a[d][q] &= ~(1ULL << r))) break;
      x = q;
    }
  }
  // max s.t. <= x (or -1)
  int prev(int x) const {
    if (x > n - 1) x = n - 1;
    for (int d = 0; d <= log64N; ++d) {
      if (x < 0) break;
      const int q = x >> 6, r = x & 63;
      const unsigned long long lower = a[d][q] << (63 - r);
      if (lower) {
        x -= __builtin_clzll(lower);
        for (int e = d; --e >= 0; ) x = x << 6 | (63 - __builtin_clzll(a[e][x]));
        return x;
      }
      x = q - 1;
    }
    return -1;
  }
  // min s.t. >= x (or n)
  int next(int x) const {
    if (x < 0) x = 0;
    for (int d = 0; d < log64N; ++d) {
      const int q = x >> 6, r = x & 63;
      if (static_cast<unsigned>(q) >= a[d].size()) break;
      const unsigned long long upper = a[d][q] >> r;
      if (upper) {
        x += __builtin_ctzll(upper);
        for (int e = d; --e >= 0; ) x = x << 6 | __builtin_ctzll(a[e][x]);
        return x;
      }
      x = q + 1;
    }
    return n;
  }
};


int N, Q;
vector<int> A;
vector<int> X, K, Y;

namespace brute {
vector<int> run() {
cerr<<"[brute::run]"<<endl;
  auto as = A;
  vector<int> bs(N);
  vector<int> app(N + 1, -1);
  vector<int> ans(Q, -1);
  for (int q = 0; q < Q; ++q) {
    as[X[q]] = K[q];
    int mex = 0;
    for (int i = 0; i < N; ++i) {
      if (as[i] == -1) {
        for (; app[mex] == q; ++mex) {}
        bs[i] = mex;
      } else {
        bs[i] = as[i];
      }
      if (bs[i] >= 0) {
        app[bs[i]] = q;
      }
    }
    ans[q] = bs[Y[q]];
  }
  return ans;
}
}  // brute

namespace sub2 {
vector<int> run() {
cerr<<"[sub2::run]"<<endl;
  int I0;
  for (I0 = 0; I0 < N && A[I0] == -2; ++I0) {}
  vector<int> bit(N + 1, 0);
  for (int b = 0; b <= N; ++b) bAdd(bit, b, +1);
  auto as = A;
  vector<int> freq(N + 1, 0);
  vector<int> ans(Q, -1);
  for (int q = 0; q < Q; ++q) {
    {
      int &a = as[X[q]];
      if (a >= 0) if (!--freq[a]) bAdd(bit, a, +1);
      a = K[q];
      if (a >= 0) if (!freq[a]++) bAdd(bit, a, -1);
    }
    if (Y[q] < I0) {
      ans[q] = as[Y[q]];
    } else {
      ans[q] = bBinarySearch(bit, [&](int sum) -> bool {
        return (sum > Y[q] - I0);
      }) - 1;
    }
  }
  return ans;
}
}  // sub2

namespace sub3 {
vector<int> run() {
cerr<<"[sub3::run]"<<endl;
  vector<int> is;
  vector<int> si(N, -1);
  for (int i = 0; i < N; ++i) if (A[i] == -1) {
    si[i] = is.size();
    is.push_back(i);
  }
  const int len = min((int)is.size(), 105);
  vector<Set> exs(len, Set(N + 1));
  for (int j = 0; j < len; ++j) {
    for (int b = 0; b <= N; ++b) exs[j].insert(b);
  }
  vector<set<int>> apps(N + 1);
  for (int b = 0; b <= N; ++b) apps[b].insert(N);
  auto as = A;
  vector<int> ans(Q, -1);
  for (int q = 0; q < Q; ++q) {
    {
      int &a = as[X[q]];
      if (a >= 0) {
        apps[a].erase(X[q]);
        for (int j = 0; j < len; ++j) if (X[q] < is[j] && is[j] < *apps[a].begin()) exs[j].insert(a);
      }
      a = K[q];
      if (a >= 0) {
        for (int j = 0; j < len; ++j) if (X[q] < is[j] && is[j] < *apps[a].begin()) exs[j].erase(a);
        apps[a].insert(X[q]);
      }
    }
    {
      const int jY = si[Y[q]];
      if (~jY) {
        int b = 0;
        for (int j = 0; j < len; ++j) {
          b = exs[j].next(b);
          if (jY == j) {
            ans[q] = b;
            break;
          }
          ++b;
        }
        if (jY >= len) {
          ans[q] = b + (jY - len);
        }
      } else {
        ans[q] = as[Y[q]];
      }
    }
  }
  return ans;
}
}  // sub3

int main() {
  for (; ~scanf("%d%d", &N, &Q); ) {
    A.resize(N);
    for (int i = 0; i < N; ++i) {
      scanf("%d", &A[i]);
      --A[i];
    }
    X.resize(Q);
    K.resize(Q);
    Y.resize(Q);
    for (int q = 0; q < Q; ++q) {
      scanf("%d%d%d", &X[q], &K[q], &Y[q]);
      --X[q];
      --K[q];
      --Y[q];
    }
    
    bool spe2 = true;
    for (int i = 0; i < N - 1; ++i) spe2 = spe2 && (A[i] <= A[i + 1]);
    const bool spe3 = (*max_element(K.begin(), K.end()) < 100);
    const bool spe4 = (count(A.begin(), A.end(), -1) <= 100);
    
    vector<int> ans;
    if (spe2) {
      ans = sub2::run();
    } else if (spe3 || spe4) {
      ans = sub3::run();
    } else {
      ans = brute::run();
    }
    for (int q = 0; q < Q; ++q) {
      printf("%d\n", ans[q] + 1);
    }
  }
  return 0;
}

详细

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 0ms
memory: 3780kb

input:

10 10
0 -1 0 0 -1 0 -1 -1 0 -1
7 5 9
7 5 1
10 8 4
7 10 1
8 -1 3
10 6 4
2 2 1
2 9 6
5 8 4
7 -1 9

output:

6
1
3
1
2
3
1
4
3
5

result:

ok 10 lines

Test #2:

score: 10
Accepted
time: 411ms
memory: 4076kb

input:

10000 10000
-1 0 -1 -1 -1 0 -1 0 -1 0 -1 0 0 -1 -1 0 0 -1 0 -1 -1 -1 0 0 -1 -1 0 -1 -1 -1 0 0 0 -1 0 -1 -1 -1 -1 0 -1 -1 0 -1 -1 0 -1 -1 0 0 -1 0 0 0 -1 -1 -1 -1 0 0 0 0 -1 0 -1 -1 0 -1 -1 -1 0 0 -1 0 0 -1 -1 0 0 -1 -1 -1 -1 0 0 0 -1 0 -1 0 0 0 0 -1 0 0 -1 -1 0 -1 -1 -1 0 -1 0 -1 0 0 -1 -1 0 -1 -1 0...

output:

37
1767
2083
1505
2208
3174
1012
3136
4044
2661
802
4772
931
2188
605
732
1473
1221
4070
706
3786
464
300
2857
4852
3026
2965
2102
4096
4859
1841
60
2465
645
4312
2002
4168
3292
2854
2043
194
4748
3298
1687
916
4465
1101
4649
4552
598
3717
3883
2111
1911
2502
2265
2737
2193
4200
3607
4086
3908
2529
...

result:

ok 10000 lines

Test #3:

score: 10
Accepted
time: 133ms
memory: 4148kb

input:

10000 10000
0 0 -1 0 0 -1 0 0 0 0 0 0 0 0 -1 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 ...

output:

6984
1876
1755
3945
3988
8817
1301
9211
6838
70
2044
5300
4026
6870
1879
7611
2604
5187
8292
1796
5087
2635
2369
8040
5721
6993
5554
966
5743
4301
8644
4755
2400
4647
6158
6998
2597
7698
8252
6522
8528
8153
3332
2833
4289
3081
9022
6921
6121
1549
2801
958
9507
2148
7998
4954
8624
7643
22
4162
5666
8...

result:

ok 10000 lines

Test #4:

score: 10
Accepted
time: 139ms
memory: 4320kb

input:

10000 10000
0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 -1 0 -1 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 -1 0 -1 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 ...

output:

549
7364
7058
4716
4807
6918
163
2855
4219
8220
1848
2315
1228
6516
1570
7755
728
911
2810
2028
3977
6371
8418
788
2040
7159
7360
3776
8573
8326
3057
3814
3587
4894
2018
5314
812
5691
5689
7967
4493
7806
1966
5618
6862
3303
1947
6878
7511
6879
5418
5836
8916
5951
4960
1424
1290
4315
873
3208
1774
73...

result:

ok 10000 lines

Test #5:

score: 10
Accepted
time: 201ms
memory: 4068kb

input:

10000 10000
-1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 -1 -1 -1 -1 0 0 0 0 0 -1 -1 0 0 0 -1 0 0 0 0 -1 0 0 -1 0 0 0 -1 -1 0 -1 -1 0 -1 -1 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 -1 0 -1 0 0 -1 0 0 0 0 -1 0 0 0 0 0 0 0 -1 0 0 0 -1 0 -1 -1 0 0 0 ...

output:

3638
2094
6615
88
2643
3081
3993
7204
6569
1008
7035
4008
6846
2407
2888
6884
5588
340
3145
3234
3779
2608
6289
1428
2477
3411
161
2203
2128
5677
1759
2106
6596
313
7461
5011
1208
3021
7029
3452
4582
6173
479
4360
224
3681
5249
2351
569
1369
5212
5572
3429
7152
6636
6318
6928
6644
6678
5661
4229
185...

result:

ok 10000 lines

Test #6:

score: 10
Accepted
time: 279ms
memory: 4344kb

input:

10000 10000
-1 0 0 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 -1 -1 0 -1 -1 -1 0 -1 0 -1 -1 -1 -1 -1 -1 0 -1 -1 0 -1 -1 0 -1 0 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 0 -1 0 -1 -1 -1 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 0 -1 -1 -1 -1 0 -1 -1 -1 0 -1 -1 -1 -1 0 -1 -1 -1 -1 -1 -1 0 0 -1 -1 -1 -1 0 0 -1 -1 -1 -1 -1 ...

output:

2420
325
2194
1102
1154
1391
12
1517
1948
1801
593
441
975
1902
1078
184
226
587
52
2361
1584
2137
2255
190
1904
193
636
62
1915
1028
1751
612
330
659
1700
1672
1073
756
202
425
766
522
1844
2295
744
37
865
2367
32
1066
948
1026
1162
812
625
1512
161
1394
2372
429
1232
1155
1295
998
1941
1632
1151
1...

result:

ok 10000 lines

Test #7:

score: 10
Accepted
time: 222ms
memory: 4156kb

input:

10000 10000
-1 0 -1 -1 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 0 -1 0 -1 -1 -1 -1 -1 -1 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0...

output:

219
484
774
725
570
54
54
931
240
552
787
897
322
15
756
440
675
152
337
275
408
856
622
562
494
3
890
858
849
460
141
187
119
271
441
426
550
804
308
823
398
918
244
522
213
785
84
429
428
500
619
179
808
173
853
1011
955
46
375
520
704
416
955
800
661
899
953
533
319
87
1011
172
254
810
842
879
59...

result:

ok 10000 lines

Test #8:

score: 10
Accepted
time: 206ms
memory: 4068kb

input:

10000 10000
-1 -1 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1...

output:

236
370
232
128
262
311
250
336
164
107
97
183
354
3
346
307
282
350
99
214
350
489
170
373
130
81
221
200
184
275
451
67
60
70
41
472
153
479
288
228
212
332
68
76
338
114
242
116
207
22
234
204
451
213
258
159
34
193
259
122
448
105
131
177
474
490
439
405
170
322
380
360
425
33
414
302
191
161
33...

result:

ok 10000 lines

Subtask #2:

score: 10
Accepted

Test #9:

score: 10
Accepted
time: 469ms
memory: 34364kb

input:

1000000 1000000
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1...

output:

459886
53317
492356
423943
292374
39197
57078
411846
146532
49283
12402
316482
109785
61994
283770
156543
483178
281298
130833
46233
335000
428931
210801
24959
71722
361514
117444
218823
54814
378720
81973
194272
135873
484070
293734
303811
349950
344506
479375
229463
8421
114254
237253
295732
15835...

result:

ok 1000000 lines

Test #10:

score: 10
Accepted
time: 507ms
memory: 34628kb

input:

1000000 1000000
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1...

output:

231864
158988
610606
558023
74606
42402
245012
525664
260911
510218
257983
146399
83879
681860
375125
59670
894882
210723
509929
9256
413137
839173
549143
526070
729809
423388
596082
184674
660967
119639
742727
901832
938252
900078
190461
920677
441621
942117
188500
185870
522884
40015
9817
716146
7...

result:

ok 1000000 lines

Test #11:

score: 10
Accepted
time: 497ms
memory: 34408kb

input:

1000000 1000000
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1...

output:

36874
472618
842917
114716
491408
773508
452063
603860
728342
748513
475705
258696
486435
316427
736929
378854
238269
110066
1161
156017
484791
539880
789570
421405
27960
173470
21339
774513
531030
728993
156647
533307
212440
258827
731424
220524
712655
444910
546596
745273
497179
341745
676112
5092...

result:

ok 1000000 lines

Test #12:

score: 10
Accepted
time: 492ms
memory: 34560kb

input:

1000000 1000000
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1...

output:

668119
431443
15455
296704
240224
645285
127520
95201
89016
184805
731059
712630
396434
292253
553741
212645
355171
214190
127817
191153
701410
89507
340566
287015
187296
35719
746439
375147
88190
102370
390425
435125
502654
399775
608758
98602
171926
271902
511567
384122
726564
28359
4230
471734
12...

result:

ok 1000000 lines

Test #13:

score: 10
Accepted
time: 412ms
memory: 34552kb

input:

1000000 1000000
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1...

output:

122105
239109
25040
14694
216977
99003
181576
195235
117059
231141
152732
140117
42783
77977
226878
131724
129445
6315
84475
200684
240468
74983
112696
224812
7559
33824
18998
187
133123
151253
107837
158008
132668
13180
180187
124564
177382
102508
128808
131293
88975
157536
238149
98474
128162
9293...

result:

ok 1000000 lines

Test #14:

score: 10
Accepted
time: 380ms
memory: 34408kb

input:

1000000 1000000
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1...

output:

47044
6150
94661
59151
4729
2518
23567
71693
42072
50518
22840
39707
35445
82412
27250
50855
39799
64638
21397
39142
82263
66705
54956
24413
54915
20050
12379
30158
7056
56960
48528
81919
34586
47114
79033
79833
35677
74173
90352
31325
75842
4392
42035
27995
87130
20590
19983
78934
8490
46331
18425
...

result:

ok 1000000 lines

Test #15:

score: 10
Accepted
time: 379ms
memory: 34428kb

input:

1000000 1000000
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1...

output:

41828
48247
26228
2049
8832
16507
32126
45098
16614
23119
34270
34422
36737
30148
40987
19693
38932
49063
35507
26936
34825
4751
48640
8128
29266
16813
36942
31358
20695
21688
15879
16628
42878
6807
40994
38198
1395
11655
10644
35127
2309
23706
2631
15256
28080
47633
38700
24115
9522
27033
46263
538...

result:

ok 1000000 lines

Subtask #3:

score: 10
Accepted

Test #16:

score: 10
Accepted
time: 1971ms
memory: 159540kb

input:

1000000 1000000
0 -1 -1 0 -1 -1 0 -1 0 -1 0 0 0 0 -1 -1 -1 0 -1 0 -1 0 -1 -1 0 -1 -1 -1 0 -1 -1 -1 0 -1 0 0 0 -1 -1 -1 -1 0 -1 -1 0 0 -1 -1 0 -1 -1 -1 0 -1 0 -1 0 0 -1 0 -1 -1 -1 -1 -1 -1 -1 0 -1 0 0 -1 0 0 0 0 0 0 0 0 0 -1 0 -1 0 0 0 -1 -1 -1 0 0 0 -1 0 0 0 -1 -1 0 0 0 0 -1 -1 0 0 0 0 -1 0 -1 0 0 0...

output:

419426
372348
476911
34348
150780
460622
223328
283198
443164
347044
103688
492126
361590
20471
24004
315761
428482
18708
420730
182298
498955
177266
56353
462764
158257
244933
422040
484780
403241
187513
20639
466402
267820
384702
293959
84073
125864
363325
86066
479275
368199
195169
20943
82210
29...

result:

ok 1000000 lines

Test #17:

score: 10
Accepted
time: 1668ms
memory: 143484kb

input:

1000000 1000000
0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 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:

877817
169670
503865
868941
757832
762592
267527
132121
530021
515297
594043
369906
279274
769900
279993
925891
867298
65017
327392
534338
454981
371962
773139
594668
861490
297472
691830
240392
6931
837802
329267
717727
622016
302076
867101
808473
234174
156539
246761
217031
706530
892460
804744
36...

result:

ok 1000000 lines

Test #18:

score: 10
Accepted
time: 1762ms
memory: 146104kb

input:

1000000 1000000
0 0 0 0 -1 0 0 0 0 0 0 0 -1 0 0 -1 0 0 0 -1 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 -...

output:

76964
254688
647867
132442
555987
772576
148660
189913
890249
469690
650795
527444
823200
239204
536286
369356
374355
316809
102958
181712
133162
278773
624648
23406
191762
690329
48553
204392
70394
472228
352467
863376
689494
255188
762658
128967
848134
101255
825979
353786
758958
597186
80265
8005...

result:

ok 1000000 lines

Test #19:

score: 10
Accepted
time: 1844ms
memory: 151836kb

input:

1000000 1000000
0 0 -1 0 0 0 0 0 -1 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 -1 0 -1 0 0 0 0 0 0 0 0 -1 0 -1 0 -1 0 -1 0 0 0 0 0 0 0 0 0 0 -1 -1 0 0 0 0 -1 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 -1 0 -1 0 -1 0 -1 -1 0 0 0 0 -1 0 0 -1 -1 0 0 0 0 0 0 0 0 0 0 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 0 0 0 -1 -1 -1 ...

output:

301362
124661
594574
157761
452519
202544
349211
125801
300630
652855
79737
245694
343621
402370
220223
476997
106123
58847
28413
436012
281469
582215
577107
244922
278352
280065
748256
673531
10514
243821
418778
355056
186471
292616
428202
270231
545683
441274
487468
96171
653364
293158
395100
6348...

result:

ok 1000000 lines

Test #20:

score: 10
Accepted
time: 1927ms
memory: 164164kb

input:

1000000 1000000
-1 -1 -1 -1 -1 -1 0 -1 0 0 -1 -1 -1 -1 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 0 0 -1 -1 -1 -1 -1 0 0 -1 -1 -1 -1 -1 -1 0 -1 0 -1 0 -1 -1 -1 -1 -1 0 -1 -1 -1 -1 -1 -1 0 -1 -1 0 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 -1 0 0 -1 -1 -1 -1 -1 0 0 0 0 -1 0 -1 -1 -1 0 0 0 0 -1 -1 0 0 0 -1 -1 -1 -1 -1 -1 ...

output:

17462
58557
246658
26828
228805
46664
5019
174233
104683
211580
60036
225402
181205
52446
98450
212982
193185
179563
194752
23834
194419
83859
193437
130118
156179
245458
17678
50207
160851
30676
225732
67445
220034
72349
22635
6223
123948
109346
105038
193636
113546
110188
66568
124787
140476
40757...

result:

ok 1000000 lines

Test #21:

score: 10
Accepted
time: 1882ms
memory: 166124kb

input:

1000000 1000000
0 -1 -1 -1 -1 -1 -1 -1 -1 0 -1 -1 -1 -1 0 -1 -1 -1 -1 -1 -1 0 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 -1 0 -1 -1 0 -1 -1 0 -1 0 -1 0 -1 -1 -1 -1 -1 -1 0 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 -1 -1 -1 -1 0 -1 -1 -1 -1 -1 -...

output:

39803
29623
63234
76116
87461
45159
12590
58765
7365
60656
1333
827
21466
7412
20037
21268
71878
14866
48131
59337
29187
66884
2578
94083
10058
23669
70154
29562
64147
74928
9714
61444
43695
25505
44102
89065
53943
61516
9907
29901
92226
17249
21627
45499
75849
54272
22009
10210
41368
99653
17547
43...

result:

ok 1000000 lines

Test #22:

score: 10
Accepted
time: 1916ms
memory: 166560kb

input:

1000000 1000000
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 -1 0 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1...

output:

41794
11248
19370
9521
15603
231
33587
39333
33779
21719
13484
35524
29843
20241
10670
33496
23214
33568
43776
30681
495
8566
17874
35327
13257
40753
26163
17324
12968
7409
24322
17057
13897
48782
29846
19715
49649
38079
16190
42374
43535
7308
22123
7177
8266
28008
40105
12128
14380
45158
48919
3273...

result:

ok 1000000 lines

Subtask #4:

score: 10
Accepted

Test #23:

score: 10
Accepted
time: 1693ms
memory: 166280kb

input:

1000000 1000000
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1...

output:

99
15
51
89
58
47
81
4
40
58
14
26
26
2
62
3
28
51
13
23
91
62
25
6
56
7
25
56
87
8
66
40
56
50
75
68
70
51
54
64
79
22
59
53
45
5
13
34
44
67
18
48
7
13
63
84
50
45
48
42
47
47
4
89
35
22
59
55
5
69
14
61
84
91
51
55
92
28
31
68
17
58
50
81
61
58
54
91
34
12
26
80
50
21
6
7
43
11
73
70
1
49
35
42
1...

result:

ok 1000000 lines

Test #24:

score: 10
Accepted
time: 1692ms
memory: 166324kb

input:

1000000 1000000
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1...

output:

80
76
92
88
88
24
88
70
71
23
40
93
52
46
63
41
50
44
60
37
40
29
32
38
17
29
86
53
37
9
39
50
39
57
95
2
66
5
34
81
47
53
19
82
61
2
9
86
57
85
66
73
71
84
3
60
34
75
80
56
58
87
68
94
2
68
14
80
52
97
16
41
97
64
35
84
83
26
46
24
88
26
30
92
56
38
88
95
5
18
100
19
42
8
56
24
44
69
99
16
50
71
10...

result:

ok 1000000 lines

Test #25:

score: 10
Accepted
time: 1718ms
memory: 166432kb

input:

1000000 1000000
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1...

output:

31
56
68
1
88
75
26
48
60
62
24
63
5
51
24
29
30
72
15
73
50
87
82
11
55
56
84
37
57
87
22
75
93
86
58
28
25
21
90
97
66
11
49
65
8
37
100
93
77
90
47
5
21
18
20
100
42
28
88
99
34
34
66
96
9
50
56
13
76
95
31
70
16
90
95
25
44
97
77
100
48
7
23
88
76
48
43
22
92
71
49
6
81
51
16
5
29
32
44
93
42
24...

result:

ok 1000000 lines

Subtask #5:

score: 0
Time Limit Exceeded

Test #26:

score: 0
Time Limit Exceeded

input:

1000000 499990
-1 0 -1 0 0 0 -1 0 0 0 -1 0 0 0 -1 -1 0 0 0 -1 0 -1 -1 0 0 0 0 -1 -1 0 -1 -1 -1 0 -1 0 -1 0 -1 0 0 0 0 -1 0 -1 0 0 0 0 0 -1 0 -1 -1 -1 0 -1 -1 0 0 0 0 -1 -1 -1 0 0 0 -1 -1 0 0 -1 0 -1 -1 0 -1 -1 -1 0 0 0 -1 0 0 0 0 -1 0 0 -1 -1 0 -1 0 0 -1 -1 0 0 -1 0 0 0 -1 -1 -1 -1 0 -1 0 -1 -1 -1 0...

output:


result:


Subtask #6:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Dependency #5:

0%