QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#355515#2296. Exchange Studentsckiseki#AC ✓202ms49012kbC++204.3kb2024-03-16 19:04:122024-03-16 19:04:13

Judging History

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

  • [2024-03-16 19:04:13]
  • 评测
  • 测评结果:AC
  • 用时:202ms
  • 内存:49012kb
  • [2024-03-16 19:04:12]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define all(x) begin(x), end(x)
#ifdef CKISEKI
#define safe cerr << __PRETTY_FUNCTION__ << " line " << __LINE__ << " safe\n"
#define debug(a...) debug_(#a, a)
#define orange(a...) orange_(#a, a)
void debug_(auto s, auto ...a) {
  cerr << "\e[1;32m(" << s << ") = (";
  int f = 0;
  (..., (cerr << (f++ ? ", " : "") << a));
  cerr << ")\e[0m\n";
}
#include <experimental/iterator>
void orange_(auto s, auto L, auto R) {
  cerr << "\e[1;33m[ " << s << " ] = [ ";
  using namespace experimental;
  copy(L, R, make_ostream_joiner(cerr, ", "));
  cerr << " ]\e[0m\n";
}
#else
#define safe ((void)0)
#define debug(...) safe
#define orange(...) safe
#endif

struct Fenwick {
  vector<int> b;
  Fenwick(int n) : b(n + 1) {}
  void add(int p, int v) {
    for (++p; p < (int)b.size(); p += p & -p)
      b[p] += v;
  }
  int query(int p) {
    int r = 0;
    for (++p; p > 0; p -= p & -p)
      r += b[p];
    return r;
  }
};

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  int n;
  cin >> n;

  vector<tuple<int,int>> A, B;
  vector<int> orig_g(n);

  for (int i = 0; i < n; i++) {
    int g;
    cin >> g;
    orig_g[i] = g;
    A.emplace_back(g, i);
  }
  for (int i = 0; i < n; i++) {
    int h;
    cin >> h;
    B.emplace_back(h, i);
  }

  sort(all(A));
  sort(all(B));

  vector<int> pos(n);
  iota(all(pos), 0);
  vector<int> seq(n);
  iota(all(seq), 0);

  vector<int> the_goal(n);

  vector<vector<pair<int,int>>> e;
  for (int i = 0, j; i < n; i = j) {
    e.emplace_back();
    for (j = i; j < n; j++) {
      if (get<0>(A[i]) != get<0>(A[j])) break;
      int cur = get<1>(A[j]);
      int goal = get<1>(B[j]);
      the_goal[cur] = goal;
      e.back().emplace_back(cur, goal);
    }
  }

  const int C = 200000;

  vector<pair<int,int>> sol;

  set<int> st;
  for (int i = 0; i < n; i++)
    st.insert(i);

  auto get_next = [&](int x) {
    return *st.upper_bound(x);
  };
  auto get_prev = [&](int x) {
    return *prev(st.lower_bound(x));
  };


  long long ans = 0;

  Fenwick af(n), bf(n);
  for (const auto &es : e) {
    for (auto [orig_pos, goal] : es) {
      int ap = orig_pos - af.query(orig_pos);
      int bp = goal - bf.query(goal);
      ans += abs(ap - bp);
    }
    for (auto [orig_pos, goal] : es) {
      af.add(orig_pos, 1);
      bf.add(goal, 1);
    }
  }

  for (const auto &es : e) {
    vector<pair<int,int>> tmp;
    for (auto [orig_pos, goal] : es) {
      debug(orig_pos, pos[orig_pos]);
      tmp.emplace_back(pos[orig_pos], -1);
      tmp.emplace_back(goal, 1);
    }
    sort(all(tmp));

    safe;
    debug(es.size());

    int tot = 0;
    vector<int> stk;
    for (auto [_, c] : tmp) {
      tot += c;
      if (c < 0)
        stk.emplace_back(_);

      if (tot == 0) {
        if (c > 0) {
          for (int p : stk | views::reverse) {
            int orig_pos = seq[p];
            debug(orig_pos);
            assert(p <= the_goal[orig_pos]);
            while (p < the_goal[orig_pos]) {
              int q = get_next(p);
              sol.emplace_back(p, q);
              swap(seq[p], seq[q]);
              pos[seq[p]] = p;
              pos[seq[q]] = q;

              swap(orig_g[p], orig_g[q]);
              orange(all(orig_g));
              orange(all(seq));
              debug(p, q, "up");
              p = q;
              if (sol.size() == C)
                goto end;
            }
          }
          stk.clear();
        } else {
          for (int p : stk) {
            int orig_pos = seq[p];
            debug(orig_pos);
            assert(p >= the_goal[orig_pos]);

            debug(the_goal[orig_pos], orig_pos);

            while (p > the_goal[orig_pos]) {
              int q = get_prev(p);
              sol.emplace_back(p, q);
              swap(seq[p], seq[q]);
              pos[seq[p]] = p;
              pos[seq[q]] = q;

              swap(orig_g[p], orig_g[q]);
              orange(all(orig_g));
              orange(all(seq));
              debug(p, q, "down");
              p = q;
              if (sol.size() == C)
                goto end;
            }
          }
          stk.clear();
        }
      }
    }

    for (auto [orig_pos, goal] : es) {
      assert(pos[orig_pos] == goal);
      st.erase(pos[orig_pos]);
    }

    orange(all(st));

  }

end:
  cout << ans << '\n';
  for (auto [x, y] : sol)
    cout << x + 1 << ' ' << y + 1 << '\n';

  return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3552kb

input:

1
279122803
279122803

output:

0

result:

ok good

Test #2:

score: 0
Accepted
time: 0ms
memory: 3604kb

input:

2
212545283 896408766
212545283 896408766

output:

0

result:

ok good

Test #3:

score: 0
Accepted
time: 1ms
memory: 3856kb

input:

4
3 1 2 4
4 2 1 3

output:

2
2 3
1 4

result:

ok good

Test #4:

score: 0
Accepted
time: 1ms
memory: 3620kb

input:

6
5 1 2 3 4 6
6 4 3 2 1 5

output:

7
2 3
3 4
4 5
2 3
3 4
2 3
1 6

result:

ok good

Test #5:

score: 0
Accepted
time: 0ms
memory: 3784kb

input:

2
2 1
1 2

output:

1
2 1

result:

ok good

Test #6:

score: 0
Accepted
time: 0ms
memory: 3608kb

input:

4
3 2 2 1
2 1 2 3

output:

4
4 3
3 2
3 1
4 3

result:

ok good

Test #7:

score: 0
Accepted
time: 0ms
memory: 3840kb

input:

9
708443928 333343028 130113530 997808421 299459189 845949632 647591888 681805948 468112900
299459189 997808421 130113530 845949632 647591888 681805948 468112900 708443928 333343028

output:

13
5 4
4 2
2 1
4 5
5 6
6 7
7 8
8 9
8 7
6 5
8 6
2 4
4 8

result:

ok good

Test #8:

score: 0
Accepted
time: 0ms
memory: 3560kb

input:

3
732684994 647116406 457545388
732684994 647116406 457545388

output:

0

result:

ok good

Test #9:

score: 0
Accepted
time: 0ms
memory: 3796kb

input:

4
105385396 776935185 411665343 757889658
776935185 411665343 757889658 105385396

output:

3
1 2
2 3
3 4

result:

ok good

Test #10:

score: 0
Accepted
time: 0ms
memory: 3648kb

input:

4
1 2 2 1
2 2 1 1

output:

2
1 2
2 3

result:

ok good

Test #11:

score: 0
Accepted
time: 0ms
memory: 3856kb

input:

10
1 2 1 2 1 1 2 2 2 1
1 2 2 2 2 1 1 2 1 1

output:

8
6 7
7 8
8 9
5 6
6 7
3 4
4 5
5 6

result:

ok good

Test #12:

score: 0
Accepted
time: 0ms
memory: 3616kb

input:

5
1 1 2 2 2
2 1 1 2 2

output:

2
2 3
1 2

result:

ok good

Test #13:

score: 0
Accepted
time: 0ms
memory: 3588kb

input:

10
1 2 1 3 2 2 3 3 1 2
1 2 2 2 2 3 3 1 3 1

output:

11
3 4
4 5
5 6
6 7
7 8
9 10
4 3
5 4
9 7
7 6
6 5

result:

ok good

Test #14:

score: 0
Accepted
time: 0ms
memory: 3652kb

input:

6
4 2 1 4 1 4
4 1 2 1 4 4

output:

2
3 2
5 4

result:

ok good

Test #15:

