QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#606451#2645. Collapsehztmax0100 ✓2636ms19868kbC++174.8kb2024-10-03 08:41:152024-10-03 08:41:16

Judging History

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

  • [2024-10-03 08:41:16]
  • 评测
  • 测评结果:100
  • 用时:2636ms
  • 内存:19868kb
  • [2024-10-03 08:41:15]
  • 提交

answer

#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <numeric>
#include <algorithm>
#include "collapse.h"

using namespace std;
using Pii = pair<int, int>; 

const int N = 1e5 + 5, B = 333;

int n, m, q;
int fa[N], p[N];
set<Pii> es;
map<Pii, int> mp;

struct E {
  int x, y, l, r;

  // One edge connected x and y with time [l, r]
}; 

struct Q {
  int t, p, id;
}; 

struct Union_find {
  int fa[N], d[N]; 
  vector<Pii> v; 

  void Init () {
    iota(fa + 1, fa + n + 1, 1);
    fill(d + 1, d + n + 1, 0);
    v.clear();
  }

  int Find (int x) {
    return fa[x] == x ? x : Find(fa[x]);
  } 

  void Unite (int x, int y) {
    x = Find(x), y = Find(y);
    if (d[x] < d[y]) swap(x, y);
    v.push_back({y, d[x]});
    fa[y] = x; 
    d[x] = max(d[x], d[y] + 1);
  }

  bool Try_to_unite (int x, int y) {
    x = Find(x), y = Find(y);
    if (x == y) return 0;  
    Unite(x, y); 
    return 1;
  }

  int Get_time () {
    return v.size();
  }

  void Roll_back (int t) {
    while (v.size() > t) {
      Pii t = v.back();
      v.pop_back();
      d[fa[t.first]] = t.second;
      fa[t.first] = t.first;
    }
  }
} uf;

vector<E> ev; 

int Find (int x) {
  if (fa[x] == x) return x;
  return fa[x] = Find(fa[x]);
} 

vector<int> simulateCollapse (int N, vector<int> T, vector<int> X, vector<int> Y, vector<int> W, vector<int> P) {
  [&]() -> void {
    // Remake
    n = N, m = T.size(), q = W.size();
    for (auto &x : X) ++x;
    for (auto &y : Y) ++y; 
    for (auto &w : W) ++w;
    for (auto &p : P) ++p;
    for (int i = 0; i < m; ++i) {
      if (X[i] > Y[i]) 
        swap(X[i], Y[i]);
    }
    for (int i = 0; i < m; ++i) {
      int x = X[i], y = Y[i];
      if (!T[i]) {
        mp.insert({{x, y}, i + 1});
      }
      else {
        auto it = mp.find({x, y});
        ev.push_back(E({x, y, it->second, i}));
        mp.erase(it);
      }
    }
    for (auto i : mp) {
      ev.push_back(E({i.first.first, i.first.second, i.second, m})); 
    }
    
    // cout << "Edge set : " << '\n';
    // for (auto i : ev) {
    //   cout << i.x << ' ' << i.y << ' ' << i.l << ' ' << i.r << '\n';
    // }
    // cout << "-------------" << '\n';
    // exit(0);
  }();
  iota(p, p + q, 0);
  sort(p, p + q, [&](int i, int j) -> bool {
    return W[i] < W[j];
  });
  vector<int> ans(q);
  for (int tl = 0, tr; tl < q; tl = tr + 1) {
    tr = min(tl + B - 1, q - 1);
    int L = W[p[tl]], R = W[p[tr]];
    vector<Pii> cover;
    vector<E> vec; 
    for (auto e : ev) {
      if (e.l <= L && e.r >= R) {
        cover.push_back({e.x, e.y});
      }
      else if (R >= e.l && e.r >= L) {
        vec.push_back(e);
      }
    }
    sort(cover.begin(), cover.end(), [&](Pii a, Pii b) -> bool {
      return a.second < b.second;
    });
    vector<Q> qv;
    for (int i = tl; i <= tr; ++i) {
      int id = p[i];
      qv.push_back(Q({W[id], P[id], id}));
    }
    sort(qv.begin(), qv.end(), [&](Q a, Q b) -> bool {
      return a.p < b.p;
    });
    auto cur = cover.begin();
    uf.Init();
    int ucnt = 0;
    // The times of successful merge
    for (auto q : qv) {
      int p = q.p, t = q.t, id = q.id;
      while (cur != cover.end() && cur->second <= p) {
        ucnt += uf.Try_to_unite(cur->first, cur->second);
        ++cur;
      }
      int timel = uf.Get_time(), tmpcnt = 0; 
      for (auto e : vec) {
        if (e.l <= t && e.r >= t && e.y <= p) {
          tmpcnt += uf.Try_to_unite(e.x, e.y);
        }
      }
      ans[q.id] += p - ucnt - tmpcnt;
      uf.Roll_back(timel);
    }
    reverse(qv.begin(), qv.end());
    sort(cover.begin(), cover.end(), [&](Pii a, Pii b) -> bool {
      return a.first > b.first;
    });
    cur = cover.begin();
    uf.Init();
    ucnt = 0; 
    for (auto q : qv) {
      int p = q.p, t = q.t, id = q.id;
      while (cur != cover.end() && cur->first > p) {
        ucnt += uf.Try_to_unite(cur->first, cur->second);
        ++cur;
      }
      int timel = uf.Get_time(), tmpcnt = 0;
      for (auto e : vec) {
        if (e.l <= t && e.r >= t && e.x > p) {
          tmpcnt += uf.Try_to_unite(e.x, e.y);
        }
      }
      ans[q.id] += (n - p) - ucnt - tmpcnt;
      uf.Roll_back(timel);
    }
  }
  return ans;
}

// void Test () {
//   int N, C, Q;
//   cin >> N >> C >> Q;
//   vector<int> T, X, Y;
//   for (int i = 0, t, x, y; i < C; ++i) {
//     cin >> t >> x >> y;
//     T.push_back(t), X.push_back(x), Y.push_back(y);
//   }
//   vector<int> W, P;
//   for (int i = 0, w, p; i < Q; ++i) {
//     cin >> w >> p;
//     W.push_back(w), P.push_back(p);
//   }
//   vector<int> ans = simulateCollapse(N, T, X, Y, W, P);
//   for (auto i : ans) {
//     cout << i << '\n';
//   }
// }

// int main () { Test(); }

詳細信息

Subtask #1:

score: 5
Accepted

Test #1:

score: 5
Accepted
time: 4ms
memory: 4152kb

input:

2 5000 5000
0 0 1
1 0 1
0 0 1
1 1 0
0 1 0
1 1 0
0 1 0
1 0 1
0 1 0
1 0 1
0 0 1
1 0 1
0 1 0
1 1 0
0 1 0
1 1 0
0 0 1
1 0 1
0 1 0
1 0 1
0 1 0
1 0 1
0 0 1
1 0 1
0 1 0
1 1 0
0 0 1
1 1 0
0 1 0
1 1 0
0 1 0
1 1 0
0 1 0
1 0 1
0 1 0
1 0 1
0 0 1
1 0 1
0 0 1
1 0 1
0 0 1
1 0 1
0 1 0
1 1 0
0 1 0
1 0 1
0 0 1
1 1 0
...

output:

2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
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2
3
2
7
3
3
9
2
2
2
6
2
9
2
2
2
2
3
7
2
8
2
2
2
2
5
8
2
2
2
2
2
6
2
3
9
3
2
2
2
3
3
2
2
3
5
4
6
2
2
7
2
2
2
...

result:

ok 5000 lines

Test #5:

score: 5
Accepted
time: 5ms
memory: 4160kb

input:

