QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#293695 | #4894. 学姐买瓜 | zyc070419 | 20 | 67ms | 12584kb | C++14 | 3.7kb | 2023-12-29 16:30:54 | 2023-12-29 16:30:55 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
const int M = 6e5 + 10;
inline int read() {
char ch = getchar(); int x = 0;
while (!isdigit(ch)) {ch = getchar();}
while (isdigit(ch)) {x = (x << 3) + (x << 1) + ch - '0'; ch = getchar();}
return x;
}
struct LCT {
int a[M], fa[M], ch[M][2], val[M], rev[M];
#define ls ch[x][0]
#define rs ch[x][1]
bool isroot(int x) {return ch[fa[x]][0] != x && ch[fa[x]][1] != x;}
int get(int x) {return ch[fa[x]][1] == x;}
void push_up(int x) {val[x] = val[ls] + val[rs] + a[x];}
void change(int x) {rev[x] ^= 1; swap(ls, rs);}
void push_down(int x) {
if(rev[x]) {
if(ls) change(ls);
if(rs) change(rs);
rev[x] ^= 1;
}
}
void rotate(int x) {
int y = fa[x], z = fa[y], k = get(x);
if(!isroot(y)) ch[z][ch[z][1] == y] = x;
ch[y][k] = ch[x][!k]; fa[ch[x][!k]] = y;
ch[x][!k] = y; fa[y] = x; fa[x] = z;
push_up(y); push_up(x);
}
void update(int x) {
if(!isroot(x)) update(fa[x]);
push_down(x);
}
void Splay(int x) {
update(x);
for(int fx; fx = fa[x], !isroot(x); rotate(x))
if(!isroot(fx)) rotate(get(x) == get(fx) ? fx : x);
}
int access(int x) {
int p;
for(p = 0; x; p = x, x = fa[x])
Splay(x), rs = p, push_up(x);
return p;
}
void make_root(int x) {x = access(x); change(x);}
void split(int x, int y) {make_root(x); access(y); Splay(y);}
int find(int x) {
access(x); Splay(x); push_down(x);
while(ls) {x = ls; push_down(x);}
Splay(x);
return x;
}
void link(int x, int y) {
make_root(x); Splay(x);
if(find(y) == x) return;
fa[x] = y;
}
void cut(int x, int y) {
make_root(x); access(y); Splay(y);
if(ch[y][0] == x && rs == 0) ch[y][0] = fa[x] = 0;
}
}t;
int n, T, v[N], nxt[M];
vector<int> mem;
set<int> S;
int main() {
T = read(); n = read() + 1;
for (int i = 1; i < n; ++i) {
t.link(i, i + n);
t.link(i + n, i + 1);
nxt[i + n] = i + 1;
}
int opt, l, r;
while (T--) {
opt = read(); l = read(); r = read();
if (opt == 1) {
auto it = S.lower_bound(r);
if (it != S.begin()) {
it--;
if (v[*it] >= max(l, v[r])) {
v[r] = max(l, v[r]);
continue;
}
}
S.insert(r);
it = S.upper_bound(r);
while (it != S.end() && v[*it] <= max(v[r], l)) {
int x = (*it); mem.push_back(x);
nxt[v[x] + n] = v[x] + 1;
t.cut(v[x], v[x] + n);
t.cut(v[x] + n, x + 1);
t.Splay(v[x] + n);
t.a[v[x] + n] = 0;
t.push_up(v[x] + n);
t.link(v[x], v[x] + n);
t.link(v[x] + n, v[x] + 1);
it++;
}
for (auto o : mem) S.erase(S.find(o));
mem.clear();
if (v[r] < l) {
if (v[r]) {
nxt[v[r] + n] = v[r] + 1;
t.cut(v[r], v[r] + n);
t.cut(v[r] + n, r + 1);
t.Splay(v[r] + n);
t.a[v[r] + n] = 0;
t.push_up(v[r] + n);
t.link(v[r], v[r] + n);
t.link(v[r] + n, v[r] + 1);
}
v[r] = l;
nxt[v[r] + n] = r + 1;
t.cut(v[r], v[r] + n);
t.cut(v[r] + n, v[r] + 1);
t.Splay(v[r] + n);
t.a[v[r] + n] = 1;
t.push_up(v[r] + n);
t.link(v[r], v[r] + n);
t.link(v[r] + n, r + 1);
}
}else {
t.split(l, n); int x = n, y = 0;
while (x) {
t.push_down(x);
int o = (x <= n ? x : nxt[x]);
if (o <= r + 1) {
y = x;
x = t.ch[x][1];
}
else x = t.ch[x][0];
}
t.split(l, y);
printf("%d\n", t.val[y]);
}
}
return 0;
}
詳細信息
Subtask #1:
score: 20
Accepted
Test #1:
score: 20
Accepted
time: 1ms
memory: 5816kb
input:
11 13 2 4 4 1 11 12 1 1 5 1 2 3 1 2 10 2 2 8 1 6 6 2 2 10 1 6 11 2 2 3 2 2 13
output:
0 1 2 1 3
result:
ok 5 lines
Test #2:
score: 0
Accepted
time: 2ms
memory: 5992kb
input:
2000 2000 2 66 273 1 475 1570 2 51 958 2 731 1771 1 1286 1627 1 37 892 1 529 890 2 155 1486 1 87 1815 1 576 1872 2 1269 1515 2 1521 1794 2 634 1887 2 204 1668 1 351 1679 2 1571 1599 1 243 681 2 1 2000 2 1 2000 2 564 648 2 1215 1807 2 466 1617 1 1119 1348 1 497 886 2 1358 1487 2 173 1974 1 401 1294 2...
output:
0 0 0 1 0 0 1 2 0 2 2 0 1 1 0 2 1 1 0 1 0 1 0 0 1 2 1 1 1 2 1 1 0 0 2 2 0 2 2 0 1 3 0 0 4 0 0 2 2 5 2 0 4 0 2 0 2 3 3 0 0 1 3 2 0 3 6 1 0 1 1 4 0 8 0 8 1 3 1 8 1 4 9 2 2 0 4 5 2 9 3 0 9 1 3 8 9 1 0 7 0 8 5 7 0 1 0 6 10 2 6 0 1 0 6 4 6 5 4 4 4 0 10 0 6 2 8 9 1 10 5 7 8 10 1 10 8 5 2 6 1 5 10 8 10 5 3...
result:
ok 1020 lines
Test #3:
score: 0
Accepted
time: 0ms
memory: 6056kb
input:
2000 2000 2 66 273 1 475 1570 2 51 958 2 731 1771 1 1286 1627 1 37 892 1 529 890 2 155 1486 1 87 1815 1 576 1872 2 1269 1515 2 1521 1794 2 634 1887 2 204 1668 1 351 1679 2 1571 1599 1 243 681 2 1 2000 2 1 2000 2 564 648 2 1215 1807 2 466 1617 1 1119 1348 1 497 886 2 1358 1487 2 173 1974 1 401 1294 2...
output:
0 0 0 1 0 0 1 2 0 2 2 0 1 1 0 2 1 1 0 1 0 1 0 0 1 2 1 1 1 2 1 1 0 0 2 2 0 2 2 0 1 3 0 0 4 0 0 2 2 5 2 0 4 0 2 0 2 3 3 0 0 1 3 2 0 3 6 1 0 1 1 4 0 8 0 8 1 3 1 8 1 4 9 2 2 0 4 5 2 9 3 0 9 1 3 8 9 1 0 7 0 8 5 7 0 1 0 6 10 2 6 0 1 0 6 4 6 5 4 4 4 0 10 0 6 2 8 9 1 10 5 7 8 10 1 10 8 5 2 6 1 5 10 8 10 5 3...
result:
ok 1020 lines
Test #4:
score: 0
Accepted
time: 1ms
memory: 5884kb
input:
14 11 1 1 8 1 4 11 2 4 8 1 2 7 1 7 11 2 2 9 1 6 10 1 2 6 1 8 10 1 2 6 2 9 10 1 9 9 1 3 10 1 2 4
output:
0 1 0
result:
ok 3 lines
Test #5:
score: 0
Accepted
time: 3ms
memory: 6156kb
input:
2000 2000 1 1589 1640 1 1741 1765 2 191 1596 1 426 493 2 1434 1606 1 925 955 2 589 1148 2 1347 1608 2 686 1516 1 1535 1563 1 1835 1841 1 1513 1537 2 30 1710 2 123 171 2 1 2000 2 128 1310 2 270 879 1 1918 1941 2 965 1951 2 176 1452 1 1391 1421 1 614 664 2 1 2000 1 296 328 1 1378 1402 1 29 47 1 92 123...
output:
0 0 1 0 1 4 0 6 2 1 5 2 9 12 4 0 6 14 3 3 0 1 13 3 6 19 13 20 1 4 2 10 1 5 4 8 3 5 24 18 9 17 13 0 28 22 4 6 13 1 13 4 15 5 2 16 1 33 25 16 18 17 8 17 23 36 22 27 9 23 9 7 17 2 12 16 39 11 32 40 4 10 15 23 21 14 10 15 6 43 17 3 17 0 1 15 14 29 33 8 44 44 5 10 27 22 11 6 23 0 7 24 14 24 1 9 36 15 39 ...
result:
ok 1000 lines
Test #6:
score: 0
Accepted
time: 3ms
memory: 6112kb
input:
2000 2000 1 1589 1640 1 1741 1765 2 191 1596 1 426 493 2 1434 1606 1 925 955 2 589 1148 2 1347 1608 2 686 1516 1 1535 1563 1 1835 1841 1 1513 1537 2 30 1710 2 123 171 2 1 2000 2 128 1310 2 270 879 1 1918 1941 2 965 1951 2 176 1452 1 1391 1421 1 614 664 2 1 2000 1 296 328 1 1378 1402 1 29 47 1 92 123...
output:
0 0 1 0 1 4 0 6 2 1 5 2 9 12 4 0 6 14 3 3 0 1 13 3 6 19 13 20 1 4 2 10 1 5 4 8 3 5 24 18 9 17 13 0 28 22 4 6 13 1 13 4 15 5 2 16 1 33 25 16 18 17 8 17 23 36 22 27 9 23 9 7 17 2 12 16 39 11 32 40 4 10 15 23 21 14 10 15 6 43 17 3 17 0 1 15 14 29 33 8 44 44 5 10 27 22 11 6 23 0 7 24 14 24 1 9 36 15 39 ...
result:
ok 1000 lines
Test #7:
score: 0
Accepted
time: 3ms
memory: 6060kb
input:
2000 2000 2 100 273 1 1901 1904 2 51 958 2 731 1771 1 1772 1775 1 375 378 1 540 543 1 649 652 1 129 132 2 139 286 2 155 1490 2 87 1279 1 547 550 2 1135 1365 1 1685 1688 2 470 1269 2 1521 1540 2 62 634 2 1186 1668 1 1276 1279 1 725 728 2 1571 1599 1 246 249 2 243 681 1 103 106 1 547 550 2 324 361 2 5...
output:
0 0 0 0 3 4 0 3 0 4 0 0 5 0 6 1 8 0 2 1 11 3 1 5 15 6 1 18 1 5 0 1 4 22 8 5 24 17 8 26 0 6 27 4 17 14 29 3 40 15 30 23 13 6 13 10 18 2 33 9 31 47 12 0 48 4 27 2 3 10 6 52 15 1 17 7 9 58 15 7 9 37 17 2 27 4 13 57 32 21 43 66 16 49 10 6 0 26 25 51 42 13 26 5 82 4 82 13 14 13 5 48 8 38 94 15 23 3 39 38...
result:
ok 990 lines
Test #8:
score: 0
Accepted
time: 0ms
memory: 8096kb
input:
2000 2000 2 100 273 1 1901 1904 2 51 958 2 731 1771 1 1772 1775 1 375 378 1 540 543 1 649 652 1 129 132 2 139 286 2 155 1490 2 87 1279 1 547 550 2 1135 1365 1 1685 1688 2 470 1269 2 1521 1540 2 62 634 2 1186 1668 1 1276 1279 1 725 728 2 1571 1599 1 246 249 2 243 681 1 103 106 1 547 550 2 324 361 2 5...
output:
0 0 0 0 3 4 0 3 0 4 0 0 5 0 6 1 8 0 2 1 11 3 1 5 15 6 1 18 1 5 0 1 4 22 8 5 24 17 8 26 0 6 27 4 17 14 29 3 40 15 30 23 13 6 13 10 18 2 33 9 31 47 12 0 48 4 27 2 3 10 6 52 15 1 17 7 9 58 15 7 9 37 17 2 27 4 13 57 32 21 43 66 16 49 10 6 0 26 25 51 42 13 26 5 82 4 82 13 14 13 5 48 8 38 94 15 23 3 39 38...
result:
ok 990 lines
Test #9:
score: 0
Accepted
time: 3ms
memory: 6092kb
input:
2000 2000 2 100 273 1 1901 1904 2 51 958 2 731 1771 1 1772 1775 1 375 378 1 540 543 1 649 652 1 129 132 2 139 286 2 155 1490 2 87 1279 1 547 550 2 1135 1365 1 1685 1688 2 470 1269 2 1521 1540 2 62 634 2 1186 1668 1 1276 1279 1 725 728 2 1571 1599 1 246 249 2 243 681 1 103 106 1 547 550 2 324 361 2 5...
output:
0 0 0 0 3 4 0 3 0 4 0 0 5 0 6 1 8 0 2 1 11 3 1 5 15 6 1 18 1 5 0 1 4 22 8 5 24 17 8 26 0 6 27 4 17 14 29 3 40 15 30 23 13 6 13 10 18 2 33 9 31 47 12 0 48 4 27 2 3 10 6 52 15 1 17 7 9 58 15 7 9 37 17 2 27 4 13 57 32 21 43 66 16 49 10 6 0 26 25 51 42 13 26 5 82 4 82 13 14 13 5 48 8 38 94 15 23 3 39 38...
result:
ok 990 lines
Test #10:
score: 0
Accepted
time: 3ms
memory: 6124kb
input:
2000 2000 2 66 273 1 1 501 1 2 502 2 51 70 1 3 503 2 731 1771 1 4 504 2 149 1627 2 1792 1849 1 5 505 2 139 286 2 155 1490 2 87 1279 1 6 506 2 816 1365 2 576 783 2 1269 1515 2 1521 1794 2 634 1887 2 204 1668 1 7 507 1 8 508 1 9 509 2 1571 1599 1 10 510 2 1 2000 2 1 2000 2 1 2000 2 564 648 2 1215 1807...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 1 1 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 ...
result:
ok 1004 lines
Test #11:
score: 0
Accepted
time: 3ms
memory: 6176kb
input:
2000 2000 2 66 273 1 1 501 1 2 502 2 51 70 1 3 503 2 731 1771 1 4 504 2 149 1627 2 1792 1849 1 5 505 2 139 286 2 155 1490 2 87 1279 1 6 506 2 816 1365 2 576 783 2 1269 1515 2 1521 1794 2 634 1887 2 204 1668 1 7 507 1 8 508 1 9 509 2 1571 1599 1 10 510 2 1 2000 2 1 2000 2 1 2000 2 564 648 2 1215 1807...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 1 1 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 ...
result:
ok 1004 lines
Test #12:
score: 0
Accepted
time: 3ms
memory: 6120kb
input:
2000 2000 2 87 1924 1 1223 1268 2 64 1968 1 426 493 2 27 1931 1 1191 1226 2 86 1985 1 1742 1771 2 81 1984 1 631 677 1 792 813 2 32 1936 2 63 1954 2 56 1952 2 4 1937 1 1095 1117 1 781 797 1 1036 1052 1 144 174 1 999 1027 2 43 1911 2 49 1995 1 326 363 1 1580 1627 1 270 303 1 1010 1037 1 687 728 1 1895...
output:
0 1 2 2 3 5 5 5 5 9 9 14 14 14 14 15 15 16 15 15 17 15 15 18 17 17 18 20 19 19 20 20 19 20 20 20 20 20 20 20 21 20 22 23 22 24 25 22 24 24 24 23 26 27 25 27 28 29 28 27 30 30 30 27 29 29 28 30 31 30 31 31 30 29 32 30 33 31 34 33 13 35 33 35 31 32 32 33 31 32 32 33 35 35 36 34 36 35 36 34 38 36 36 35...
result:
ok 1000 lines
Test #13:
score: 0
Accepted
time: 3ms
memory: 6064kb
input:
2000 2000 2 87 1924 1 1223 1268 2 64 1968 1 426 493 2 27 1931 1 1191 1226 2 86 1985 1 1742 1771 2 81 1984 1 631 677 1 792 813 2 32 1936 2 63 1954 2 56 1952 2 4 1937 1 1095 1117 1 781 797 1 1036 1052 1 144 174 1 999 1027 2 43 1911 2 49 1995 1 326 363 1 1580 1627 1 270 303 1 1010 1037 1 687 728 1 1895...
output:
0 1 2 2 3 5 5 5 5 9 9 14 14 14 14 15 15 16 15 15 17 15 15 18 17 17 18 20 19 19 20 20 19 20 20 20 20 20 20 20 21 20 22 23 22 24 25 22 24 24 24 23 26 27 25 27 28 29 28 27 30 30 30 27 29 29 28 30 31 30 31 31 30 29 32 30 33 31 34 33 13 35 33 35 31 32 32 33 31 32 32 33 35 35 36 34 36 35 36 34 38 36 36 35...
result:
ok 1000 lines
Test #14:
score: 0
Accepted
time: 3ms
memory: 6132kb
input:
2000 2000 2 87 1924 1 1223 1268 2 64 1968 1 426 493 2 27 1931 1 1191 1226 2 86 1985 1 1742 1771 2 81 1984 1 631 677 1 792 813 2 32 1936 2 63 1954 2 56 1952 2 4 1937 1 1095 1117 1 781 797 1 1036 1052 1 144 174 1 999 1027 2 43 1911 2 49 1995 1 326 363 1 1580 1627 1 270 303 1 1010 1037 1 687 728 1 1895...
output:
0 1 2 2 3 5 5 5 5 9 9 14 14 14 14 15 15 16 15 15 17 15 15 18 17 17 18 20 19 19 20 20 19 20 20 20 20 20 20 20 21 20 22 23 22 24 25 22 24 24 24 23 26 27 25 27 28 29 28 27 30 30 30 27 29 29 28 30 31 30 31 31 30 29 32 30 33 31 34 33 13 35 33 35 31 32 32 33 31 32 32 33 35 35 36 34 36 35 36 34 38 36 36 35...
result:
ok 1000 lines
Test #15:
score: 0
Accepted
time: 0ms
memory: 5924kb
input:
12 11 2 4 5 2 2 10 1 3 7 1 4 7 1 5 11 1 5 7 2 1 3 1 1 4 2 3 3 2 11 11 1 1 10 2 10 11
output:
0 0 0 0 0 0
result:
ok 6 lines
Subtask #2:
score: 0
Wrong Answer
Dependency #1:
100%
Accepted
Test #16:
score: 0
Wrong Answer
time: 67ms
memory: 12584kb
input:
80000 80000 2 14017 46708 2 26100 26240 2 3855 12007 2 72192 75052 1 12615 30948 2 36 51149 1 47528 79363 1 68506 72310 1 31635 62123 2 7480 77998 1 52530 75803 2 1793 30290 2 47012 72210 1 63304 66834 1 24988 62161 1 34585 61735 1 2973 61060 2 23879 44146 2 11903 26606 2 11536 72847 1 47874 65933 1...
output:
0 0 0 0 1 3 0 0 0 0 4 2 0 0 0 0 2 0 0 1 0 1 1 4 0 6 1 1 3 1 1 0 6 6 0 1 1 4 1 4 6 3 0 4 4 0 4 0 4 5 7 4 7 5 5 2 9 5 5 2 10 1 1 0 1 0 3 8 0 11 2 0 8 5 5 3 11 5 11 4 4 3 0 2 6 5 9 4 6 5 2 0 0 0 7 5 0 4 0 2 13 0 5 7 7 5 5 2 6 0 14 0 0 3 4 4 7 7 2 4 3 8 2 1 15 7 7 7 0 12 5 10 0 5 5 5 6 7 12 1 16 3 2 0 2...
result:
wrong answer 2319th lines differ - expected: '31', found: '30'
Subtask #3:
score: 0
Skipped
Dependency #2:
0%