score: 0
Accepted
time: 1ms
memory: 3548kb

input:

6
4 5 4 6 5 2
5 4 2 4 5 6

output:

5
6 5
5 4
4 3
1 2
6 5

result:

ok good

Test #16:

score: 0
Accepted
time: 1ms
memory: 3568kb

input:

6
4 3 8 5 1 2
5 8 2 4 1 3

output:

7
6 4
4 3
2 4
4 6
1 2
2 4
2 1

result:

ok good

Test #17:

score: 0
Accepted
time: 1ms
memory: 3640kb

input:

112
633894500 167641802 339937464 844945998 269698167 432803430 591795000 657246871 31461268 443731992 6055837 817590568 986936937 160504265 528606045 304078549 879939770 433943593 793192949 260825675 586504056 752833202 507520443 563583937 733291184 91069383 362243954 908994979 651876073 944319771 ...

output:

2255
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
100 99
99 98
98 97
97 96
96 95
95 94
94 93
93 92
92 91
91 90
90 89
89 88
88 87
87 86
86 85
85 84
84 83
83 82
82 81
81 80
80 79
79 78
78 77
77 76
76 75
75 74
...

result:

ok good

Test #18:

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

input:

475
513851595 939887761 535431296 196631717 780659274 904345731 960702202 930549847 783401281 700008841 764948141 408683368 580730549 656069530 812938319 239750378 509869370 458659369 111931962 953621825 247129346 579636113 197526284 860965062 770656291 712648065 719627561 994512440 776717865 721575...

output:

38843
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50 51
51 52
52 53
53 54
54 55
55 56
56 57
57 58
58 59
59 60
60 61
61 62
62 63
63 64
64 65
65 66
66 67
67 68
68 69
69 70
70 71
71 72
72 73
73 74
74 75
75 76
76 77
77 78
78 79
79 80
80 81
81 82
82 83
83 84
84 85
85 86
86 87
87 88
88 89
89 90
...

result:

ok good

Test #19:

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

input:

511
692538384 450798311 689060453 338600390 623425233 806325979 214986187 65806871 160563193 565038083 651234761 686197630 390054944 16695632 976193125 348998588 109084352 295378672 886085460 966887442 454774074 452488333 950625229 873137681 490203016 343841646 453468043 199579268 254523368 59890754...

output:

41191
182 183
183 184
184 185
185 186
186 187
187 188
188 189
189 190
190 191
191 192
192 193
193 194
194 195
195 196
196 197
197 198
198 199
199 200
200 201
201 202
202 203
203 204
204 205
205 206
206 207
207 208
208 209
209 210
210 211
211 212
212 213
213 214
214 215
215 216
216 217
217 218
218 21...

result:

ok good

Test #20:

score: 0
Accepted
time: 28ms
memory: 6100kb

input:

6529
742820256 407098265 340024622 783273460 90005697 317112311 638332065 979785745 10427038 998056248 711257071 670551250 993934171 563965867 740492636 477441398 446620497 782019827 436884507 80766292 73444545 628480256 914515547 747218815 252222910 629497196 601718131 468014294 722599489 976762176...

output:

7165684
178 179
179 180
180 181
181 182
182 183
183 184
184 185
185 186
186 187
187 188
188 189
189 190
190 191
191 192
192 193
193 194
194 195
195 196
196 197
197 198
198 199
199 200
200 201
201 202
202 203
203 204
204 205
205 206
206 207
207 208
208 209
209 210
210 211
211 212
212 213
213 214
214 ...

result:

ok good

Test #21:

score: 0
Accepted
time: 55ms
memory: 13232kb

input:

49656
219729028 922565163 973184177 401278488 398509977 430136880 355221823 531198609 427159272 620342214 807056246 946023229 863329676 594785601 919885246 514268227 322020072 283161368 230524610 216372594 971966245 750604631 235100536 294361839 700788364 78618139 559468465 858060770 714675158 94275...

output:

410203271
47389 47388
47388 47387
47387 47386
47386 47385
47385 47384
47384 47383
47383 47382
47382 47381
47381 47380
47380 47379
47379 47378
47378 47377
47377 47376
47376 47375
47375 47374
47374 47373
47373 47372
47372 47371
47371 47370
47370 47369
47369 47368
47368 47367
47367 47366
47366 47365
47...

result:

ok good

Test #22:

score: 0
Accepted
time: 103ms
memory: 27180kb