10 5000 5000
0 5 1
1 1 5
0 9 1
1 9 1
0 6 2
1 2 6
0 6 2
1 6 2
0 4 2
1 4 2
0 8 7
1 8 7
0 3 0
1 3 0
0 8 3
1 8 3
0 3 5
1 3 5
0 9 2
1 9 2
0 9 6
1 6 9
0 1 5
0 4 3
1 1 5
1 4 3
0 2 6
0 9 4
1 4 9
1 2 6
0 1 4
1 1 4
0 1 6
1 6 1
0 9 3
0 2 7
1 7 2
1 3 9
0 6 9
0 2 5
1 9 6
0 1 3
1 3 1
0 0 4
0 8 7
1 5 2
1 7 8
1 0 4...

output:

3
4
7
5
9
3
5
4
4
5
10
4
2
7
8
7
2
3
3
8
5
2
6
10
8
3
10
10
8
2
4
3
5
5
6
5
5
9
3
2
2
3
9
5
2
2
3
10
5
10
2
8
4
9
4
9
2
2
5
2
7
10
5
4
2
2
8
5
4
4
6
9
10
2
3
5
3
8
5
8
3
2
9
3
3
9
7
5
5
5
6
10
10
4
10
7
5
9
9
8
2
2
6
8
2
6
2
2
6
6
2
8
3
2
2
5
4
3
9
2
8
5
3
9
4
9
2
3
6
8
8
3
3
7
3
6
8
7
10
4
3
2
5
2
...

result:

ok 5000 lines

Test #6:

score: 5
Accepted
time: 14ms
memory: 4520kb

input:

100 4950 5000
0 38 3
0 56 61
0 87 71
0 64 10
0 92 60
0 44 11
0 3 7
0 81 41
0 43 72
0 73 61
0 77 23
0 63 20
0 64 16
0 11 37
0 51 97
0 80 10
0 56 2
0 76 42
0 69 74
0 26 28
0 40 37
0 5 35
0 25 22
0 95 35
0 89 34
0 3 88
0 26 17
0 40 8
0 8 79
0 48 6
0 18 94
0 76 75
0 44 22
0 30 94
0 50 41
0 92 45
0 11 20...

output:

2
2
2
2
2
2
2
2
2
3
2
2
5
2
2
7
2
2
2
2
2
3
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
3
2
2
2
2
2
2
4
2
2
3
2
2
2
68
2
2
2
2
2
3
2
2
2
2
2
2
2
2
2
7
3
2
2
2
2
2
2
2
2
2
13
2
2
2
9
9
71
3
2
7
2
2
2
13
2
9
3
2
2
2
2
2
3
2
2
8
2
2
2
2
2
2
2
2
2
2
2
3
2
2
2
7
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
...

result:

ok 5000 lines

Test #7:

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

input:

5000 1 5000
0 4285 4296
0 174
0 1012
0 3399
0 3238
0 1816
0 4133
0 3019
0 4260
0 2930
0 4630
0 1081
0 2725
0 4468
0 3870
0 1078
0 2021
0 2532
0 4271
0 3007
0 4647
0 3279
0 1541
0 4631
0 2309
0 2625
0 1049
0 3253
0 1274
0 4488
0 4202
0 885
0 2684
0 2656
0 1036
0 2263
0 2196
0 4410
0 1974
0 2852
0 113...

output:

4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
...

result:

ok 5000 lines

Test #8:

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

input:

5000 13 5000
0 1437 2917
0 4619 3686
0 4797 4454
0 3445 4933
0 561 1988
1 4797 4454
1 1988 561
0 1409 339
0 2874 2680
0 1266 4421
0 803 4698
0 3886 2422
1 3686 4619
1 2249
7 4184
3 4331
3 1568
4 4846
1 3533
12 2754
6 232
4 3193
9 2272
7 2268
10 4048
8 4216
6 3985
0 4840
12 3065
5 2887
12 592
2 1092
...

output:

4999
4998
4998
4997
4996
4998
4998
4997
4995
4996
4997
4997
4997
4999
4999
4996
4997
4994
4997
4996
4999
4997
4996
4995
4995
4997
4998
4996
4998
4996
4999
4998
4995
4996
4997
4996
4998
4996
4994
4996
4996
4998
4997
4996
4999
4998
4993
4997
4997
4998
4997
4999
4996
4992
4998
5000
4993
4998
4997
4997
...

result:

ok 5000 lines

Test #9:

score: 5
Accepted
time: 3ms
memory: 4488kb

input:

5000 5000 5000
0 975 2469
1 2469 975
0 3116 3798
0 2112 4747
0 1861 3986
1 3798 3116
0 2915 1795
0 1550 3770
0 433 3583
1 4747 2112
0 1153 4006
0 2233 3268
1 4006 1153
0 4456 1149
0 4 655
0 4058 2897
1 2915 1795
0 1725 1423
0 2206 1507
1 4058 2897
1 1423 1725
1 4 655
1 433 3583
0 4821 1327
0 1407 24...

output:

4961
4981
4994
4986
4974
4993
4987
4987
4981
4998
4986
4994
4997
4974
4986
4998
5000
4988
4993
4982
4993
4984
4993
4965
4996
4968
4997
4963
4986
4996
4996
4982
4996
4993
4998
4992
4972
4999
4999
4991
4996
5000
4999
4987
4961
4991
4993
4979
4994
4981
4999
4983
4989
4975
4996
4993
4989
4998
5000
4991
...

result:

ok 5000 lines

Test #10:

score: 5
Accepted
time: 12ms
memory: 4264kb

input:

5000 5000 5000
0 3449 1421
1 1421 3449
0 253 3884
1 253 3884
0 2908 3268
0 4948 3871
0 2908 3908
1 2908 3268
0 4186 1306
1 3871 4948
1 2908 3908
1 4186 1306
0 3741 2117
0 1391 4186
0 778 509
0 1597 2117
1 4186 1391
0 2908 4020
1 4020 2908
1 1597 2117
0 4948 3179
0 196 4186
0 2117 1579
1 778 509
1 41...

output:

4464
4508
4509
4635
4763
4516
4646
4766
4525
4772
4789
4388
4910
4779
4907
4409
4907
4724
4669
4873
4850
4545
4383
4438
4509
4850
4537
4859
4725
4828
4532
4826
4629
4299
4957
4477
4992
4543
4805
4656
4996
4832
4465
4729
4923
4717
4364
4564
4456
4388
4680
4534
4800
4457
4734
4747
4793
4740
4926
4532
...

result:

ok 5000 lines

Test #11:

score: 5
Accepted
time: 20ms
memory: 4676kb

input:

5000 5000 5000
0 1900 2340
0 4130 1922
0 4969 1233
0 2827 3942
0 3982 1431
0 3486 3980
0 3997 2929
0 2449 3118
0 3060 2285
0 971 2628
0 1938 1814
0 240 4209
0 2249 2974
0 2372 1784
0 3729 4064
0 3636 2763
0 3518 2722
0 3948 2501
0 200 1592
0 3783 1348
0 3343 1642
0 4576 3200
0 1460 1735
0 3938 2178
...

output:

4740
2997
3403
4239
2531
4424
2465
2519
3310
2420
3799
1923
3777
2055
3063
3748
2640
4713
4792
3263
3068
3434
4461
2712
3717
1634
1751
2536
4249
4870
4382
3349
3591
4942
3143
2777
4796
4931
1675
3006
3737
3628
1197
2662
2059
3752
3720
3887
4469
4127
4526
1813
4369
4559
4582
3506
4054
3771
3815
2561
...

result:

ok 5000 lines

Test #12:

score: 5
Accepted
time: 13ms
memory: 4568kb

input:

5000 5000 5000
0 976 1107
0 2771 4969
0 976 3008
0 155 976
0 3048 3929
0 4548 2155
0 3811 3048
0 4982 3048
0 4308 976
0 3048 2390
0 3048 3912
0 3250 2339
0 2660 976
0 976 2307
0 3048 4635
0 3048 1329
0 952 1913
0 4996 8
0 3717 976
0 2022 4914
0 3048 457
0 976 740
0 976 991
0 2989 3048
0 976 4925
0 3...

output:

3578
2489
4843
4622
3701
3077
4881
2925
2394
2513
3902
2867
4299
4769
4021
2773
3530
3958
4462
4306
4707
2657
4068
4490
2105
3627
3887
2680
4428
4258
3269
4525
4126
2759
3107
4294
2508
2012
3755
3588
4804
3768
3122
2763
3570
1818
3020
4546
3826
3357
2310
3197
3512
3293
3145
3089
4023
3132
4052
2462
...

result:

ok 5000 lines

Subtask #2:

score: 30
Accepted

Test #13:

score: 30
Accepted
time: 10ms
memory: 5580kb

input:

2 1 100000
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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4
4
4
5
5
5
4
5
4
4
5
5
4
4
5
4
4
4
5
4
5
4
5
5
4
4
4
5
5
4
4
5
5
4
5
4
4
5
5
5
5
4
4
4
4
4
4
5
5
4
4
5
4
5
5
5
5
4
5
4
4
4
5
5
...

result:

ok 100000 lines

Test #15:

score: 30
Accepted
time: 103ms
memory: 8656kb

input:

10 100000 100000
0 4 5
0 2 0
1 2 0
0 1 8
1 5 4
0 8 6
0 2 3
0 1 7
1 7 1
1 8 6
0 6 0
0 9 1
0 2 1
0 0 7
1 7 0
1 8 1
1 2 1
1 1 9
0 9 4
1 6 0
1 4 9
1 3 2
0 2 6
0 5 4
0 7 5
0 1 9
0 6 0
1 1 9
1 0 6
0 3 8
1 6 2
1 7 5
1 4 5
1 8 3
0 1 5
0 1 6
0 1 9
1 6 1
1 9 1
1 5 1
0 7 2
1 2 7
0 8 9
1 9 8
0 9 4
0 9 1
0 4 1
1...

output:

2
2
2
9
3
2
9
7
2
5
2
3
5
9
2
3
9
10
4
2
2
3
2
3
2
2
2
2
3
2
8
10
5
7
2
2
7
2
9
3
3
2
9
10
2
2
2
3
8
4
2
2
2
2
4
8
9
3
2
2
4
8
2
2
7
2
3
2
2
4
2
2
5
5
5
4
2
2
2
2
2
2
3
2
2
5
3
2
2
10
2
2
10
2
8
2
6
3
3
2
2
6
4
2
5
10
2
2
2
4
4
9
3
2
2
2
5
2
10
8
5
2
3
2
2
2
2
2
2
8
4
9
2
2
2
2
2
3
2
2
5
2
9
2
6
4
4...

result:

ok 100000 lines

Test #16:

score: 30
Accepted
time: 18ms
memory: 5552kb

input:

10 45 100000
0 9 7
0 0 6
0 3 2
0 7 8
0 3 7
0 1 0
0 2 8
0 8 3
0 0 4
0 8 4
0 7 0
0 6 1
0 0 3
0 8 1
0 5 8
0 5 1
0 7 6
0 4 2
0 9 3
0 0 9
0 3 1
0 3 6
0 5 3
0 9 8
0 2 9
0 7 1
0 4 6
0 0 8
0 9 5
0 6 2
0 4 5
0 4 7
0 0 2
0 6 9
0 5 6
0 5 0
0 8 6
0 1 9
0 1 2
0 1 4
0 4 3
0 9 4
0 5 7
0 2 7
0 5 2
1 6
14 6
26 6
6 6...

output:

8
3
2
5
3
2
2
5
2
2
2
2
5
2
2
9
5
2
2
2
2
2
2
2
3
2
2
3
2
2
4
4
2
2
2
5
3
2
4
2
2
3
2
3
2
3
5
3
9
5
2
4
4
3
2
2
7
2
4
2
6
7
4
2
2
4
3
2
2
2
2
2
2
6
4
2
2
9
4
7
4
2
2
3
6
2
2
2
4
2
2
2
2
2
2
4
9
2
9
2
3
2
2
2
2
2
3
2
2
3
2
2
2
2
2
2
2
2
2
2
2
6
2
2
2
5
2
2
4
2
2
2
2
2
4
2
2
6
2
2
2
2
6
2
2
4
2
2
2
5
...

result:

ok 100000 lines

Test #17:

score: 30
Accepted
time: 137ms
memory: 8748kb

input:

100 100000 100000
0 12 26
1 12 26
0 44 29
1 44 29
0 21 32
1 21 32
0 81 30
1 30 81
0 93 39
0 26 5
1 39 93
0 93 87
0 60 13
1 87 93
1 13 60
1 26 5
0 26 84
1 26 84
0 26 50
0 44 32
1 26 50
0 61 86
1 61 86
1 32 44
0 69 59
0 68 92
0 37 21
0 5 53
1 37 21
0 87 78
0 64 9
1 64 9
1 53 5
1 92 68
0 31 66
1 66 31
...

output:

19
25
62
11
13
61
20
31
79
83
63
50
94
9
35
31
17
17
86
56
98
9
69
38
54
91
78
11
69
30
8
41
10
33
5
45
48
70
76
80
9
59
7
58
24
15
35
97
96
46
88
38
19
38
86
18
49
70
61
14
37
58
5
91
35
23
30
29
61
56
13
55
12
63
56
74
67
40
92
12
81
14
42
29
68
93
10
10
19
84
60
32
77
67
44
96
38
98
9
13
21
97
60...

result:

ok 100000 lines

Test #18:

score: 30
Accepted
time: 76ms
memory: 6348kb

input:

100 4950 100000
0 84 47
0 31 87
0 62 83
0 54 79
0 41 94
0 87 43
0 46 70
0 84 93
0 33 91
0 0 87
0 36 88
0 8 74
0 86 39
0 99 23
0 74 33
0 86 11
0 29 8
0 24 23
0 5 97
0 7 68
0 9 8
0 17 22
0 75 55
0 61 35
0 32 18
0 20 38
0 99 89
0 89 80
0 96 29
0 5 27
0 90 6
0 36 1
0 83 49
0 69 33
0 70 36
0 4 94
0 51 74...

output:

8
2
2
2
2
2
2
2
2
2
2
2
2
9
2
2
2
2
2
2
2
2
2
6
2
2
2
2
2
2
2
2
2
2
2
2
2
2
9
2
2
2
2
12
2
2
2
19
65
2
2
2
2
2
2
58
9
2
2
2
2
7
2
11
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
8
89
2
2
2
2
2
2
2
2
9
2
2
2
2
2
2
2
2
2
2
2
2
2
2
87
2
2
2
2
2
2
2
2
2
2
2
2
3
2
2
2
2
2
21
2
2
2
2
65
2
2
2
2
2
2
2
2
2
2...

result:

ok 100000 lines

Test #19:

score: 30
Accepted
time: 1432ms
memory: 17672kb

input:

1000 100000 100000
0 401 876
0 420 792
0 965 268
0 909 871
0 736 337
0 341 634
0 112 317
0 685 606
0 778 506
0 162 289
0 375 590
0 874 77
0 434 986
0 78 804
0 743 760
0 290 466
0 721 828
0 44 145
0 601 101
0 223 651
0 327 860
0 105 727
0 447 93
0 680 298
0 868 502
0 130 527
0 567 523
0 871 862
0 423...

output:

9
2
2
2
166
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
483
2
2
2
2
2
2
2
49
2
2
2
2
2
2
2
2
2
2
2
198
804
2
2
3
2
9
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
9
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
200
2
2
2
2
2...

result:

ok 100000 lines

Test #20:

score: 30
Accepted
time: 142ms
memory: 8708kb

input:

