QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#166115#7182. Very Sparse Tableucup-team987#AC ✓1325ms28252kbC++234.7kb2023-09-06 01:08:192023-09-06 01:08:19

Judging History

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

  • [2023-09-06 01:08:19]
  • 评测
  • 测评结果:AC
  • 用时:1325ms
  • 内存:28252kb
  • [2023-09-06 01:08:19]
  • 提交

answer

#if __INCLUDE_LEVEL__ == 0

#include <bits/stdc++.h>

using namespace std;

#include __BASE_FILE__

namespace {

void solve() {
  int n;
  cin >> n;
  vector<tuple<int, int, int>> ans;
  set<pair<int, int>> se;
  for (int i : rep(n)) {
    se.emplace(i, i + 1);
  }
  auto add = [&](int a, int b, int c) {
    if (n < c) {
      return;
    }
    if (se.contains({a, c})) {
      return;
    }
    assert(se.contains({a, b}));
    assert(se.contains({b, c}));
    ans.emplace_back(a, b, c);
    se.emplace(a, c);
  };
  for (int o = 0; o < 1 << 16; o += 16) {
    for (int p = o + 4; p < o + 16; p += 4) {
      for (int w : rep1(2, 4)) {
        add(p - w, p - w + 1, p);
        add(p, p + w - 1, p + w);
      }
    }
    add(o + 4, o + 8, o + 12);
  }
  for (int o = 0; o < 1 << 16; o += 256) {
    for (int p = o + 16; p < o + 256; p += 16) {
      for (int w : rep1(2, 16)) {
        add(p - w, p - w + 1, p);
        add(p, p + w - 1, p + w);
      }
    }
    for (int r = 48; r < 256; r += 16) {
      for (int l = r - 32; 16 <= l; l -= 16) {
        add(o + l, o + r - 16, o + r);
      }
    }
  }
  for (int p = 256; p < 1 << 16; p += 256) {
    for (int w : rep1(2, 256)) {
      add(p - w, p - w + 1, p);
      add(p, p + w - 1, p + w);
    }
  }
  for (int r = 256 * 3; r < 1 << 16; r += 256) {
    for (int l = r - 256 * 2; 256 <= l; l -= 256) {
      add(l, r - 256, r);
    }
  }
  print(ssize(ans));
  for (auto [a, b, c] : ans) {
    print(a, b, c);
  }
  int q;
  cin >> q;
  while (q--) {
    int l, r;
    cin >> tie(l, r);
    auto path = [&]() -> vector<int> {
      if (se.contains({l, r})) {
        return {l, r};
      }
      int l256 = (l / 256 + 1) * 256;
      int r256 = (r - 1) / 256 * 256;
      if (l256 <= r256) {
        return {l, l256, r256, r};
      }
      int l16 = (l / 16 + 1) * 16;
      int r16 = (r - 1) / 16 * 16;
      if (l16 <= r16) {
        return {l, l16, r16, r};
      }
      int l4 = (l / 4 + 1) * 4;
      int r4 = (r - 1) / 4 * 4;
      if (l4 <= r4) {
        return {l, l4, r4, r};
      }
      return ALL(vector, rep1(l, r));
    }();
    ALL(path.erase, ranges::unique(path));
    print(path);
    assert(ssize(path) <= 4);
    for (int i : rep(1, ssize(path))) {
      assert(se.contains({path[i - 1], path[i]}));
    }
  }
}

}  // namespace

int main() {
  ios::sync_with_stdio(false);

  solve();
}

#else  // __INCLUDE_LEVEL__

#undef assert
#define assert(expr) (expr) || (__builtin_unreachable(), 0)

#define ALL(f, r, ...) \
  [&](auto&& _) { return f(begin(_), end(_), ##__VA_ARGS__); }(r)

template <class T, class U = T>
bool chmin(T& x, U&& y) {
  return y < x && (x = forward<U>(y), true);
}

template <class T, class U = T>
bool chmax(T& x, U&& y) {
  return x < y && (x = forward<U>(y), true);
}

namespace std {

template <class T1, class T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
  return is >> p.first >> p.second;
}

template <class... Ts>
istream& operator>>(istream& is, tuple<Ts...>& t) {
  return apply([&is](auto&... xs) -> istream& { return (is >> ... >> xs); }, t);
}

template <class... Ts>
istream& operator>>(istream& is, tuple<Ts&...>&& t) {
  return is >> t;
}

template <class R, enable_if_t<!is_convertible_v<R, string>>* = nullptr>
auto operator>>(istream& is, R&& r) -> decltype(is >> *begin(r)) {
  for (auto&& e : r) {
    is >> e;
  }
  return is;
}

template <class T1, class T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& p) {
  return os << p.first << ' ' << p.second;
}

template <class... Ts>
ostream& operator<<(ostream& os, const tuple<Ts...>& t) {
  auto f = [&os](const auto&... xs) -> ostream& {
    [[maybe_unused]] auto sep = "";
    ((os << exchange(sep, " ") << xs), ...);
    return os;
  };
  return apply(f, t);
}

template <class R, enable_if_t<!is_convertible_v<R, string_view>>* = nullptr>
auto operator<<(ostream& os, R&& r) -> decltype(os << *begin(r)) {
  auto sep = "";
  for (auto&& e : r) {
    os << exchange(sep, " ") << e;
  }
  return os;
}

}  // namespace std