input:

143669
948851763 284443096 962878315 551277661 202354141 381651768 403739560 826584405 363147562 724688034 670173153 506757091 350542543 655812219 60748415 522515497 41316518 689650777 261560751 125071377 69204090 943711167 165930454 226368865 920920481 458809698 371422646 842157114 24781050 7796296...

output:

3440983752
109079 109078
109078 109077
109077 109076
109076 109075
109075 109074
109074 109073
109073 109072
109072 109071
109071 109070
109070 109069
109069 109068
109068 109067
109067 109066
109066 109065
109065 109064
109064 109063
109063 109062
109062 109061
109061 109060
109060 109059
109059 10...

result:

ok good

Test #23:

score: 0
Accepted
time: 202ms
memory: 48836kb

input:

300000
331520194 609970309 604859193 816982812 725275830 848832553 819288112 916926379 193011613 436808431 53021469 38879580 455498144 387664917 824677349 258913448 967649601 259681227 672184202 936087138 579468080 716313897 121681024 568713806 32234516 783526144 244218286 423421704 256589283 747706...

output:

15016413052
206667 206666
206666 206665
206665 206664
206664 206663
206663 206662
206662 206661
206661 206660
206660 206659
206659 206658
206658 206657
206657 206656
206656 206655
206655 206654
206654 206653
206653 206652
206652 206651
206651 206650
206650 206649
206649 206648
206648 206647
206647 2...

result:

ok good

Test #24:

score: 0
Accepted
time: 194ms
memory: 49012kb

input:

300000
416161145 142034803 687753433 586352821 818995942 920991843 909428809 134612316 468444784 932090888 907047166 658380288 342653817 153914548 682888570 433423150 709429365 500294745 496103894 471710770 194392504 370866028 138123366 751752703 411914434 322763592 603804776 126892125 514141682 314...

output:

14986242618
51484 51485
51485 51486
51486 51487
51487 51488
51488 51489
51489 51490
51490 51491
51491 51492
51492 51493
51493 51494
51494 51495
51495 51496
51496 51497
51497 51498
51498 51499
51499 51500
51500 51501
51501 51502
51502 51503
51503 51504
51504 51505
51505 51506
51506 51507
51507 51508
...

result:

ok good

Test #25:

score: 0
Accepted
time: 197ms
memory: 48944kb

input:

300000
63625989 165478863 263256412 91849262 716080542 237746804 700124328 748582752 398038374 654941747 955098470 199364646 300934431 149830580 970278026 465946242 69915827 304885370 96648834 808029699 733367012 541983596 633866224 993204257 599104305 776829056 49291455 688945398 434972599 79929872...

output:

15009354497
134185 134184
134184 134183
134183 134182
134182 134181
134181 134180
134180 134179
134179 134178
134178 134177
134177 134176
134176 134175
134175 134174
134174 134173
134173 134172
134172 134171
134171 134170
134170 134169
134169 134168
134168 134167
134167 134166
134166 134165
134165 1...

result:

ok good

Test #26:

score: 0
Accepted
time: 147ms
memory: 37460kb

input:

300000
2 2 1 2 1 1 2 1 1 1 1 2 2 2 1 1 2 1 2 2 1 1 1 2 2 2 2 1 1 2 2 2 1 2 2 1 1 1 2 1 2 1 2 1 2 2 1 1 2 2 2 2 1 2 2 1 1 2 2 1 1 2 2 2 1 2 1 2 1 1 2 2 1 2 2 2 2 1 2 1 2 1 1 2 2 1 1 1 1 1 2 2 1 2 1 2 1 2 2 1 1 2 1 2 1 2 2 2 2 1 1 1 2 1 1 1 1 2 1 2 2 1 2 1 2 1 2 1 1 1 2 1 1 2 1 1 2 2 2 1 1 1 1 2 2 2 2...

output:

25886863
3 2
5 4
4 3
6 5
23 24
24 25
25 26
22 23
23 24
21 22
22 23
18 19
19 20
20 21
21 22
16 17
17 18
18 19
19 20
20 21
15 16
16 17
17 18
18 19
11 12
12 13
13 14
14 15
15 16
10 11
11 12
12 13
13 14
14 15
9 10
10 11
11 12
12 13
8 9
9 10
10 11
29 30
30 31
28 29
33 32
36 35
35 34
34 33
37 36
36 35
35 ...