10000 100000 100000
0 3029 6081
0 8203 8589
1 3029 6081
1 8203 8589
0 5644 5052
0 7453 4217
1 4217 7453
0 411 1437
0 6129 6204
1 6129 6204
1 411 1437
1 5052 5644
0 3706 3648
1 3648 3706
0 4124 255
1 4124 255
0 6254 1238
1 6254 1238
0 315 9450
0 3482 4345
0 5779 9692
0 8499 9981
0 9054 4198
1 3482 43...

output:

9954
9868
9838
9950
9998
9870
9919
9954
9980
9949
9944
9911
9836
9904
9970
9943
9890
9903
9871
9984
9998
9934
9950
9885
9922
9997
9981
9953
9870
9942
9924
9916
9996
9899
9995
9937
9901
9878
9986
9854
9928
9981
9966
9990
9926
9974
9977
9881
9908
9996
9980
9843
9940
9944
9887
9903
9860
9897
9952
9880
...

result:

ok 100000 lines

Test #21:

score: 30
Accepted
time: 35ms
memory: 6376kb

input:

100000 1 100000
0 82807 93097
0 73456
0 73456
0 73456
0 73456
0 73456
0 73456
0 73456
0 73456
0 73456
0 73456
0 73456
0 73456
0 73456
0 73456
0 73456
0 73456
0 73456
0 73456
0 73456
0 73456
0 73456
0 73456
0 73456
0 73456
0 73456
0 73456
0 73456
0 73456
0 73456
0 73456
0 73456
0 73456
0 73456
0 7345...

output:

99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
...

result:

ok 100000 lines

Test #22:

score: 30
Accepted
time: 42ms
memory: 6572kb

input:

100000 13 100000
0 1439 16071
0 77126 71233
0 65676 31466
0 46411 63728
0 89638 56713
0 87375 51822
1 51822 87375
0 8857 81973
1 46411 63728
0 3682 72818
0 99222 1242
0 9034 60037
1 8857 81973
9 24572
11 24572
11 24572
9 24572
10 24572
12 24572
12 24572
9 24572
9 24572
1 24572
5 24572
1 24572
10 245...

output:

99996
99996
99996
99996
99996
99996
99996
99996
99996
99998
99994
99998
99996
99995
99998
99996
99996
99996
99996
99996
99997
99996
99996
99995
99996
99998
99996
99995
99996
99997
99996
99999
99996
99995
99995
99998
99998
99996
99995
99997
99995
99996
99995
99996
99996
99995
99996
99995
99996
99996
...

result:

ok 100000 lines

Test #23:

score: 30
Accepted
time: 56ms
memory: 6720kb

input:

100000 1300 100000
0 89356 81602
0 25968 71253
1 71253 25968
1 81602 89356
0 9552 48034
1 48034 9552
0 60781 48013
1 48013 60781
0 37834 44402
1 44402 37834
0 65946 49304
0 18516 23388
0 29228 56191
1 23388 18516
0 59336 2420
0 93358 56425
1 56425 93358
1 65946 49304
0 54778 99482
1 54778 99482
1 29...

output:

100000
99959
99919
99844
99931
99870
99885
99972
99848
99619
99897
99730
99916
99947
99926
99796
99832
99920
99620
99880
99690
99888
99888
99865
99730
99914
99690
99916
99681
99757
99720
99962
99864
99795
99685
99962
99618
99915
99752
99681
99962
99687
99622
99798
99795
99877
99786
99796
99756
99963...

result:

ok 100000 lines

Test #24:

score: 30
Accepted
time: 166ms
memory: 9396kb

input:

100000 100000 100000
0 17804 63065
1 63065 17804
0 45575 88403
1 45575 88403
0 80699 2416
1 80699 2416
0 31614 61013
0 56546 21713
1 31614 61013
1 56546 21713
0 62497 35703
1 35703 62497
0 31149 60185
1 60185 31149
0 78537 84342
1 78537 84342
0 32132 70924
1 70924 32132
0 43661 10068
0 347 91377
0 5...

output:

99867
99992
99898
99888
99915
99975
99864
99877
99876
99861
99866
99864
99986
99997
99908
99990
99835
99886
99819
99894
99918
99844
99877
99982
99887
99900
99867
99886
99910
99988
99918
99936
99913
99961
99891
99928
99850
99948
99974
99865
99800
99895
99953
99863
99958
99836
99961
99841
99945
99867
...

result:

ok 100000 lines

Test #25:

score: 30
Accepted
time: 767ms
memory: 13188kb

input:

100000 100000 100000
0 24907 27865
1 27865 24907
0 52274 52157
0 33 31159
0 55043 23321
0 82744 42837
1 31159 33
1 82744 42837
0 88688 98999
1 52274 52157
0 51278 31159
1 88688 98999
1 55043 23321
0 61377 31159
0 26891 98999
0 98999 45687
0 43623 39111
0 89515 31159
1 45687 98999
0 38524 94012
0 152...

output:

93423
87123
82099
95363
93522
88616
96001
88490
87910
87114
90029
84266
89936
98685
84402
88903
96346
86243
89791
84715
95956
98159
84744
93347
99490
83760
96070
86758
89011
82768
88238
81508
92733
84987
93386
94883
84738
97333
86359
81562
92756
85568
85310
88344
93250
81356
83659
99905
82166
85746
...

result:

ok 100000 lines

Test #26:

score: 30
Accepted
time: 2094ms
memory: 18636kb

input:

100000 100000 100000
0 51121 62431
0 99918 74056
0 60825 71018
0 7595 24939
0 98355 56680
0 53097 32198
0 6546 74840
0 53620 67586
0 32747 14603
0 15566 41025
0 10663 7997
0 63554 41417
0 86524 78350
0 93313 23614
0 48984 86305
0 29296 37851
0 69475 8084
0 58875 73654
0 92009 45536
0 89865 67813
0 2...

output:

88708
54743
74756
52508
82115
60826
55492
61928
78480
88881
70276
64099
96761
54320
52627
75089
79098
65142
56337
53275
72623
96839
73044
72228
96403
94337
55788
79638
55339
84654
73149
87995
94910
86555
92763
77829
51834
93682
60263
75213
92260
83673
80054
70258
86209
97431
58540
95354
77864
65201
...

result:

ok 100000 lines

Test #27:

score: 30
Accepted
time: 1390ms
memory: 19188kb

input:

100000 100000 100000
0 89314 98452
0 72955 89314
0 95887 89314
0 28546 37614
0 67761 89314
0 57217 89314
0 13498 89314
0 19464 89314
0 89314 75998
0 89314 3870
0 29915 89314
0 54647 89314
0 29791 89314
0 89314 67142
0 97782 89314
0 71818 89314
0 89314 81825
0 89314 5179
0 89314 11827
0 89314 29810
0...

output:

76456
55592
70239
93604
83773
96733
56888
88513
99477
65201
78604
64096
93431
78182
99725
88413
81654
67948
82865
82661
97307
78239
92785
68980
74987
62001
80105
84208
93063
78936
58274
82054
82905
91269
57440
79094
98253
72375
65912
98241
61274
67790
94902
86726
87733
92843
83379
61042
76099
82396
...

result:

ok 100000 lines

Subtask #3:

score: 30
Accepted

Test #28:

score: 30
Accepted
time: 14ms
memory: 5484kb

input:

2 1 100000
0 1 0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
4
4
5
3
5
5
3
2
3
4
5
2
3
4
3
4
3
5
2
5
4
5
2
4
2
5
2
4
5
4
3
2
3
3
3
2
4
5
4
5
4
4
2
3
4
3
3
2
3
2
3
3
2
4
4
4
5
3
3
4
5
4
4
5
3
3
2
5
3
5
4
3
2
5
4
4
5
3
3
4
4
3
5
4
2
4
2
2
4
2
3
4
2
5
5
4
4
2
2
3
3
4
2
2
5
5
4
...

result:

ok 100000 lines

Test #30:

score: 30
Accepted
time: 16ms
memory: 5492kb

input:

