QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#449944 | #7760. 化学实验 | Made_in_Code | 0 | 47ms | 17388kb | C++14 | 3.2kb | 2024-06-21 19:56:20 | 2024-06-21 19:56:20 |
Judging History
answer
#include <iostream>
using namespace std;
const int kMaxN = 5e5 + 1;
struct V {
int mn, c, t;
int f, s[2];
bool b;
} v[kMaxN];
int u, n, m;
void TagB(int x) {
v[x].b ^= 1, swap(v[x].s[0], v[x].s[1]);
}
void TagC(int x, int y) {
v[x].c += y, v[x].t += y;
}
void Pushdown(int x) {
if (v[x].b) {
TagB(v[x].s[0]), TagB(v[x].s[1]), v[x].b = 0;
}
if (v[x].t) {
TagC(v[x].s[0], v[x].t);
TagC(v[x].s[1], v[x].t);
v[x].t = 0;
}
}
void Pushup(int x) {
v[x].mn = v[x].s[1] ? v[v[x].s[1]].mn : x;
}
int Son(int x) {
return (v[v[x].f].s[0] == x) + (v[v[x].f].s[1] == x) * 2 - 1;
}
void RePush(int x) {
~Son(x) ? RePush(v[x].f) : void(), Pushdown(x);
}
void Rotate(int x, bool o) {
int y = v[x].s[!o], s = Son(x);
v[x].s[!o] = v[y].s[o], v[y].s[o] = x;
v[y].f = v[x].f, v[x].f = y;
v[v[x].s[!o]].f = x, ~s && (v[v[y].f].s[s] = y);
Pushup(x), Pushup(y);
}
void Splay(int x) {
RePush(x);
while (~Son(x)) {
int s = Son(x), t = Son(v[x].f);
if (~t) {
Rotate(s == t ? v[v[x].f].f : v[x].f, !s);
Rotate(v[x].f, !t);
} else {
Rotate(v[x].f, !s);
}
}
}
void Access(int x) {
for (int y = 0; x; y = x, x = v[x].f) {
Splay(x), v[x].s[1] = y, Pushup(x);
}
}
void MakeRoot(int x) {
Access(x), Splay(x), TagB(x);
}
int FindTop(int x) {
Splay(x);
for (; v[x].s[0];) {
x = v[x].s[0], Pushdown(x);
}
return Splay(x), x;
}
int FindRoot(int x) {
return Access(x), FindTop(x);
}
void Link(int x, int y) {
x > y ? swap(x, y) : void();
int z = FindRoot(y);
if (FindRoot(x) != z) {
MakeRoot(x), v[x].f = y, MakeRoot(z);
Access(y), Splay(y), TagC(y, v[x].c);
}
}
bool Exist(int x, int y) {
MakeRoot(x), Access(y), Splay(x);
return v[x].s[1] == y && !v[y].s[0];
}
void Cut(int x, int y) {
x > y ? swap(x, y) : void();
int z = FindRoot(y);
if (Exist(x, y)) {
v[x].s[1] = v[y].f = 0, Pushup(x), MakeRoot(z);
Access(y), Splay(y), TagC(y, -v[x].c);
}
}
int FindGap(int x, int y) {
if (v[x].s[0] && v[v[x].s[0]].mn <= y) {
return FindGap(v[x].s[0], y);
} else if (x <= y) {
return x;
}
return FindGap(v[x].s[1], y);
}
void Merge(int x, int y) {
int topx, topy, _x, _y, mid;
Access(x), topx = FindTop(x);
if (topx == FindTop(y)) {
return;
}
Access(y), topy = FindTop(y);
if (FindTop(x) == topy) {
return;
}
_x = FindTop(x), Access(v[_x].f), _y = FindTop(y);
if (topx == topy) {
Cut(_y, v[_y].f);
}
for (; Splay(_x), v[_x].mn < _y;) {
_x = FindGap(_x, _y);
if (~Son(_x)) {
mid = v[_x].f, Cut(mid, _x);
Link(_y, mid);
}
swap(_x, _y), swap(x, y);
}
Link(x, _y);
}
int Ask(int x, int y) { return v[FindGap(FindRoot(x), y)].c; }
int main() {
cin.tie(0), cout.tie(0);
ios::sync_with_stdio(0);
for (int i = 0; i < kMaxN; i++) {
v[i].mn = i, v[i].c = 1;
}
cin >> u >> n >> m;
for (int i = 1, o, x, y, p = 0; i <= m; i++) {
cin >> o >> x >> y;
if (u) {
x = (x + p - 1) % n + 1, y = (y + p - 1) % n + 1;
}
if (o == 1) {
Merge(x, y);
} else {
cout << Ask(x, y) << '\n';
}
}
return 0;
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 3ms
memory: 17388kb
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:
19
result:
wrong answer 1st lines differ - expected: '3984', found: '19'
Subtask #2:
score: 0
Wrong Answer
Test #11:
score: 0
Wrong Answer
time: 34ms
memory: 17272kb
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:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
result:
wrong answer 1766th lines differ - expected: '1', found: '2'
Subtask #3:
score: 0
Wrong Answer
Test #21:
score: 0
Wrong Answer
time: 47ms
memory: 17276kb
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:
56
result:
wrong answer 1st lines differ - expected: '80930', found: '56'
Subtask #4:
score: 0
Skipped
Dependency #1:
0%
Subtask #5:
score: 0
Skipped
Dependency #3:
0%
Subtask #6:
score: 0
Skipped
Dependency #4:
0%