result:

ok good

Test #27:

score: 0
Accepted
time: 129ms
memory: 39604kb

input:

300000
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000...

output:

0

result:

ok good

Test #28:

score: 0
Accepted
time: 97ms
memory: 24036kb

input:

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

output:

44397301
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
88 87
87 86
86 85
85 84
84 83
83 82
82 81
81 80
80 79
79 78
78 77
77 76
76 75
75 74
74 73
73 72
72 71
71 70
70 69
69 68
68 67
67 66
66 65
65 64
64 63
63 62
62 61
61 60
60 ...

result:

ok good

Test #29:

score: 0
Accepted
time: 141ms
memory: 28576kb

input:

231566
67 96 2 6 60 98 30 2 77 62 89 28 4 53 1 85 57 41 95 74 72 77 69 79 13 4 58 100 54 1 50 1 73 25 47 8 91 51 7 25 40 61 44 39 10 28 93 46 35 33 39 52 69 87 2 32 71 97 11 65 41 58 11 93 3 71 99 72 65 98 95 23 13 10 45 86 61 2 98 48 37 82 67 8 82 50 85 56 69 2 43 95 20 12 19 75 38 48 39 97 97 16 7...

output:

235926480
1926 1927
1927 1928
1928 1929
1929 1930
1930 1931
1931 1932
1932 1933
1933 1934
1934 1935
1935 1936
1936 1937
1937 1938
1938 1939
1939 1940
1940 1941
1941 1942
1942 1943
1943 1944
1944 1945
1945 1946
1946 1947
1947 1948
1948 1949
1949 1950
1950 1951
1951 1952
1952 1953
1953 1954
1954 1955
...

result:

ok good

Test #30:

score: 0
Accepted
time: 33ms
memory: 9148kb

input:

39371
903 946 850 148 541 566 318 133 897 157 297 522 96 691 112 322 687 450 544 227 585 975 85 641 757 913 547 645 297 508 307 492 885 355 675 576 117 440 272 115 768 337 587 136 475 150 590 441 910 786 326 50 503 113 63 150 107 97 783 559 534 94 916 729 404 49 797 895 204 59 133 328 952 371 492 69...

output:

54149414
1022 1021
1021 1020
1020 1019
1019 1018
1018 1017
1017 1016
1016 1015
1015 1014
1014 1013
1013 1012
1012 1011
1011 1010
1010 1009
1009 1008
1008 1007
1007 1006
1006 1005
1005 1004
1004 1003
1003 1002
1002 1001
1001 1000
1000 999
999 998
998 997
997 996
996 995
995 994
994 993
993 992
992 99...

result:

ok good

Test #31:

score: 0
Accepted
time: 142ms
memory: 29660kb

input:

235958
14 3 11 7 6 14 2 17 7 9 5 18 48 5 6 34 6 12 7 18 7 13 2 7 3 5 10 10 1 2 30 3 3 5 7 17 15 16 9 2 5 8 9 16 2 57 8 14 29 2 5 3 5 8 26 5 5 11 25 2 1 3 1 4 5 9 9 23 6 13 7 18 1 2 1 5 8 16 10 13 3 11 8 2 2 8 2 13 4 2 2 9 58 4 1 18 4 23 23 16 7 4 3 5 21 1 20 6 4 25 4 4 27 19 3 1 5 6 14 2 10 5 15 10 ...

output:

112071301
29 28
28 27
27 26
26 25
61 60
60 59
59 58
58 57
57 56
56 55
55 54
54 53
53 52
52 51
51 50
50 49
49 48
48 47
47 46
46 45
45 44
44 43
43 42
42 41
41 40
40 39
39 38
38 37
37 36
36 35
63 62
62 61
61 60
60 59
59 58
58 57
57 56
56 55
55 54
54 53
53 52
52 51
51 50
50 49
49 48
48 47
47 46
46 45
45...

result:

ok good

Test #32:

score: 0
Accepted
time: 93ms
memory: 22764kb

input:

168818
20 120 38 1 33 24 2 117 89 163 206 130 159 107 80 18 49 81 12 148 215 33 118 70 212 273 200 186 381 11 87 119 27 114 18 98 13 5 7 19 8 233 5 56 5 202 52 12 167 42 3 22 99 252 6 70 58 157 113 118 32 19 58 93 55 4 75 114 100 110 23 61 32 47 111 78 21 40 29 53 34 17 8 22 256 60 214 75 33 44 77 4...