10 20 100000
0 5 6
0 5 0
0 0 9
0 0 6
0 3 4
0 4 0
0 7 9
0 3 1
0 4 1
0 6 1
0 3 0
0 8 7
0 1 2
0 5 1
0 3 2
0 8 4
0 8 6
0 2 0
0 4 6
0 9 3
11 6
13 5
19 8
11 4
13 7
5 8
12 6
9 0
9 5
3 4
7 2
18 4
19 0
0 3
4 8
11 4
17 8
4 7
11 3
8 5
0 7
4 5
4 5
10 5
4 6
11 8
9 3
17 7
3 2
17 7
12 5
14 5
12 4
8 4
3 4
12 7
8 1
...

output:

3
3
2
4
4
6
2
5
5
9
7
2
2
9
7
4
2
7
5
5
9
8
8
5
7
4
7
4
9
4
3
3
3
5
9
4
7
5
3
3
5
9
5
3
8
5
4
8
7
7
4
9
9
7
3
9
5
8
8
4
3
6
8
4
8
8
5
2
4
10
3
2
7
2
3
8
9
8
2
7
4
9
2
3
4
4
4
9
9
7
5
2
3
9
2
8
9
8
6
7
9
8
8
2
8
5
6
3
9
2
9
4
9
6
4
7
4
3
5
3
9
7
7
2
5
8
4
7
8
6
2
8
9
5
2
8
7
10
5
9
5
2
5
7
9
3
10
4
2...

result:

ok 100000 lines

Test #31:

score: 30
Accepted
time: 19ms
memory: 5600kb

input:

10 45 100000
0 5 7
0 2 1
0 3 5
0 4 2
0 4 8
0 7 3
0 0 8
0 1 4
0 6 2
0 9 8
0 7 2
0 5 0
0 1 3
0 6 4
0 9 1
0 4 3
0 8 6
0 2 8
0 5 1
0 3 2
0 7 9
0 4 5
0 0 2
0 0 3
0 8 5
0 1 8
0 0 1
0 0 7
0 1 7
0 6 0
0 6 5
0 7 6
0 4 7
0 7 8
0 2 9
0 9 3
0 1 6
0 6 9
0 0 9
0 9 4
0 3 8
0 5 2
0 3 6
0 9 5
0 0 4
17 8
32 2
8 0
29 ...

output:

2
2
4
2
2
2
2
2
9
2
2
4
2
2
2
2
2
2
6
4
5
2
7
3
3
2
2
8
2
2
3
2
9
5
6
3
3
4
6
7
4
6
2
2
7
7
2
5
2
2
2
2
2
2
3
2
2
6
8
2
2
10
9
6
2
5
2
2
2
2
7
3
6
8
2
2
2
7
2
2
2
2
2
9
4
2
2
3
2
2
2
2
2
7
2
7
3
5
2
3
2
2
2
2
2
6
5
2
2
3
7
2
7
2
6
3
8
5
7
2
5
4
3
2
3
2
2
9
4
2
2
2
2
3
9
2
2
3
3
4
6
2
5
2
3
5
2
6
2
2...

result:

ok 100000 lines

Test #32:

score: 30
Accepted
time: 27ms
memory: 5660kb

input:

100 500 100000
0 75 20
0 23 42
0 53 70
0 11 28
0 23 67
0 74 63
0 93 4
0 13 43
0 96 72
0 2 65
0 43 96
0 86 52
0 77 38
0 89 33
0 85 84
0 55 48
0 8 20
0 7 18
0 43 62
0 38 44
0 42 24
0 98 6
0 92 66
0 17 33
0 4 70
0 12 74
0 13 99
0 79 63
0 53 14
0 38 22
0 54 41
0 61 44
0 85 21
0 25 38
0 38 28
0 81 87
0 7...

output:

8
19
7
7
5
51
5
8
16
8
3
6
5
3
42
3
6
5
9
15
3
9
7
6
5
26
12
4
22
22
3
13
11
6
99
3
79
2
30
3
2
9
56
5
67
2
43
4
12
3
28
26
11
6
5
18
2
6
72
6
17
2
11
18
48
86
3
3
85
6
10
3
7
36
5
3
6
12
5
3
38
3
3
11
9
93
54
60
8
22
35
4
34
16
48
6
11
5
5
31
99
43
60
5
11
8
2
21
69
3
94
50
8
3
8
3
8
6
25
28
3
6
2
...

result:

ok 100000 lines

Test #33:

score: 30
Accepted
time: 85ms
memory: 6452kb

input:

100 4950 100000
0 50 40
0 87 50
0 72 73
0 74 65
0 2 4
0 29 28
0 20 28
0 15 99
0 13 56
0 31 5
0 5 89
0 28 10
0 84 6
0 19 92
0 38 96
0 89 86
0 21 10
0 18 35
0 84 28
0 86 80
0 69 45
0 33 62
0 3 45
0 81 22
0 0 43
0 12 41
0 81 58
0 34 4
0 53 65
0 55 43
0 71 18
0 60 17
0 44 18
0 12 6
0 55 94
0 87 41
0 42 ...

output:

2
4
2
2
2
2
4
2
2
3
2
2
2
2
2
2
5
2
2
2
2
2
2
2
2
2
2
4
2
2
5
2
2
2
14
2
16
2
2
2
2
2
2
2
2
2
3
2
2
2
2
2
2
41
2
2
2
2
2
14
2
2
2
2
2
2
2
2
6
2
2
2
2
2
2
2
2
8
2
2
2
2
2
2
2
2
2
28
2
2
2
2
2
14
2
2
12
2
2
2
2
2
2
2
2
2
3
2
2
2
2
10
2
2
2
2
2
2
2
3
2
2
2
2
2
2
2
2
2
2
2
2
2
6
78
2
2
2
2
2
2
2
2
2
2
1...

result:

ok 100000 lines

Test #34:

score: 30
Accepted
time: 1183ms
memory: 14788kb

input:

1000 75000 100000
0 312 514
0 320 439
0 100 448
0 646 280
0 535 701
0 199 217
0 178 777
0 843 287
0 996 52
0 587 444
0 728 395
0 882 610
0 875 656
0 971 990
0 656 990
0 549 684
0 766 968
0 969 956
0 15 757
0 978 467
0 736 621
0 673 44
0 911 944
0 555 47
0 385 922
0 897 648
0 352 936
0 157 311
0 645 ...

output:

2
6
2
2
2
10
2
2
2
2
2
2
2
2
3
2
2
2
17
177
3
2
3
2
2
2
39
4
3
2
2
3
2
2
2
2
4
2
2
2
40
2
236
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
694
2
2
2
3
12
19
2
10
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
3
2
2
2
2
34
4
2
2
2
2
2
2
2
2
2
2
2
2
2
2
12
2
2
2
3
2
2
2
3
70
33
2
14
2
3
2
2
17
2
2
2
2
2
2
2
7
2
2
2
8
10
2
2
3
...

result:

ok 100000 lines

Test #35:

score: 30
Accepted
time: 2168ms
memory: 18000kb

input:

10000 100000 100000
0 4650 4651
0 5118 50
0 8501 1203
0 4320 9114
0 5284 84
0 7128 8483
0 6247 6754
0 4110 4770
0 7990 4574
0 1552 708
0 772 6932
0 924 9657
0 9165 8340
0 8946 1023
0 4548 8725
0 3262 6753
0 8435 8769
0 7335 9388
0 4270 5695
0 2997 5918
0 6108 18
0 724 5121
0 1094 3007
0 7024 4086
0 ...

output:

51
73
889
316
26
367
4
5327
2831
167
3436
107
142
37
8
510
9029
32
28
436
377
342
84
17
4266
38
2590
120
95
52
404
19
21
591
8941
5501
56
362
225
87
263
226
576
40
207
917
31
154
48
6348
1250
53
194
60
65
222
21
67
1688
620
342
62
946
155
25
207
61
1402
72
226
153
22
8283
314
7467
117
9033
17
7044
2...

result:

