Submission #872354

# Submission time Handle Problem Language Result Execution time Memory
872354 2023-11-13T00:22:28 Z bemiko8984 Bitaro, who Leaps through Time (JOI19_timeleap) C++14
100 / 100
280 ms 48464 KB
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
const int maxn = 3e5 + 5;
 
inline int gi()
{
	char c = getchar();
	while (c < '0' || c > '9') c = getchar();
	int sum = 0;
	while ('0' <= c && c <= '9') sum = sum * 10 + c - 48, c = getchar();
	return sum;
}
 
int n, q;
int l[maxn], r[maxn], op[maxn], a[maxn], b[maxn], c[maxn], d[maxn];
ll ans[maxn];
 
struct node
{
	int op, x, y;
	ll c;
} seq[maxn], val[maxn << 2];
 
node operator + (const node &a, const node &b)
{
	if (a.op) {
		if (b.op) return (node) {1, a.x, b.y, a.c + b.c + max(0, a.y - b.x)};
		else return (node) {1, a.x, max(b.x, min(b.y, a.y)), a.c + max(0, a.y - b.y)};
	} else {
		if (b.op) return (node) {1, min(a.y, max(a.x, b.x)), b.y, b.c + max(0, a.x - b.x)};
		else if (a.y < b.x) return (node) {1, a.y, b.x, 0};
		else if (a.x > b.y) return (node) {1, a.x, b.y, a.x - b.y};
		else return (node) {0, max(a.x, b.x), min(a.y, b.y), 0};
	}
}
 
#define mid ((l + r) >> 1)
#define lch (s << 1)
#define rch (s << 1 | 1)
 
void build(int s, int l, int r)
{
	if (l == r) return val[s] = seq[l], void();
	build(lch, l, mid);
	build(rch, mid + 1, r);
	val[s] = val[lch] + val[rch];
}
 
void modify(int s, int l, int r, int p, node v)
{
	if (l == r) return val[s] = v, void();
	if (p <= mid) modify(lch, l, mid, p, v);
	if (p >= mid + 1) modify(rch, mid + 1, r, p, v);
	val[s] = val[lch] + val[rch];
}
 
node query(int s, int l, int r, int ql, int qr)
{
	if (ql <= l && r <= qr) return val[s];
	if (qr <= mid) return query(lch, l, mid, ql, qr);
	else if (ql >= mid + 1) return query(rch, mid + 1, r, ql, qr);
	else return query(lch, l, mid, ql, qr) + query(rch, mid + 1, r, ql, qr);
}
 
void reverse()
{
	reverse(l + 1, l + n);
	reverse(r + 1, r + n);
	for (int i = 1; i <= q; ++i)
		if (op[i] == 1) a[i] = n - a[i];
		else a[i] = n + 1 - a[i], c[i] = n + 1 - c[i];
}
 
void solve()
{
	for (int i = 1; i < n; ++i) seq[i] = (node) {0, l[i] - i, r[i] - i - 1, 0};
	build(1, 1, n - 1);
	for (int i = 1; i <= q; ++i)
		if (op[i] == 1) modify(1, 1, n - 1, a[i], (node) {0, b[i] - a[i], c[i] - a[i] - 1, 0});
		else if (a[i] == c[i]) ans[i] = max(0, b[i] - d[i]);
		else if (a[i] < c[i]) ans[i] = ((node) {0, b[i] - a[i], b[i] - a[i], 0} + query(1, 1, n - 1, a[i], c[i] - 1) + (node) {0, (int)-1e9, d[i] - c[i], 0}).c;
}
 