output:

197324279
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
411 410
410 409
409 408
408 407
407 406
406 405
405 404...

result:

ok good

Test #33:

score: 0
Accepted
time: 143ms
memory: 29116kb

input:

232968
551 666 2798 73 92 153 695 365 665 1892 246 5 622 1023 306 517 659 184 22 4253 903 1677 704 489 176 825 62 690 932 595 373 1332 110 2472 5060 2962 2168 476 2151 258 650 47 1387 743 279 734 654 1034 319 605 583 743 1071 2368 2453 343 2920 903 283 2267 247 1987 2435 226 2848 1901 627 332 795 24...

output:

1039756443
1390 1389
1389 1388
1388 1387
1387 1386
1386 1385
1385 1384
1384 1383
1383 1382
1382 1381
1381 1380
1380 1379
1379 1378
1378 1377
1377 1376
1376 1375
1375 1374
1374 1373
1373 1372
1372 1371
1371 1370
1370 1369
1369 1368
1368 1367
1367 1366
1366 1365
1365 1364
1364 1363
1363 1362
1362 1361...

result:

ok good

Test #34:

score: 0
Accepted
time: 125ms
memory: 26512kb

input:

195773
5302 14362 3699 11204 9432 5223 874 3176 9560 12580 11109 5568 3112 16403 4984 9107 14921 2825 26911 1114 12676 8934 7553 5707 4624 261 7174 3969 7229 995 12560 3149 15395 361 2741 17350 13096 692 5663 4382 1787 5225 5789 38682 5639 142 2026 13175 56693 5144 8186 7674 8151 20929 3120 19942 45...

output:

2400974864
16995 16994
16994 16993
16993 16992
16992 16991
16991 16990
16990 16989
16989 16988
16988 16987
16987 16986
16986 16985
16985 16984
16984 16983
16983 16982
16982 16981
16981 16980
16980 16979
16979 16978
16978 16977
16977 16976
16976 16975
16975 16974
16974 16973
16973 16972
16972 16971
1...

result:

ok good

Test #35:

score: 0
Accepted
time: 42ms
memory: 9436kb

input:

43310
485 488 505 499 514 506 516 504 509 494 485 485 461 515 473 490 497 506 514 486 498 499 485 476 511 509 504 515 473 503 504 499 519 503 497 490 518 493 511 513 527 517 521 500 486 501 527 489 497 490 481 509 485 519 490 505 512 487 513 503 498 505 468 491 501 511 508 494 486 512 498 483 491 50...

output:

17692669
25035 25036
25036 25037
25037 25038
25038 25039
25039 25040
25040 25041
25041 25042
25042 25043
25043 25044
25044 25045
25045 25046
25046 25047
25047 25048
25048 25049
25049 25050
25050 25051
25051 25052
25052 25053
25053 25054
25054 25055
25055 25056
25056 25057
25057 25058
25058 25059
250...

result:

ok good

Test #36:

score: 0
Accepted
time: 123ms
memory: 24964kb

input:

194102
50131 49939 49866 50269 49793 49984 49901 50093 49948 49752 49932 49959 50080 50115 50096 50195 49844 49922 49846 50088 49963 49868 49949 50004 50001 49904 49998 50198 50238 50052 50106 49908 49952 49941 49984 49841 49833 49921 50056 49848 49782 50294 50024 49710 50097 50094 50147 50060 50091...

output:

535599810
84021 84022
84022 84023
84023 84024
84024 84025
84025 84026
84026 84027
84027 84028
84028 84029
84029 84030
84030 84031
84031 84032
84032 84033
84033 84034
84034 84035
84035 84036
84036 84037
84037 84038
84038 84039
84039 84040
84040 84041
84041 84042
84042 84043
84043 84044
84044 84045
84...

result:

ok good

Test #37:

score: 0
Accepted
time: 29ms
memory: 6224kb

input:

7271
4997632 4998700 5002258 4999918 4997849 4999632 5002192 5001791 4999609 4998611 5002424 5001283 5001105 5000026 4999812 4999613 5001085 5000628 4998722 4999207 5000423 4998174 4998956 4999616 5000560 5000759 4999883 5000452 5002041 5000568 5003774 4995060 4999806 5001118 5001118 5001143 4998699...