template <class... Ts>
void print(Ts&&... xs) {
  cout << tie(xs...) << '\n';
}

inline auto rep(int l, int r) { return views::iota(min(l, r), r); }
inline auto rep(int n) { return rep(0, n); }
inline auto rep1(int l, int r) { return rep(l, r + 1); }
inline auto rep1(int n) { return rep(1, n + 1); }
inline auto per(int l, int r) { return rep(l, r) | views::reverse; }
inline auto per(int n) { return per(0, n); }
inline auto per1(int l, int r) { return per(l, r + 1); }
inline auto per1(int n) { return per(1, n + 1); }

#endif  // __INCLUDE_LEVEL__

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3408kb

input:

9
45
0 1
0 2
0 3
0 4
0 5
0 6
0 7
0 8
0 9
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
2 3
2 4
2 5
2 6
2 7
2 8
2 9
3 4
3 5
3 6
3 7
3 8
3 9
4 5
4 6
4 7
4 8
4 9
5 6
5 7
5 8
5 9
6 7
6 8
6 9
7 8
7 9
8 9

output:

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

result:

ok edges: 8

Test #2:

score: 0
Accepted
time: 3ms
memory: 3432kb

input:

30
465
0 1
0 2
0 3
0 4
0 5
0 6
0 7
0 8
0 9
0 10
0 11
0 12
0 13
0 14
0 15
0 16
0 17
0 18
0 19
0 20
0 21
0 22
0 23
0 24
0 25
0 26
0 27
0 28
0 29
0 30
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
1 21
1 22
1 23
1 24
1 25
1 26
1 27
1 28
1 29
1 30
2 3
2 4
2 5
2 6...

output:

58
2 3 4
4 5 6
1 2 4
4 6 7
0 1 4
4 7 8
6 7 8
8 9 10
5 6 8
8 10 11
8 11 12
10 11 12
12 13 14
9 10 12
12 14 15
12 15 16
4 8 12
18 19 20
20 21 22
17 18 20
20 22 23
16 17 20
20 23 24
22 23 24
24 25 26
21 22 24
24 26 27
24 27 28
26 27 28
28 29 30
25 26 28
20 24 28
14 15 16
16 17 18
13 14 16
16 18 19
11 1...

result:

ok edges: 58

Test #3:

score: 0
Accepted
time: 501ms
memory: 3660kb

input:

736
200000
170 268
126 166
565 723
664 735
61 524
226 234
146 314
217 272
294 713
115 381
563 706
74 567
552 614
120 211
472 620
213 432
488 623
447 564
96 129
331 354
79 677
50 547
174 568
56 129
189 227
55 701
244 253
264 715
154 220
380 657
46 390
53 161
325 537
666 696
64 465
391 659
284 448
207...

output:

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

result:

ok edges: 3198

Test #4:

score: 0
Accepted
time: 1274ms
memory: 28088kb

input:

65536
200000
51949 58727
7943 43298
6290 7369
41493 53070
24229 36675
28087 49947
11703 48217
19923 24739
2144 59777
53830 56793
13509 37211
2300 38595
27415 42879
24616 48531
58341 63327
20628 38407
48616 60290
7450 61685
37010 47595
22164 42732
19181 29850
35383 43587
39257 44397
19340 45183
34523...

output:

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

result:

ok edges: 357771

Test #5:

score: 0
Accepted
time: 2ms
memory: 3472kb

input:

0
0

output:

0

result:

ok edges: 0

Test #6:

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

input:

1
1
0 1

output:

0
0 1

result:

ok edges: 0

Test #7:

score: 0
Accepted
time: 2ms
memory: 3540kb

input:

2
3
0 1
0 2
1 2

output:

0
0 1
0 1 2
1 2

result:

ok edges: 0

Test #8:

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

input:

3
6
0 1
0 2
0 3
1 2
1 3
2 3

output:

0
0 1
0 1 2
0 1 2 3
1 2
1 2 3
2 3

result:

ok edges: 0

Test #9:

score: 0
Accepted
time: 1207ms
memory: 28252kb

input:

65535
200000
35006 46944
17075 57351
24605 50445
5938 60705
15221 40233
28599 38915
1132 35574
8555 31494
13644 35806
44940 55401
9503 59206
21011 26540
41156 62487
57510 64305
9254 25610
17301 47249
34083 49167
48018 64394
38855 62175
15464 22525
23728 60275
54028 63810
22711 53902
5984 48625
5838 ...

output:

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

result:

ok edges: 357768

Test #10:

score: 0
Accepted
time: 1325ms
memory: 26928kb

input:

64800
200000
55124 62263
24992 39760
32262 37059
25987 42889
10413 64701
7223 43221
45810 63205
11437 29357
10814 52096
1154 36319
10730 54157
18473 26729
9152 23374
5426 12744
3502 37577
5559 37160
30503 62433
12426 47332
14933 62086
8781 21527
27180 53773
29658 46742
20592 61553
8337 27197
8024 38...

output:

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

result:

ok edges: 353800

Extra Test:

score: 0
Extra Test Passed