QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#175524 | #7182. Very Sparse Table | SorahISA | AC ✓ | 1353ms | 52540kb | C++20 | 5.5kb | 2023-09-10 19:06:57 | 2023-09-10 19:06:58 |
Judging History
answer
#ifndef Yamada
#define Yamada
#include Yamada __FILE__ Yamada
using p3i = tuple<int, int, int>;
const int maxn = (1 << 16) + 5;
// int max_depth = 0;
vector<int> sq(maxn);
void recur(auto &edges, int L, int R, bool output = false, int dep = 1) {
// if (chmax(max_depth, dep)) debug(dep);
int B = sq[R-L];
vector<int> big;
for (int i = L; i < R; i += B) big.eb(i);
big.eb(R);
if (output) {
// if (chmax(max_depth, dep)) debug(dep, L, R, 2*(R-L-2));
for (int i = L+2; i <= R-1; ++i) edges.eb(L, i-1, i);
for (int i = R-2; i >= L+1; --i) edges.eb(i, i+1, R);
}
if (R - L <= 2) return;
for (int i = 0; i+1 < SZ(big); ++i) recur(edges, big[i], big[i+1], true, dep+1);
// for (int id = 0; id+1 < SZ(big); ++id) {
// int i = big[id], b = big[id+1] - big[id];
// /// link i to i+1, ..., i+B-1 ///
// /// link i+1, ..., i+B-1 to i+B ///
// /// link i to i+B ///
// for (int j = 2; j <= b-1; ++j) edges.eb(i, i+j-1, i+j);
// for (int j = b-2; j >= 1; --j) edges.eb(i+j, i+j+1, i+b);
// if (b != 1) edges.eb(i, i+1, i+b);
// }
for (int i = 0; i+1 < SZ(big); ++i) edges.eb(big[i], big[i]+1, big[i+1]);
for (int len = 2; len < SZ(big); ++len) {
for (int i = 0, j = i+len; j < SZ(big); ++i, ++j) edges.eb(big[i], big[i+1], big[j]);
}
}
pii query(int L, int R, int u, int v) {
int B = sq[R-L];
int u_blk = (u - L) / B * B + L, v_blk = (v - L) / B * B + L;
if (u_blk == v_blk) return query(u_blk, min(u_blk + B, R), u, v);
return {min(u_blk + B, R), v_blk};
}
void solve() {
int N; cin >> N;
vector<p3i> _edges;
recur(_edges, 0, N);
set<pii> edge_set;
vector<p3i> edges;
for (int i = 0; i+1 <= N; ++i) edge_set.ee(i, i+1);
for (auto [a, b, c] : _edges) {
if (edge_set.contains(pii{a, c})) continue;
edge_set.ee(a, c);
edges.eb(a, b, c);
if (a == b or b == c or a == c) {
// debug(a, b, c);
assert(false);
}
if (!edge_set.contains(pii{a, b}) or !edge_set.contains(pii{b, c})) {
// debug("add", a, c, "no", a, b, "or", b, c);
assert(false);
}
}
// assert(SZ(edges) <= 6 * N); /// not here
cout << SZ(edges) << "\n";
for (auto [a, b, c] : edges) cout << a << " " << b << " " << c << "\n";
cout << flush;
/// start query ///
int Q; cin >> Q;
for (int q = 1; q <= Q; ++q) {
int l, r; cin >> l >> r;
// l = rng() % (N+1), r = (l + rng() % N) % (N+1);
// if (l > r) swap(l, r);
if (r - l <= 3) {
for (int i = l; i <= r; ++i) cout << i << " \n"[i == r];
cout << flush;
continue;
}
pii res = query(0, N, l, r);
vector<int> ans{l, res.first, res.second, r};
ans.erase(unique(ALL(ans)), end(ans));
for (int i = 0; i < SZ(ans); ++i) cout << ans[i] << " \n"[i == SZ(ans)-1];
cout << flush;
for (int i = 0; i+1 < SZ(ans); ++i) {
if (!edge_set.contains(pii{ans[i], ans[i+1]})) {
// debug(ans);
assert(false);
}
}
}
}
void init() {
for (int i = 0; i < maxn; ++i) {
// sq[i] = int(sqrt(i));
if (i <= (1 << 1)) sq[i] = (1 << 0);
else if (i <= (1 << 2)) sq[i] = (1 << 1);
else if (i <= (1 << 4)) sq[i] = (1 << 2);
else if (i <= (1 << 8)) sq[i] = (1 << 4);
else if (i <= (1 << 16)) sq[i] = (1 << 8);
}
}
int32_t main() {
fastIO();
init();
int t = 1; // cin >> t;
for (int _ = 1; _ <= t; ++_) {
solve();
}
return 0;
}
#else
#ifdef local
#define _GLIBCXX_DEBUG 1
#endif
#pragma GCC optimize("Ofast", "unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
// #define double __float80
using pii = pair<int, int>;
template <typename T> using Prior = std::priority_queue<T>;
template <typename T> using prior = std::priority_queue<T, vector<T>, greater<T>>;
// #define X first
// #define Y second
#define eb emplace_back
#define ef emplace_front
#define ee emplace
#define pb pop_back
#define pf pop_front
#define ALL(x) begin(x), end(x)
#define RALL(x) rbegin(x), rend(x)
#define SZ(x) ((int)(x).size())
#ifdef local
#define fastIO() void()
#define debug(...) \
fprintf(stderr, "%sAt [%s], line %d: (%s) = ", "\u001b[33m", __FILE__, __LINE__, #__VA_ARGS__), \
_do(__VA_ARGS__), fprintf(stderr, "%s", "\u001b[0m")
template <typename T> void _do(T &&_t) {cerr << _t << "\n";}
template <typename T, typename ...U> void _do(T &&_t, U &&..._u) {cerr << _t << ", ", _do(_u...);}
#else
#define fastIO() ios_base::sync_with_stdio(0), cin.tie(0)
#define debug(...) void()
#endif
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T, typename U> bool chmin(T &lhs, U rhs) {return lhs > rhs ? lhs = rhs, 1 : 0;}
template <typename T, typename U> bool chmax(T &lhs, U rhs) {return lhs < rhs ? lhs = rhs, 1 : 0;}
template <typename T>
ostream & operator << (ostream &os, const vector<T> &vec) {
os << "[";
for (int i = 0; i < SZ(vec); ++i) {
if (i) os << ", ";
os << vec[i];
}
os << "]";
return os;
}
#endif
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 3524kb
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:
13 0 1 2 0 2 3 2 3 4 1 2 4 0 2 4 4 5 6 4 6 7 6 7 8 5 6 8 4 6 8 0 4 8 4 8 9 0 4 9 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 2 3 4 1 4 5 1 4 6 1 4 7 1 4 8 1 4 8 9 2 3 2 3 4 2 3 4 5 2 4 6 2 4 7 2 4 8 2 4 8 9 3 4 3 4 5 3 4 5 6 3 4 7 3 4 8 3 4 8 9 4 5 4 5 6 4 5 6 7 4 8 4 8 9 5 6 5...
result:
ok edges: 13
Test #2:
score: 0
Accepted
time: 5ms
memory: 3556kb
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:
83 0 1 2 0 2 3 0 3 4 0 4 5 0 5 6 0 6 7 0 7 8 0 8 9 0 9 10 0 10 11 0 11 12 0 12 13 0 13 14 0 14 15 14 15 16 13 14 16 12 13 16 11 12 16 10 11 16 9 10 16 8 9 16 7 8 16 6 7 16 5 6 16 4 5 16 3 4 16 2 3 16 1 2 16 2 3 4 1 2 4 4 5 6 4 6 7 6 7 8 5 6 8 4 6 8 8 9 10 8 10 11 10 11 12 9 10 12 8 10 12 12 13 14 12...
result:
ok edges: 83
Test #3:
score: 0
Accepted
time: 518ms
memory: 4304kb
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:
3648 0 1 2 0 2 3 0 3 4 0 4 5 0 5 6 0 6 7 0 7 8 0 8 9 0 9 10 0 10 11 0 11 12 0 12 13 0 13 14 0 14 15 0 15 16 0 16 17 0 17 18 0 18 19 0 19 20 0 20 21 0 21 22 0 22 23 0 23 24 0 24 25 0 25 26 0 26 27 0 27 28 0 28 29 0 29 30 0 30 31 0 31 32 0 32 33 0 33 34 0 34 35 0 35 36 0 36 37 0 37 38 0 38 39 0 39 40 ...
result:
ok edges: 3648
Test #4:
score: 0
Accepted
time: 1353ms
memory: 52540kb
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:
358784 0 1 2 0 2 3 0 3 4 0 4 5 0 5 6 0 6 7 0 7 8 0 8 9 0 9 10 0 10 11 0 11 12 0 12 13 0 13 14 0 14 15 0 15 16 0 16 17 0 17 18 0 18 19 0 19 20 0 20 21 0 21 22 0 22 23 0 23 24 0 24 25 0 25 26 0 26 27 0 27 28 0 28 29 0 29 30 0 30 31 0 31 32 0 32 33 0 33 34 0 34 35 0 35 36 0 36 37 0 37 38 0 38 39 0 39 4...
result:
ok edges: 358784
Test #5:
score: 0
Accepted
time: 0ms
memory: 3500kb
input:
0 0
output:
0
result:
ok edges: 0
Test #6:
score: 0
Accepted
time: 1ms
memory: 3528kb
input:
1 1 0 1
output:
0 0 1
result:
ok edges: 0
Test #7:
score: 0
Accepted
time: 1ms
memory: 3520kb
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: 0ms
memory: 3544kb
input:
3 6 0 1 0 2 0 3 1 2 1 3 2 3
output:
2 0 1 2 0 2 3 0 1 0 1 2 0 1 2 3 1 2 1 2 3 2 3
result:
ok edges: 2
Test #9:
score: 0
Accepted
time: 1282ms
memory: 49960kb
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:
358780 0 1 2 0 2 3 0 3 4 0 4 5 0 5 6 0 6 7 0 7 8 0 8 9 0 9 10 0 10 11 0 11 12 0 12 13 0 13 14 0 14 15 0 15 16 0 16 17 0 17 18 0 18 19 0 19 20 0 20 21 0 21 22 0 22 23 0 23 24 0 24 25 0 25 26 0 26 27 0 27 28 0 28 29 0 29 30 0 30 31 0 31 32 0 32 33 0 33 34 0 34 35 0 35 36 0 36 37 0 37 38 0 38 39 0 39 4...
result:
ok edges: 358780
Test #10:
score: 0
Accepted
time: 1273ms
memory: 50612kb
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:
354572 0 1 2 0 2 3 0 3 4 0 4 5 0 5 6 0 6 7 0 7 8 0 8 9 0 9 10 0 10 11 0 11 12 0 12 13 0 13 14 0 14 15 0 15 16 0 16 17 0 17 18 0 18 19 0 19 20 0 20 21 0 21 22 0 22 23 0 23 24 0 24 25 0 25 26 0 26 27 0 27 28 0 28 29 0 29 30 0 30 31 0 31 32 0 32 33 0 33 34 0 34 35 0 35 36 0 36 37 0 37 38 0 38 39 0 39 4...
result:
ok edges: 354572
Extra Test:
score: 0
Extra Test Passed