int main()
{
	n = gi(); q = gi();
	if (n == 1) {
		for (int i = 1; i <= q; ++i) {
			op[i] = gi(), a[i] = gi(), b[i] = gi(), c[i] = gi(), d[i] = op[i] == 2 ? gi() : 0;
			if (op[i] == 2) printf("%d\n", max(0, b[i] - d[i]));
		}
		return 0;
	}
	for (int i = 1; i < n; ++i) l[i] = gi(), r[i] = gi();
	for (int i = 1; i <= q; ++i) op[i] = gi(), a[i] = gi(), b[i] = gi(), c[i] = gi(), d[i] = op[i] == 2 ? gi() : 0;
 
	solve();
	reverse();
	solve();
 
	for (int i = 1; i <= q; ++i) if (op[i] == 2) printf("%lld\n", ans[i]);
	
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 12636 KB Output is correct
2 Correct 1 ms 12636 KB Output is correct
3 Correct 2 ms 12636 KB Output is correct
4 Correct 2 ms 12636 KB Output is correct
5 Correct 1 ms 12636 KB Output is correct
6 Correct 1 ms 12636 KB Output is correct
7 Correct 2 ms 12632 KB Output is correct
8 Correct 2 ms 12636 KB Output is correct
9 Correct 1 ms 12636 KB Output is correct
10 Correct 2 ms 12636 KB Output is correct
11 Correct 2 ms 12636 KB Output is correct
12 Correct 2 ms 12636 KB Output is correct
13 Correct 2 ms 12636 KB Output is correct
14 Correct 2 ms 12636 KB Output is correct
15 Correct 2 ms 12636 KB Output is correct
16 Correct 2 ms 12636 KB Output is correct
17 Correct 2 ms 12636 KB Output is correct
18 Correct 2 ms 12636 KB Output is correct
19 Correct 2 ms 12632 KB Output is correct
20 Correct 2 ms 12636 KB Output is correct
21 Correct 2 ms 12632 KB Output is correct
22 Correct 2 ms 12636 KB Output is correct
23 Correct 2 ms 12636 KB Output is correct
24 Correct 3 ms 12632 KB Output is correct
25 Correct 2 ms 12636 KB Output is correct
26 Correct 2 ms 12636 KB Output is correct
27 Correct 2 ms 12636 KB Output is correct
28 Correct 2 ms 12636 KB Output is correct
29 Correct 2 ms 12636 KB Output is correct
30 Correct 2 ms 12740 KB Output is correct
31 Correct 2 ms 12636 KB Output is correct
32 Correct 2 ms 12636 KB Output is correct
33 Correct 2 ms 12636 KB Output is correct
34 Correct 2 ms 12636 KB Output is correct
35 Correct 2 ms 12636 KB Output is correct
36 Correct 2 ms 12636 KB Output is correct
37 Correct 2 ms 12636 KB Output is correct
38 Correct 2 ms 12804 KB Output is correct
39 Correct 2 ms 12636 KB Output is correct
40 Correct 2 ms 12636 KB Output is correct
41 Correct 1 ms 6596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 213 ms 48148 KB Output is correct
2 Correct 214 ms 35648 KB Output is correct
3 Correct 214 ms 35788 KB Output is correct
4 Correct 210 ms 35924 KB Output is correct
5 Correct 218 ms 48212 KB Output is correct
6 Correct 201 ms 48132 KB Output is correct
7 Correct 213 ms 48212 KB Output is correct
8 Correct 226 ms 48464 KB Output is correct
9 Correct 205 ms 35920 KB Output is correct
10 Correct 213 ms 48156 KB Output is correct
11 Correct 221 ms 48148 KB Output is correct
12 Correct 214 ms 48212 KB Output is correct
13 Correct 230 ms 48248 KB Output is correct
14 Correct 1 ms 6488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 12636 KB Output is correct
2 Correct 1 ms 12636 KB Output is correct
3 Correct 2 ms 12636 KB Output is correct
4 Correct 2 ms 12636 KB Output is correct
5 Correct 1 ms 12636 KB Output is correct
6 Correct 1 ms 12636 KB Output is correct
7 Correct 2 ms 12632 KB Output is correct
8 Correct 2 ms 12636 KB Output is correct
9 Correct 1 ms 12636 KB Output is correct
10 Correct 2 ms 12636 KB Output is correct
11 Correct 2 ms 12636 KB Output is correct
12 Correct 2 ms 12636 KB Output is correct
13 Correct 2 ms 12636 KB Output is correct
14 Correct 2 ms 12636 KB Output is correct
15 Correct 2 ms 12636 KB Output is correct
16 Correct 2 ms 12636 KB Output is correct
17 Correct 2 ms 12636 KB Output is correct
18 Correct 2 ms 12636 KB Output is correct
19 Correct 2 ms 12632 KB Output is correct
20 Correct 2 ms 12636 KB Output is correct
21 Correct 2 ms 12632 KB Output is correct
22 Correct 2 ms 12636 KB Output is correct
23 Correct 2 ms 12636 KB Output is correct
24 Correct 3 ms 12632 KB Output is correct
25 Correct 2 ms 12636 KB Output is correct
26 Correct 2 ms 12636 KB Output is correct
27 Correct 2 ms 12636 KB Output is correct
28 Correct 2 ms 12636 KB Output is correct
29 Correct 2 ms 12636 KB Output is correct
30 Correct 2 ms 12740 KB Output is correct
31 Correct 2 ms 12636 KB Output is correct
32 Correct 2 ms 12636 KB Output is correct
33 Correct 2 ms 12636 KB Output is correct
34 Correct 2 ms 12636 KB Output is correct
35 Correct 2 ms 12636 KB Output is correct
36 Correct 2 ms 12636 KB Output is correct
37 Correct 2 ms 12636 KB Output is correct
38 Correct 2 ms 12804 KB Output is correct
39 Correct 2 ms 12636 KB Output is correct
40 Correct 2 ms 12636 KB Output is correct
41 Correct 1 ms 6596 KB Output is correct
42 Correct 213 ms 48148 KB Output is correct
43 Correct 214 ms 35648 KB Output is correct
44 Correct 214 ms 35788 KB Output is correct
45 Correct 210 ms 35924 KB Output is correct
46 Correct 218 ms 48212 KB Output is correct
47 Correct 201 ms 48132 KB Output is correct
48 Correct 213 ms 48212 KB Output is correct
49 Correct 226 ms 48464 KB Output is correct
50 Correct 205 ms 35920 KB Output is correct
51 Correct 213 ms 48156 KB Output is correct
52 Correct 221 ms 48148 KB Output is correct
53 Correct 214 ms 48212 KB Output is correct
54 Correct 230 ms 48248 KB Output is correct
55 Correct 1 ms 6488 KB Output is correct
56 Correct 229 ms 46116 KB Output is correct
57 Correct 230 ms 33880 KB Output is correct
58 Correct 236 ms 46164 KB Output is correct
59 Correct 235 ms 46160 KB Output is correct
60 Correct 223 ms 33732 KB Output is correct
61 Correct 238 ms 46184 KB Output is correct
62 Correct 248 ms 46056 KB Output is correct
63 Correct 233 ms 46164 KB Output is correct
64 Correct 238 ms 46172 KB Output is correct
65 Correct 232 ms 46132 KB Output is correct
66 Correct 225 ms 46160 KB Output is correct
67 Correct 236 ms 46168 KB Output is correct
68 Correct 217 ms 46168 KB Output is correct
69 Correct 280 ms 46196 KB Output is correct
70 Correct 217 ms 33796 KB Output is correct
71 Correct 214 ms 33620 KB Output is correct
72 Correct 241 ms 46160 KB Output is correct
73 Correct 234 ms 46164 KB Output is correct
74 Correct 236 ms 46164 KB Output is correct
75 Correct 236 ms 46196 KB Output is correct
76 Correct 252 ms 46164 KB Output is correct
77 Correct 1 ms 6488 KB Output is correct