output:

7152021
6506 6505
6505 6504
6504 6503
6503 6502
6502 6501
6501 6500
6500 6499
6499 6498
6498 6497
6497 6496
6496 6495
6495 6494
6494 6493
6493 6492
6492 6491
6491 6490
6490 6489
6489 6488
6488 6487
6487 6486
6486 6485
6485 6484
6484 6483
6483 6482
6482 6481
6481 6480
6480 6479
6479 6478
6478 6477
64...

result:

ok good

Test #38:

score: 0
Accepted
time: 146ms
memory: 38120kb

input:

300000
2 2 1 1 2 1 1 2 2 2 1 2 1 2 1 1 1 1 1 1 2 1 1 2 1 1 2 1 1 2 2 2 2 1 2 1 2 2 2 2 2 1 2 1 1 2 2 2 1 2 2 2 2 2 1 1 2 2 1 1 1 2 2 2 1 1 2 1 2 1 1 1 2 2 1 1 1 1 2 1 2 1 2 2 2 2 2 2 1 2 2 1 1 2 1 2 1 1 1 1 2 1 2 1 2 2 2 1 2 2 1 2 2 1 2 1 1 1 2 1 1 2 2 2 2 2 1 1 2 2 1 1 1 1 2 2 2 1 2 1 2 1 2 1 2 1 1...

output:

57845874
3 2
6 5
7 6
11 10
10 9
9 8
8 7
13 12
12 11
11 10
10 9
15 14
14 13
13 12
12 11
16 15
15 14
14 13
17 16
16 15
18 17
22 21
23 22
25 24
24 23
26 25
25 24
28 27
27 26
26 25
29 28
28 27
27 26
34 33
33 32
32 31
31 30
30 29
29 28
36 35
35 34
34 33
33 32
32 31
31 30
42 41
41 40
40 39
39 38
38 37
37 ...

result:

ok good

Test #39:

score: 0
Accepted
time: 0ms
memory: 3564kb

input:

100
4 87 26 88 67 39 23 63 85 31 14 89 100 6 66 47 9 15 83 65 94 24 97 30 90 78 75 49 55 55 88 17 55 74 80 94 96 22 20 46 89 36 63 71 99 26 37 85 20 65 74 88 18 34 36 39 97 90 12 99 77 2 85 50 65 55 14 76 33 97 31 18 52 59 38 39 10 100 3 9 12 65 84 28 41 8 38 16 4 71 66 58 70 70 83 98 77 48 1 1
4 87...

output:

0

result:

ok good

Test #40:

score: 0
Accepted
time: 198ms
memory: 36996kb

input:

300000
3510 109 8532 4953 4212 4287 288 6752 2547 2477 10403 23835 24740 6351 11012 17052 3052 28948 5420 28157 26745 4075 27407 6857 12543 17382 10752 17794 9895 27509 23933 29329 12170 13620 8967 9018 18540 317 6179 207 8022 8239 13903 11277 13499 28190 24090 13577 2795 21398 9884 27429 20882 1976...

output:

7358593880
69374 69373
69373 69372
69372 69371
69371 69370
69370 69369
69369 69368
69368 69367
69367 69366
69366 69365
69365 69364
69364 69363
69363 69362
69362 69361
69361 69360
69360 69359
69359 69358
69358 69357
69357 69356
69356 69355
69355 69354
69354 69353
69353 69352
69352 69351
69351 69350
6...

result:

ok good

Test #41:

score: 0
Accepted
time: 132ms
memory: 36892kb

input:

300000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 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 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 7 7 8 8 8 8 8 8 8 8 8 9 9 9 9 9 9 9 9 9 10 10 10 10 10 10 10 10 10 11 11 11 11 11 11 11 11 11 12 12 12 12 12 13 13 13 13 13 13 13 13 14 14 14 14 14 14 15 15 15...

output:

44998350640
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50 51
51 52
52 53
53 54
54 55
55 56
56 57
57 58
58 59
59 60
60 61
61 62
...

result:

ok good

Test #42:

score: 0
Accepted
time: 155ms
memory: 36960kb

input:

300000
30000 30000 30000 30000 30000 30000 30000 30000 30000 30000 30000 29999 29999 29999 29999 29999 29999 29999 29999 29999 29998 29998 29998 29998 29998 29998 29998 29997 29997 29997 29997 29997 29997 29997 29996 29996 29996 29996 29996 29996 29996 29996 29996 29996 29996 29996 29996 29996 29996...