ok 100000 lines

Test #36:

score: 30
Accepted
time: 44ms
memory: 6380kb

input:

100000 1 100000
0 33336 16556
0 92196
0 26197
0 53372
0 38599
0 96200
0 44612
0 24541
0 75990
0 28525
0 25457
0 83626
0 61731
0 69015
0 29071
0 3513
0 39485
0 52956
0 9699
0 90062
0 41875
0 14538
0 74187
0 73753
0 97815
0 61704
0 86178
0 42498
0 44887
0 55131
0 98310
0 78129
0 54118
0 25940
0 11754
...

output:

99999
100000
99999
99999
99999
99999
100000
99999
100000
100000
99999
99999
99999
100000
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
100000
99999
100000
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999...

result:

ok 100000 lines

Test #37:

score: 30
Accepted
time: 68ms
memory: 6720kb

input:

100000 1000 100000
0 40911 70767
0 43851 74810
0 98101 23348
0 2588 74553
0 99709 32715
0 80067 21678
0 65194 58715
0 20669 33662
0 58431 82503
0 23326 15298
0 65281 6831
0 49793 40357
0 84369 53367
0 65621 16191
0 99338 18468
0 87123 1278
0 59646 15976
0 34874 48231
0 28748 77608
0 35658 19831
0 75...

output:

99535
99471
99799
99610
99996
99597
99721
99361
99778
99792
99768
99743
99656
99504
99638
99595
99552
99737
99882
99866
99084
99509
99941
99630
99745
99988
99547
99633
99860
99915
99552
99610
99329
99766
99922
99521
99815
99359
99621
99658
99442
99979
99982
99672
99971
99742
99867
99690
99834
99601
...

result:

ok 100000 lines

Test #38:

score: 30
Accepted
time: 1754ms
memory: 19568kb

input:

100000 100000 100000
0 58788 61813
0 21513 25800
0 88016 61813
0 61813 76909
0 80963 25800
0 10224 61813
0 6529 25800
0 84889 16488
0 25800 18639
0 61813 12954
0 86274 61813
0 61813 47108
0 87338 61813
0 31751 61813
0 33113 51903
0 16488 72671
0 28731 40816
0 16488 46955
0 25800 47670
0 72904 16488
...

output:

78047
60034
90581
63392
67541
60865
89448
81437
80808
79233
52778
88836
65017
68685
94108
41263
58600
55445
39882
58392
51111
98840
66143
82087
62682
89169
86782
58768
55792
96187
67172
45894
85547
78657
55227
61523
29863
74318
66324
66850
79441
68780
88962
60149
69875
92753
72295
47527
39478
71770
...

result:

ok 100000 lines

Test #39:

score: 30
Accepted
time: 2633ms
memory: 19100kb

input:

100000 100000 100000
0 20750 63020
0 78129 41347
0 6274 44744
0 84800 27790
0 38830 41299
0 45700 1339
0 54539 62677
0 66137 96771
0 97257 95836
0 99860 22225
0 1817 18865
0 76593 67906
0 14538 48021
0 53976 99932
0 18091 93984
0 81227 60047
0 71218 27770
0 62632 49210
0 85275 86222
0 10536 63833
0 ...

output:

88077
66351
43555
98311
76970
85188
67953
96695
98165
87840
97902
67078
65917
32814
60688
79773
87542
87169
90678
32969
18859
79587
68673
96540
63993
71149
84892
67772
82692
87232
62853
73469
55781
84424
54545
37716
47689
80251
24168
86865
93483
96163
44418
54410
87600
79937
69548
44728
56964
80189
...

result:

ok 100000 lines

Test #40:

score: 30
Accepted
time: 1991ms
memory: 19432kb

input:

100000 100000 100000
0 24007 36308
0 52927 68791
0 95137 45226
0 10784 75384
0 90861 35974
0 81890 88268
0 26777 14199
0 92428 85441
0 66610 8487
0 3746 34776
0 47521 89142
0 90743 35945
0 26115 27924
0 95170 63280
0 41624 77097
0 19642 34518
0 15117 62167
0 10663 77097
0 93671 2025
0 51770 75828
0 ...

output:

51411
77149
96113
77490
84598
62391
99241
46815
40291
74029
93925
67737
66450
93691
64564
75470
83557
63192
84727
57751
60141
64550
69346
88417
58038
87104
94220
63013
41891
92031
36584
77981
99097
58991
61542
62750
80874
95942
65306
46282
74545
97876
97610
66217
97809
89512
56091
50030
76977
85890
...

result:

ok 100000 lines

Test #41:

score: 30
Accepted
time: 2636ms
memory: 19460kb

input:

100000 100000 100000
0 65651 48902
0 84667 35936
0 73024 16804
0 5374 77124
0 17205 73436
0 18540 99513
0 7048 92935
0 72054 88567
0 77955 93939
0 99106 87086
0 9052 9237
0 34647 94136
0 90418 80149
0 55698 79280
0 60802 51478
0 20905 34292
0 95456 46928
0 98559 43417
0 11663 36243
0 16470 6130
0 52...

output:

81558
55935
31308
89473
94345
73763
82660
40166
69594
36585
91823
49813
72459
68991
35951
32853
64563
64550
70157
52290
76126
48299
65460
81567
73587
58624
59193
68437
75642
68679
70021
47115
47790
95440
78980
47420
93991
98741
83471
64897
92529
78684
74145
89346
88724
83537
58583
59499
55799
47347
...

result:

ok 100000 lines

Test #42:

score: 30
Accepted
time: 1860ms
memory: 19372kb

input:

100000 100000 100000
0 54220 61916
0 526 28325
0 14497 62560
0 38388 27290
0 94818 38388
0 23177 526
0 38388 56628
0 62560 84580
0 526 84615
0 38388 98919
0 9724 9093
0 10509 40011
0 92988 526
0 21318 68095
0 62560 95221
0 51163 73339
0 21318 52788
0 526 34532
0 61916 59601
0 18715 10509
0 67982 105...

output:

94878
79612
56533
73286
40137
59908
57270
70648
80252
67162
80149
89060
62846
62028
87195
80685
72870
84600
52422
98141
69384
68794
95212
90500
45747
84970
54626
82542
58343
89556
77480
70226
57173
76400
76532
55170
99615
96690
79350
96051
60899
34694
60962
40663
93677
93114
58047
61732
79378
90705
...

result:

ok 100000 lines

Subtask #4:

score: 35
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Test #43:

score: 35
Accepted
time: 156ms
memory: 8644kb

input:

1000 100000 100000
0 66 692
0 335 394
1 66 692
1 394 335
0 343 731
1 731 343
0 256 986
1 256 986
0 533 878
1 533 878
0 858 963
1 858 963
0 430 553
0 341 923
0 441 507
1 441 507
1 430 553
0 320 235
1 923 341
0 289 961
0 231 166
0 349 619
1 961 289
0 471 688
0 779 423
1 231 166
0 952 503
0 408 12
0 63...

output:

957
933
975
958
966
960
963
908
934
931
997
929
946
935
982
956
971
966
995
962
980
941
998
948
899
954
965
968
960
975
992
928
951
952
922
955
995
959
906
901
990
974
953
948
962
980
993
970
964
913
992
987
970
976
996
922
961
995
992
933
947
943
979
980
955
933
974
981
971
963
924
943
950
967
986
...

result:

ok 100000 lines

Test #44:

score: 35
Accepted
time: 1553ms
memory: 17608kb

input:

1000 100000 100000
0 341 571
0 649 510
0 311 906
0 525 596
0 807 126
0 772 230
0 158 979
0 211 530
0 917 465
0 738 54
0 83 48
0 757 503
0 673 77
0 962 884
0 391 501
0 997 203
0 72 441
0 423 710
0 293 566
0 192 948
0 602 42
0 752 787
0 421 120
0 382 932
0 859 399
0 414 973
0 261 784
0 165 752
0 345 9...

