QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#339937 | #7760. 化学实验 | ClHg2 | 0 | 0ms | 0kb | C++14 | 3.1kb | 2024-02-28 07:49:07 | 2024-02-28 07:49:08 |
Judging History
answer
#include <bits/stdc++.h>
#define FOR(i, l, r) for (int i = l; i < (r); ++i)
#define F0R(i, r) FOR (i, 0, r)
#define ROF(i, l, r) for (int i = r; i-- > (l);)
#define R0F(i, r) ROF (i, 0, r)
#define rep(n) F0R (_, n)
#define each(i, x) for (auto& i : x)
using namespace std;
using ll = long long;
using db = long double;
using str = string;
using pi = pair<int, int>;
#define mp make_pair
#define f first
#define s second
#define ttt template <typename T
ttt > using vec = vector<T>;
ttt, size_t n > using arr = array<T, n>;
using vi = vec<int>;
using vb = vec<bool>;
using vl = vec<ll>;
using vpi = vec<pi>;
#define sz(x) int((x).size())
#define all(x) begin(x), end(x)
#define rsz resize
#define pb push_back
#define eb emplace_back
#define il inline
ttt > il bool ckmin(T& x, const T& y) { return y < x ? x = y, true : false; }
ttt > il bool ckmax(T& x, const T& y) { return x < y ? x = y, true : false; }
struct Node {
int sz, lsz, mx, p, l, r;
};
struct Lct {
vec<Node> t;
Lct(int n) : t(n + 1) {}
bool not_rt(int o) const { return o == t[t[o].p].l || o == t[t[o].p].r; }
void pull(int o) {
t[o].sz = t[o].lsz + t[t[o].l].sz + t[t[o].r].sz;
t[o].mx = max({o, t[t[o].l].mx, t[t[o].r].mx});
}
void rot(int o) {
int& p = t[o].p;
Node &x = t[o], &y = t[p];
if (o == y.l)
t[x.r].p = p, y.l = x.r, x.r = p;
else
t[x.l].p = p, y.r = x.l, x.l = p;
if (not_rt(p)) (p == t[y.p].l ? t[y.p].l : t[y.p].r) = o;
pull(p), pull(o), p = y.p, y.p = o;
}
void splay(int o) {
for (; not_rt(o); rot(o)) {
int p = t[o].p;
if (not_rt(p)) rot((o == t[p].l) == (p == t[t[p].p].l) ? p : o);
}
}
int access(int o) {
int p = 0;
for (; o; o = t[p = o].p)
t[o].lsz += t[p].sz - t[t[o].r].sz, t[o].r = p, pull(o);
return p;
}
int split(int o, int v) {
int p = -1, q = 0;
while (o) {
q = o;
if (o >= v)
p = o, o = t[o].l;
else
o = t[o].r;
}
return splay(q), splay(p), p;
}
void unite(int o1, int o2) {
access(o1);
int p = access(o2);
if (o1 == p || o2 == p) return;
access(p), splay(o1), splay(o2);
p = 0;
while (o1 || o2) {
if (t[o1].mx < t[o2].mx) swap(o1, o2);
o1 = split(o1, t[o2].mx);
t[o1].l = p, t[p].p = o1, pull(p = o1);
o1 = t[p].r, t[p].r = t[o1].p = 0, pull(p);
}
}
int qry(int o, int v) {
access(o), splay(o);
int ans = 0, p = 0;
while (o) {
p = o;
if (o <= v)
ans += t[o].lsz + t[t[o].r].sz, o = t[o].l;
else
o = t[o].r;
}
return splay(p), ans;
}
};
int main() {
cin.tie(nullptr)->sync_with_stdio(false), cin.exceptions(cin.failbit);
int t, n, q;
cin >> t >> n >> q;
Lct lct(n + 1);
FOR (i, 1, n + 1) lct.t[i] = {1, 1, i, n + 1};
lct.t[n + 1] = {n, n, n + 1};
int ans = 0;
rep (q) {
int type, x, y;
cin >> type >> x >> y;
x = (x - 1 + t * ans) % n + 1, y = (y - 1 + t * ans) % n + 1;
if (type == 1)
lct.unite(x, y);
else
cout << (ans = lct.qry(x, y)) << "\n";
}
}
詳細信息
Subtask #1:
score: 0
Runtime Error
Test #1:
score: 0
Runtime Error
input:
1 7500 7500 1 263 1446 1 6338 3037 1 5651 6129 1 572 3137 1 3159 5472 1 6038 4451 1 5988 5462 1 3873 1562 1 3516 5142 1 3375 2376 1 5832 1884 1 6243 3066 1 4001 6195 1 5301 6851 1 4382 2910 1 5299 562 1 452 335 1 3459 814 1 6681 6391 1 5816 4975 1 2244 1118 1 1410 1067 1 331 6324 1 6305 1294 1 4251 ...
output:
result:
Subtask #2:
score: 0
Runtime Error
Test #11:
score: 0
Runtime Error
input:
1 5000 100000 2 872 876 1 2895 4566 1 2676 1220 2 1852 1856 2 4153 4153 2 3675 3685 2 1489 1493 2 2782 2784 2 206 207 2 555 560 2 4149 4157 2 1875 1885 2 364 374 2 8 17 2 746 754 2 4785 4786 2 2394 2394 2 3386 3389 2 365 373 2 2290 2296 2 1419 1428 2 3651 3659 2 1922 1927 2 4877 4882 2 2597 2599 2 4...
output:
result:
Subtask #3:
score: 0
Runtime Error
Test #21:
score: 0
Runtime Error
input:
0 100000 100000 1 29135 32144 1 58340 30601 1 68869 18606 1 73019 84578 1 13050 79881 1 22773 20030 1 74542 28744 1 46491 64238 1 26985 17174 1 93308 48003 1 90547 4510 1 18373 35069 1 34019 14080 1 13461 19407 1 33811 60169 1 22131 76457 1 88085 38979 1 49749 20241 1 90505 42660 1 25889 75426 1 420...
output:
result:
Subtask #4:
score: 0
Skipped
Dependency #1:
0%
Subtask #5:
score: 0
Skipped
Dependency #3:
0%
Subtask #6:
score: 0
Skipped
Dependency #4:
0%