output:

44998347970
299986 299985
299985 299984
299984 299983
299983 299982
299982 299981
299981 299980
299980 299979
299979 299978
299978 299977
299977 299976
299976 299975
299975 299974
299974 299973
299973 299972
299972 299971
299971 299970
299970 299969
299969 299968
299968 299967
299967 299966
299966 2...

result:

ok good

Test #43:

score: 0
Accepted
time: 153ms
memory: 36936kb

input:

300000
19672 8950 23909 24951 28567 27869 26008 28228 26386 14895 16933 9274 126 9775 26676 351 24407 21498 7594 5537 1233 20507 14785 22396 14060 6360 1560 12033 23426 18978 28983 14093 12532 6607 11002 4584 16311 28864 28349 3566 10622 27973 14784 13581 25877 19888 27730 25763 2402 29804 16834 272...

output:

22488871204
45504 45503
45503 45502
45502 45501
45501 45500
45500 45499
45499 45498
45498 45497
45497 45496
45496 45495
45495 45494
45494 45493
45493 45492
45492 45491
45491 45490
45490 45489
45489 45488
45488 45487
45487 45486
45486 45485
45485 45484
45484 45483
45483 45482
45482 45481
45481 45480
...

result:

ok good

Test #44:

score: 0
Accepted
time: 188ms
memory: 36956kb

input:

300000
23753 3887 28899 6050 25836 19213 12501 6087 6494 6511 5634 4213 8368 26766 10517 886 29785 21144 13177 7246 28535 8442 10770 20409 23538 8496 6671 13794 22582 26076 4761 21624 1974 1416 17685 10559 27335 26950 7893 7066 17000 7898 14529 6739 10443 417 24046 8210 29437 4556 28410 18871 98 265...

output:

22455006608
266099 266100
266100 266101
266101 266102
266102 266103
266103 266104
266104 266105
266105 266106
266106 266107
266107 266108
266108 266109
266109 266110
266110 266111
266111 266112
266112 266113
266113 266114
266114 266115
266115 266116
266116 266117
266117 266118
266118 266119
266119 2...

result:

ok good

Test #45:

score: 0
Accepted
time: 159ms
memory: 36996kb

input:

300000
1 1 1 1 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 7 7 7 7 7 7 8 8 8 8 8 8 8 8 8 8 8 8 8 9 9 9 9 9 9 9 9 9 9 9 9 9 10 10 10 10 10 10 10 10 10 10 10 10 10 10 11 11 11 11 11 11 11 11 11 11 12 12 12 12 12 12 12 12 12 12 12 13 13 13 13 13 13 ...

output:

22487598571
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50 51
51 52
52 53
53 54
54 55
55 56
56 57
5...

result:

ok good

Test #46:

score: 0
Accepted
time: 169ms
memory: 36992kb

input:

300000
30000 30000 30000 30000 30000 30000 30000 30000 30000 29999 29999 29999 29999 29999 29999 29999 29999 29999 29999 29998 29998 29998 29998 29998 29998 29998 29998 29998 29998 29998 29998 29998 29998 29997 29997 29997 29997 29997 29997 29997 29997 29997 29996 29996 29996 29996 29996 29996 29996...

output:

22518298944
299991 299990
299990 299989
299989 299988
299988 299987
299987 299986
299986 299985
299985 299984
299984 299983
299983 299982
299982 299981
299981 299980
299980 299979
299979 299978
299978 299977
299977 299976
299976 299975
299975 299974
299974 299973
299973 299972
299972 299971
299971 2...

result:

ok good

Test #47:

score: 0
Accepted
time: 0ms
memory: 3548kb

input:

3
1 1 2
2 1 1

output:

2
2 3
1 2

result:

ok good

Test #48:

score: 0
Accepted
time: 1ms
memory: 3608kb

input:

3
2 1 1
1 1 2

output:

2
2 1
3 2

result:

ok good

Test #49:

score: 0
Accepted
time: 1ms
memory: 3552kb

input:

3
2 2 1
1 2 2

output:

2
3 2
2 1

result:

ok good

Test #50:

score: 0
Accepted
time: 0ms
memory: 3608kb

input:

3
1 2 2
2 2 1

output:

2
1 2
2 3

result:

ok good