output:

2
2
2
2
2
2
36
2
2
2
2
17
22
2
2
2
35
2
2
5
2
19
6
2
4
2
2
2
2
4
2
2
2
2
2
2
2
2
2
2
2
2
2
2
6
2
2
2
2
2
6
2
2
5
2
2
2
6
2
2
2
2
2
2
9
2
2
2
2
2
2
2
5
2
2
2
9
807
2
2
2
2
2
2
2
2
652
2
3
10
2
2
2
2
2
14
2
2
2
2
2
2
2
2
2
2
2
194
2
2
2
2
2
273
2
2
2
2
2
2
31
2
4
2
2
2
2
2
2
2
2
2
2
2
26
2
2
2
2
2
2
1...

result:

ok 100000 lines

Test #45:

score: 35
Accepted
time: 178ms
memory: 8728kb

input:

10000 100000 100000
0 3670 2509
1 3670 2509
0 7036 958
0 9473 8298
1 9473 8298
0 9269 3377
1 3377 9269
0 2992 6308
0 9393 7775
1 9393 7775
0 3473 1372
1 2992 6308
0 5532 6329
1 1372 3473
0 4381 1690
1 1690 4381
0 1172 2325
1 2325 1172
1 7036 958
1 6329 5532
0 2275 859
1 859 2275
0 3590 8797
0 1540 7...

output:

9966
9845
9949
9820
9996
9932
9992
9990
9997
9965
9949
9941
9963
9982
9894
9852
9906
9914
9939
9994
9971
9853
9982
9929
9971
9986
9985
9923
9950
9971
9876
9937
9816
9893
9742
9927
9912
9977
9992
9856
9986
9887
9935
9770
9872
9993
9999
9903
9955
9951
9985
9930
9979
9883
9873
9957
9927
9968
10000
9963...

result:

ok 100000 lines

Test #46:

score: 35
Accepted
time: 2162ms
memory: 17780kb

input:

10000 100000 100000
0 2548 5477
0 450 2661
0 3481 7636
0 2515 6773
0 7012 174
0 5794 5569
0 4209 4035
0 717 7234
0 9247 2024
0 9022 6546
0 8350 363
0 5572 2439
0 1797 7956
0 6285 2028
0 2465 7642
0 5551 7585
0 9866 5959
0 4872 2518
0 9932 7361
0 5289 930
0 8182 7966
0 9903 1300
0 471 2967
0 4205 788...

output:

418
1317
1701
21
10
539
210
6
992
85
2037
8
1176
2097
6501
2
1024
186
45
290
408
2
148
3459
233
65
2805
272
33
6606
107
1477
493
651
315
72
2
46
7657
32
135
1017
5844
99
660
8608
387
7946
1821
64
249
1066
174
36
305
4
43
145
570
7
5101
1499
5
7637
81
74
445
2615
2907
15
414
2654
504
334
720
75
968
1...

result:

ok 100000 lines

Test #47:

score: 35
Accepted
time: 42ms
memory: 6328kb

input:

100000 1 100000
0 58538 55896
0 16718
0 88616
0 8082
0 75872
0 13446
0 45644
0 12270
0 56752
0 49864
0 23542
0 46346
0 12558
0 38585
0 40689
0 22822
0 65822
0 22151
0 97889
0 68645
0 33954
0 51780
0 19707
0 41611
0 70090
0 25382
0 10350
0 48631
0 60578
0 5937
0 8563
0 26546
0 15261
0 67933
0 14651
0...

output:

99999
99999
99999
99999
99999
99999
99999
100000
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999...

result:

ok 100000 lines

Test #48:

score: 35
Accepted
time: 44ms
memory: 6372kb

input:

100000 13 100000
0 59859 69181
0 47542 47530
1 47542 47530
0 48752 42093
0 23653 33947
0 42963 29275
0 71457 51715
1 51715 71457
1 29275 42963
0 17889 50694
0 96440 50858
0 71797 13691
0 43520 61519
1 73545
9 19648
6 19870
3 41487
3 6392
1 97342
0 10043
7 96936
7 59111
8 37313
7 33186
5 29571
10 687...

output:

99998
99997
99995
99998
99998
99998
99999
99996
99996
99997
99998
99998
99997
99996
99996
99996
99996
99997
99998
99998
99998
99997
99999
99996
99998
99997
99998
99995
99997
99997
99998
99998
99997
99998
99999
99996
99996
99998
99998
99996
99998
99997
99999
99998
99996
99996
99996
99996
99999
99996
...

result:

ok 100000 lines

Test #49:

score: 35
Accepted
time: 64ms
memory: 6648kb

input:

100000 1300 100000
0 59208 76440
0 79513 30538
0 38681 1368
1 59208 76440
0 78112 22549
0 2038 33638
1 1368 38681
0 74674 78619
0 32215 57517
1 74674 78619
0 33427 77902
0 53945 55685
0 34922 17383
0 85398 64824
0 64124 18659
1 30538 79513
0 62190 58056
1 64124 18659
1 17383 34922
0 56804 72251
1 53...

output:

99573
99862
99979
99824
99596
99615
99754
99798
99543
99805
99584
99871
99723
99964
99812
99789
99591
99786
99999
99980
99758
99867
99784
99779
99800
99872
99853
99557
99770
99825
99803
99861
99720
99738
99853
99870
99709
99872
99956
99967
99713
99600
99991
99365
99588
99625
99686
99881
99553
99640
...

result:

ok 100000 lines

Test #50:

score: 35
Accepted
time: 200ms
memory: 7428kb

input:

100000 13000 100000
0 8762 36932
1 8762 36932
0 67606 99988
0 61604 32126
1 32126 61604
1 67606 99988
0 47809 26704
1 47809 26704
0 40804 12239
0 97482 29222
1 97482 29222
0 28784 43750
0 23655 68781
1 68781 23655
0 4438 70084
0 69303 24513
0 96518 95603
0 11962 30404
0 23712 37514
0 68503 31357
0 4...

output:

98916
98939
98622
93878
98699
95932
98920
97666
98466
99321
99478
97128
99038
98391
95974
98479
95747
97169
97440
99220
97995
99964
98158
96342
98438
99978
98513
96846
96460
98314
96773
98128
98908
97241
97666
93871
98542
95829
99459
99523
94089
98458
99896
99901
99047
98700
97850
95091
98669
98580
...

result:

ok 100000 lines

Test #51:

score: 35
Accepted
time: 235ms
memory: 9448kb

input:

100000 100000 100000
0 48577 82452
0 36959 38553
0 76997 64205
0 34965 79134
0 48577 20538
1 82452 48577
1 34965 79134
0 69798 30848
0 21356 94552
1 21356 94552
1 48577 20538
1 30848 69798
0 47990 30848
0 56063 34298
1 64205 76997
0 24863 79270
1 36959 38553
1 34298 56063
1 24863 79270
0 75416 89581...

output:

99821
99906
99807
99866
99885
99867
99862
99852
99912
99974
99939
99879
99984
99884
99924
99909
99919
99951
99875
99879
99852
99817
99925
99846
99979
99918
99835
99910
99865
99875
99922
99967
99755
99988
99913
99997
99986
99880
99843
99982
99855
99902
99834
99983
99825
99928
99781
99810
99924
99903
...

result:

ok 100000 lines

Test #52:

score: 35
Accepted
time: 652ms
memory: 11960kb

input:

100000 100000 100000
0 70595 2653
0 98392 77008
0 74584 76288
0 48291 86890
1 74584 76288
0 6282 42546
1 2653 70595
0 57712 36931
0 4871 82967
0 86040 10364
1 10364 86040
1 98392 77008
0 29663 65913
0 18370 97975
0 54354 56918
0 9926 67870
1 18370 97975
0 52366 39162
1 6282 42546
1 82967 4871
1 5771...

output:

