1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
#define int long long
#define db double
#define ls(x) tr[x].ls
#define rs(x) tr[x].rs
const int MAXN = 2e6 + 5;
int n, m, tmp, cnt, fa[MAXN], d[MAXN], rts[MAXN];
struct node
{
int op, x, y;
} q[MAXN];
struct tree
{
int ls, rs, num;
bool tag;
db val;
} tr[MAXN * 20];
int rk(int x)
{
return lower_bound(d + 1, d + 1 + n, x) - d;
}
int find(int x)
{
// 略
}
void pushup(int rt)
{
tr[rt].num = tr[ls(rt)].num + tr[rs(rt)].num;
tr[rt].val = tr[ls(rt)].val + tr[rs(rt)].val;
}
void pushdown(int rt)
{
if (tr[rt].tag)
{
tr[rt].tag = 0;
tr[ls(rt)].num = tr[ls(rt)].val = 0, tr[ls(rt)].tag = 1;
tr[rs(rt)].num = tr[rs(rt)].val = 0, tr[rs(rt)].tag = 1;
}
}
void update(int &rt, int l, int r, int k, int x, db y)
{
// 略
}
void merge(int &rt1, int rt2, int l, int r)
{
// 略
}
int query(int rt, int l, int r, int lf, int rg)
{
// 略
}
void clean(int rt, int l, int r, int lf, int rg)
{
if (!rt || rg < lf)
return;
if (lf <= l && rg >= r)
{
tr[rt].num = tr[rt].val = 0, tr[rt].tag = 1;
return;
}
int mid = (l + r) >> 1;
if (lf <= mid)
clean(ls(rt), l, mid, lf, rg);
if (rg > mid)
clean(rs(rt), mid + 1, r, lf, rg);
pushup(rt);
return;
}
int ask(int rt, int l, int r, int k)
{
// 略
}
signed main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> m;
for (int i = 1; i <= m; i++)
{
int op, x, y = 0;
cin >> op >> x;
if (op != 1 && op != 7)
cin >> y;
q[i] = (node){op, x, y};
if (op == 3 || op == 4)
d[++n] = y;
if (op == 1)
d[++n] = x;
}
sort(d + 1, d + 1 + n);
n = unique(d + 1, d + 1 + n) - d - 1;
for (int i = 1; i <= m; i++)
{
int op = q[i].op, x = q[i].x, y = q[i].y;
if (op == 1)
update(rts[++tmp], 1, n, rk(x), 1, (db)log(x)), fa[tmp] = tmp;
if (op == 2)
{
int fx = find(x), fy = find(y);
if (fx != fy)
{
fa[fy] = fx;
merge(rts[fx], rts[fy], 1, n);
}
}
if (op == 3)
{
int fx = find(x), k = rk(y);
int sum = query(rts[fx], 1, n, 1, k - 1);
clean(rts[fx], 1, n, 1, k - 1);
update(rts[fx], 1, n, k, sum, sum * log(y));
}
if (op == 4)
{
int fx = find(x), k = rk(y);
int sum = query(rts[fx], 1, n, k + 1, n);
clean(rts[fx], 1, n, k + 1, n);
update(rts[fx], 1, n, k, sum, sum * log(y));
}
if (op == 5)
printf("%lld\n", ask(rts[find(x)], 1, n, y));
if (op == 6)
puts(tr[rts[find(x)]].val > tr[rts[find(y)]].val ? "1" : "0");
if (op == 7)
printf("%lld\n", tr[rts[find(x)]].num);
}
return 0;
}
|