QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#293693#4894. 学姐买瓜zyc0704190 0ms0kbC++143.7kb2023-12-29 16:28:482023-12-29 16:28:49

Judging History

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

  • [2023-12-29 16:28:49]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2023-12-29 16:28:48]
  • 提交

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 = o; assert(y < o);
					x = t.ch[x][1];
				}
				else x = t.ch[x][0];
			}
			assert(y >= l);
			t.split(l, y);
			printf("%d\n", t.val[y]);
		}
	}
	return 0;
}

详细

Subtask #1:

score: 0
Runtime Error

Test #1:

score: 0
Runtime Error

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:


result:


Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #2:

0%