91840
95152
97192
93783
97032
92661
94465
84819
95333
99702
97710
95516
92198
92667
99325
96604
81878
92897
91399
89889
94512
99728
92964
92853
97237
92065
95763
97238
91748
94330
93710
97909
87472
98672
97798
91136
99475
94357
90201
88977
88285
91510
96396
91728
97024
92670
99937
99818
92300
98061
...

result:

ok 100000 lines

Test #53:

score: 35
Accepted
time: 525ms
memory: 11696kb

input:

100000 100000 100000
0 45121 23384
0 91777 23384
0 91544 23384
1 45121 23384
0 11471 77603
0 23384 8300
0 11213 23384
0 91684 23384
0 54331 23384
1 91777 23384
1 54331 23384
0 23384 29612
1 23384 8300
1 91544 23384
0 60454 23384
0 51445 23384
1 11471 77603
0 23384 891
1 11213 23384
1 29612 23384
0 4...

output:

98542
89171
91758
96782
91425
94775
85753
90721
82358
95469
86335
95808
98890
90326
96292
91801
88345
96292
96675
99914
93738
92504
96918
96830
85662
91161
86491
92599
90571
90930
91587
89976
97769
90921
99715
97413
95159
90273
93413
95158
82816
99603
99308
86708
98069
98344
87973
93779
87466
94671
...

result:

ok 100000 lines

Test #54:

score: 35
Accepted
time: 1093ms
memory: 14212kb

input:

100000 100000 100000
0 67407 75689
0 52972 30127
0 32736 7403
0 74252 24827
1 7403 32736
1 67407 75689
0 19201 59856
1 19201 59856
1 74252 24827
0 84667 92031
1 92031 84667
1 52972 30127
0 39357 24976
0 72106 71313
0 79826 48624
0 13505 45566
1 39357 24976
0 58040 16537
0 32838 59004
0 87774 3740
1 ...

output:

85362
74926
65835
92312
81059
92759
84045
79815
97619
66635
86767
82176
95768
85472
76407
80706
81765
86876
68848
84219
99577
86006
93473
93807
84418
96727
80796
90775
82730
92566
83274
90684
82019
94982
97868
85218
87711
96266
81003
90017
67798
63642
85701
88220
73964
89853
81758
89458
76751
92135
...

result:

ok 100000 lines

Test #55:

score: 35
Accepted
time: 854ms
memory: 13952kb

input:

100000 100000 100000
0 68501 60956
0 80357 34101
0 30965 84251
1 68501 60956
1 80357 34101
0 57179 84251
0 34101 47264
1 84251 57179
0 44680 34101
1 34101 47264
0 9585 68321
1 44680 34101
0 84251 99956
1 84251 30965
0 84251 28796
0 56169 34101
0 92427 71867
0 84251 99765
0 34101 10132
0 84251 26288
...

output:

78285
82157
95119
92439
95472
73763
81762
75954
79385
88064
95001
93910
93954
86818
92646
91591
85066
82741
89078
80143
98138
82931
81114
85737
91578
97163
69940
84970
90012
83419
73071
91770
84919
85707
90515
69924
83205
86212
85451
90461
90737
88463
90860
85354
85997
94749
92940
91812
98666
92042
...

result:

ok 100000 lines

Test #56:

score: 35
Accepted
time: 1220ms
memory: 15256kb

input:

100000 100000 100000
0 49229 82731
0 88325 73140
0 44164 99516
1 99516 44164
0 23679 59021
0 44164 97537
0 66063 44164
1 59021 23679
0 41269 19604
0 88325 99835
0 97515 48573
0 14789 44164
0 26861 68325
0 66730 41269
0 88325 32874
0 88325 89770
0 51001 44164
1 89770 88325
0 74915 14676
1 68325 26861...

output:

84475
83347
89678
70761
83288
98050
98375
79450
65018
94231
90834
68075
78389
91683
81759
82357
90082
92333
89028
79836
66141
91967
82374
78151
77789
97642
80281
92908
82892
96984
75015
98927
82663
80871
74390
76677
70609
70560
82395
79701
64517
88595
76620
59910
53505
95496
60725
89376
80917
65594
...

result:

ok 100000 lines

Test #57:

score: 35
Accepted
time: 1598ms
memory: 17256kb

input:

100000 100000 100000
0 43873 45498
1 45498 43873
0 56432 3040
0 27996 19078
0 35938 4744
0 44685 85400
1 44685 85400
0 75852 14782
0 43873 93789
0 22457 40394
0 43873 82399
0 68597 4744
0 40155 50068
1 4744 35938
0 43873 35723
0 72541 50068
0 2270 3040
0 67353 40394
1 40394 67353
0 61218 88184
0 403...

output:

59626
62531
80094
79330
71319
76735
88586
69670
60356
90160
85835
91235
95446
98101
68177
66364
69816
69111
64666
86068
87613
65713
94204
84691
83059
75337
95166
58552
96913
67742
73246
74005
63421
84578
82103
64880
83004
69913
78637
94849
91639
81069
76240
61115
93793
74174
69113
88126
45484
51041
...

result:

ok 100000 lines

Test #58:

score: 35
Accepted
time: 2120ms
memory: 17772kb

input:

100000 100000 100000
0 60575 71283
0 22952 3706
0 76130 8295
0 11028 29856
1 22952 3706
0 57365 75649
0 92752 78916
0 48025 3664
0 26116 233
0 60180 95824
0 62191 65776
0 29094 1340
1 11028 29856
0 48532 2468
0 44008 83108
0 13240 75004
0 12124 47895
0 53014 14759
0 29509 68006
1 3664 48025
0 61162 ...

output:

68640
50785
96565
94444
78222
69568
61922
95833
54111
73996
60990
83613
59319
37725
91092
67559
98406
69512
76168
63390
76093
48630
66889
65694
28732
60549
98870
78551
48049
71750
71710
54310
58803
59987
85461
49485
87280
57268
68791
78993
73512
46738
58536
61527
44857
73862
94718
81251
92554
76015
...

result:

ok 100000 lines

Test #59:

score: 35
Accepted
time: 1798ms
memory: 19584kb

input:

100000 100000 100000
0 94943 25656
0 93478 71731
0 71688 94943
0 97305 21103
0 65841 52827
0 68842 88032
0 21103 82442
0 31754 52827
0 21103 72666
0 25090 56994
0 16861 1295
0 49602 21103
0 97053 54536
0 26169 11005
0 69467 21103
0 84791 94943
0 52827 15959
0 72250 7124
0 43532 94034
0 94943 40943
0...

output:

79354
74942
63751
48733
50956
59979
58347
69350
65294
65128
55536
83245
94474
58410
46783
71052
29548
57857
63672
84494
65869
75965
79385
56863
91703
86627
68965
79788
83519
86824
77455
36661
67293
69704
57570
82251
71480
87817
71877
70702
97146
58756
92592
43291
48199
54382
77331
54881
91208
85135
...

result:

ok 100000 lines

Test #60:

score: 35
Accepted
time: 2628ms
memory: 19868kb

input:

100000 100000 100000
0 31690 72761
0 28153 44361
0 24932 22701
0 1282 12242
0 29912 93079
0 96914 66885
0 3495 88317
0 95316 23459
0 56191 79512
0 79234 8065
0 94783 66420
0 67200 59945
0 85676 30990
0 13884 1962
0 12191 55764
0 68478 14894
0 75351 77429
0 24408 91321
0 90951 33412
0 57115 90497
0 3...

output:

66552
84533
91494
87727
63243
65839
90620
59673
74045
93288
97217
65076
75924
60013
49263
62100
82024
77099
87062
65902
61848
91634
92083
73081
18576
63282
58131
49819
81465
87281
62321
26525
94097
79718
69388
38119
69204
87524
78280
92042
67981
63044
66891
67664
61004
53905
63850
67352
85453
95026
...

result:

ok 100000 lines

Extra Test:

score: 0
Extra Test Passed