QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#293606 | #4894. 学姐买瓜 | zyc070419 | 0 | 1ms | 6456kb | C++14 | 3.8kb | 2023-12-29 14:17:16 | 2023-12-29 14:17:16 |
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], tree[N];
vector<int> mem;
set<int> S;
void add(int p, int val) {
for (int i = p; i <= n; i += (i & -i))
tree[i] = max(tree[i], val);
}
int main() {
memset(tree, -0x3f, sizeof(tree));
T = read(); n = read() + 1;
for (int i = 1; i < n; ++i) {
t.link(i, i + n);
t.link(i + n, i + 1);
}
int opt, l, r;
while (T--) {
opt = read(); l = read(); r = read();
if (opt == 1) {
add(n - l + 1, n - r + 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] <= v[r]) {
int x = (*it); mem.push_back(x);
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]) {
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;
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 {
int res = 0;
for (int i = 20; i >= 0; --i) {
if (res + (1 << i) > n) continue;
if (tree[res + (1 << i)] >= n - r + 1) continue;
res += (1 << i);
}
res++;
if (n - res + 1 < l) puts("0");
else {
res = n - tree[res] + 1;
t.split(l, res + 1);
printf("%d\n", t.val[res + 1]);
}
}
}
return 0;
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 6456kb
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 2
result:
wrong answer 5th lines differ - expected: '3', found: '2'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #2:
0%