QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#85868#5686. 种苹果RensheyTL 65ms30056kbC++233.1kb2023-03-08 19:35:012023-03-08 19:35:03

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-08 19:35:03]
  • 评测
  • 测评结果:TL
  • 用时:65ms
  • 内存:30056kb
  • [2023-03-08 19:35:01]
  • 提交

answer

#include <bits/stdc++.h>
#define Getchar() p1 == p2 and (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++
char buf[1 << 21], *p1, *p2;
int read (void)
{
	int x = 0; char c = Getchar(); bool f = c != '-';
	while (c < '0' or c > '9') if ((c = Getchar()) == '-') f = false;
	while (c >= '0' and c <= '9') x = x * 10 + c - 48, c = Getchar();
	return f ? x : -x;
}
const int maxn = 1 << 19, B = 350;
int n, m, siz[maxn], fa[maxn], ch[maxn][2], rev[maxn]; std::vector<int> e[maxn];
long long a[maxn], tag[maxn]; std::vector<long long> g[maxn];
int get (int x) {return ch[fa[x]][1] == x;}
bool isroot (int x) {return ch[fa[x]][0] != x and ch[fa[x]][1] != x;}
void pushup (int x)
{
	siz[x] = siz[ch[x][0]] + siz[ch[x][1]] + 1;
	std::vector<long long>().swap(g[x]);
	if (siz[x] <= B)
		g[x].insert(g[x].end(), g[ch[x][0]].begin(), g[ch[x][0]].end()),
		g[x].insert(g[x].end(), g[ch[x][1]].begin(), g[ch[x][1]].end()),
		std::inplace_merge(g[x].begin(), g[x].begin() + siz[ch[x][0]], g[x].end()),
		g[x].insert(std::lower_bound(g[x].begin(), g[x].end(), a[x]), a[x]);
}
void upd (int u, long long w)
{
	if (u)
	{
		a[u] += w; tag[u] += w;
		if (siz[u] <= B) for (auto &c: g[u]) c += w;
	}
}
void reverse (int x) {if (x) std::swap(ch[x][0], ch[x][1]), rev[x] ^= 1;}
void pushdown (int x)
{
	if (rev[x]) reverse(ch[x][0]), reverse(ch[x][1]), rev[x] = 0;
	if (tag[x]) upd(ch[x][0], tag[x]), upd(ch[x][1], tag[x]), tag[x] = 0;
}
void rotate (int x)
{
	int y = fa[x], z = fa[y], k = get(x);
	fa[x] = z; if (!isroot(y)) ch[z][get(y)] = x;
	fa[ch[x][k ^ 1]] = y; ch[y][k] = ch[x][k ^ 1];
	fa[y] = x; ch[x][k ^ 1] = y; pushup(y); pushup(x);
}
void splay (int x)
{
	static int st[maxn], tp; st[tp = 1] = x;
	for (int y = x; !isroot(y); y = fa[y]) st[++tp] = fa[y];
	while (tp) pushdown(st[tp--]);
	while (!isroot(x))
	{
		int y = fa[x];
		if (!isroot(y)) rotate(get(x) == get(y) ? y : x);
		rotate(x);
	}
}
void access (int u) {for (int v = 0; u; u = fa[v = u]) splay(u), ch[u][1] = v, pushup(u);}
void makeroot (int u) {access(u); splay(u); reverse(u);}
void split (int u, int v) {makeroot(u); access(v); splay(v);}
void link (int u, int v) {split(u, v); fa[u] = v;}
void cut (int u, int v) {split(u, v); ch[v][0] = fa[u] = 0; siz[v] = 1; g[v] = {a[v]};}
int ask (int u, long long w)
{
	if (siz[u] <= B) return g[u].end() - std::lower_bound(g[u].begin(), g[u].end(), w);
	pushdown(u); return (ch[u][0] ? ask(ch[u][0], w) : 0) + (ch[u][1] ? ask(ch[u][1], w) : 0) + (a[u] >= w);
}
void dfs (int u, int fr)
{
	for (int v: e[u]) if (v != fr) fa[v] = u, dfs(v, u), ch[u][1] = v;
	pushup(u);
}
signed main ()
{
	n = read(); m = read();
	for (int i = 1; i <= n; i++) g[i] = {a[i] = read()}, siz[i] = 1;
	for (int i = 1, u, v; i < n; i++) u = read(), v = read(), e[u].push_back(v), e[v].push_back(u);
	dfs(1, 0);
	for (int ans = 0; m--; )
	{
		int o = read(), u = read() ^ ans, v = o ^ 2 ? read() ^ ans : 0, w = read() ^ ans;
		if (o == 1) a[++n] = w, cut(u, v), link(u, n), link(v, n);
		if (o == 2) a[++n] = w, link(u, n);
		if (o == 3) split(u, v), upd(v, w);
		if (o == 4) split(u, v), printf("%d\n", ans = ask(v, w));
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 56ms
memory: 30056kb

input:

5000 5000
-1201801 4507224 -765313 5795451 -126649 -5052948 470601 -5571705 7680665 -2662502 -689392 -3195719 3416253 -1023134 -3112032 3810606 -6975732 712075 257599 -180764 5190759 177433 -6055975 1555412 7768627 3402404 -872471 -1311920 -4231370 117735 3172664 -1502849 -3929398 -90435 6955032 382...

output:

645
0
0
0
57
0
1665
1087
1455
73
1172
1094
0
1739
1202
1290
0
0
0
569
0
1532
0
358
337
437
0
567
1086
12
73
922
1024
183
25
0
0
0
979
4
3
7
162
305
1285
0
1185
0
1263
402
576
1284
0
0
832
908
0
422
1425
1268
12
0
1692
439
0
0
28
0
384
0
0
1079
1257
1149
541
642
133
966
406
0
0
848
1335
431
0
0
363
8...

result:

ok 1020 lines

Test #2:

score: 0
Accepted
time: 58ms
memory: 29996kb

input:

5000 5000
-994733 862196 -2643618 4810652 2000445 -712322 -3955371 2924820 -675771 -6848147 825176 -5612153 4757907 1475460 1043402 1647007 -1015110 2001651 -6330733 2969460 -815149 6241724 136943 2360333 -3204656 5569099 809569 -4081554 -178998 -1363975 -4486956 -1858705 -59824 845830 4381332 17942...

output:

1469
2442
2
0
35
1869
0
353
993
1572
1095
0
12
1458
0
1659
545
0
0
1243
0
0
1410
911
1701
1660
0
0
84
728
0
5
0
1031
2089
1108
524
225
1237
2233
3
43
1324
327
1085
1049
615
61
1840
1892
0
491
989
242
1058
965
625
0
2592
340
36
0
211
0
146
2168
46
0
227
0
0
0
8
2103
1334
0
23
128
0
0
1307
0
0
0
2280
...

result:

ok 962 lines

Test #3:

score: 0
Accepted
time: 65ms
memory: 30000kb

input:

5000 5000
1655881 -6171013 -6563069 6407036 -349214 1212406 2942912 -6594577 2008815 -1128329 -2115530 3807690 2938269 3705147 -5102093 -5658055 -2326373 4349357 -299635 825659 877457 3662152 358404 -892346 4685730 5257128 -6518733 -852709 4390588 -3492594 4680660 -386634 1743811 4770445 1735641 -39...

output:

1263
2159
0
107
4
2257
15
1329
172
0
929
0
1465
260
2106
496
685
80
347
1492
0
2638
409
0
177
0
0
0
5
0
2324
0
179
0
0
0
2122
1322
102
412
300
3
1272
0
6
0
1823
0
13
1739
1459
13
1207
278
0
1261
0
684
0
284
639
69
1700
88
243
1529
1970
0
98
2178
0
978
0
1229
1637
1620
660
835
0
0
214
953
203
674
159...

result:

ok 1055 lines

Test #4:

score: 0
Accepted
time: 63ms
memory: 29984kb

input:

5000 5000
1916330 -1277666 -2692038 -1686680 445447 522240 -9102533 4958411 5497747 -6470449 -1304451 -327692 -3951014 -5481922 -71181 -324109 -2416764 -6133434 -2713206 -6507719 -4562989 3531489 2232499 -1303696 3799685 1596321 4508356 -698966 6244189 -3451377 1146222 -1190263 -1224078 -1867687 256...

output:

0
0
0
1099
0
463
0
1182
25
0
784
0
663
1483
2171
0
1057
0
0
1377
0
0
0
218
0
0
70
906
1524
141
89
992
0
1667
0
308
0
77
6
0
148
0
1364
121
513
162
0
1440
1
1588
290
0
380
0
1517
8
1125
0
1362
592
74
0
83
443
857
0
0
0
10
307
1182
6
2352
15
953
31
966
2
536
2104
872
347
0
1846
185
146
1096
0
368
295
...

result:

ok 1023 lines

Test #5:

score: -100
Time Limit Exceeded

input:

200000 200000
3962736 -7195878 -1853269 5312599 2123365 7028251 2312158 123258 -4443494 -5269322 877331 -616200 927434 -1927540 2943960 -7002528 -5869789 2362131 -2612652 -7859698 2076672 3520022 5147597 17824 -54033 5931665 -8193552 4202786 2726128 1137312 5233018 -580693 2414120 4925088 1642992 35...

output:

47152
78705
47731
29708
99910
0
62117
0
44783
61200
5955
2
46232
0
16545
1271
36509
0
90957
1856
0
84922
27751
45838
0
91943
2373
28623
1118
32482
0
3
63630
57801
81142
0
0
0
9458
0
34391
12206
9510
0
0
1284
92189
98017
23372
7
4783
38278
54827
0
0
0
65641
0
13882
16443
908
0
59951
44221
36623
0
897...

result: