QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#293613#4894. 学姐买瓜zyc0704190 2ms7044kbC++143.8kb2023-12-29 14:27:342023-12-29 14:27:35

Judging History

你现在查看的是最新测评结果

  • [2023-12-29 14:27:35]
  • 评测
  • 测评结果:0
  • 用时:2ms
  • 内存:7044kb
  • [2023-12-29 14:27:34]
  • 提交

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] <= max(v[r], l)) {
				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;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 20
Accepted
time: 1ms
memory: 6484kb

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: -20
Wrong Answer
time: 2ms
memory: 7044kb

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
3
3
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:

wrong answer 38th lines differ - expected: '2', found: '3'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #2:

0%