Submission #421830

# Submission time Handle Problem Language Result Execution time Memory
421830 2021-06-09T12:46:22 Z shenxy Food Court (JOI21_foodcourt) C++11
68 / 100
1000 ms 59008 KB
#include <cstdio>
#include <algorithm>
#include <vector>
#define m (s+e)/2
using namespace std;
typedef pair<int, int> ii;
int N, M, Q, T[250001], L[250001], R[250001], C[250001], ans[250001];
long long K[250001];
void readInt(int &x) {
	x = 0;
	char c = getchar_unlocked();
	while (c < '0' || c > '9') c = getchar_unlocked();
	while (c >= '0' && c <= '9') {
		x = (x << 3) + (x << 1) + (c - '0');
		c = getchar_unlocked();
	}
}
void readLL(long long &x) {
	x = 0;
	char c = getchar_unlocked();
	while (c < '0' || c > '9') c = getchar_unlocked();
	while (c >= '0' && c <= '9') {
		x = (x << 3) + (x << 1) + (c - '0');
		c = getchar_unlocked();
	}
}
struct seg {
	int s, e;
	long long lazy, v;
	seg *l, *r;
	seg(int _s, int _e) {
		s = _s, e = _e;
		lazy = 0;
		v = 0;
		if (s != e) {
			l = new seg(s, m);
			r = new seg(m + 1, e);
		}
	}
	void prop() {
		if (lazy) {
			v += lazy;
			if (s != e) {
				l -> lazy += lazy;
				r -> lazy += lazy;
			}
			lazy = 0;
		}
	}
	void update(int a, int b, long long dv) {
		if (s != a || e != b) {
			if (a > m) r -> update(a, b, dv);
			else if (b <= m) l -> update(a, b, dv);
			else l -> update(a, m, dv), r -> update(m + 1, b, dv);
			l -> prop(), r -> prop();
			v = min(l -> v, r -> v);
		} else lazy += dv;
	}
	long long query(int a, int b) {
		prop();
		if (s == a && e == b) return v;
		if (a > m) return r -> query(a, b);
		if (b <= m) return l -> query(a, b);
		return min(l -> query(a, m), r -> query(m + 1, b));
	}
	int descend(int i, long long k) {
		prop();
		if (s == e) return s;
		if (m < i && r -> lazy + r -> v < k) return r -> descend(i, k);
		return l -> descend(i, k);
	}
} *r1, *r2;
int main() {
	readInt(N), readInt(M), readInt(Q);
	r1 = new seg(0, Q);
	r2 = new seg(0, Q);
	ii ops[2 * Q];
	int ptr = 0;
	for (int i = 1; i <= Q; ++i) {
		readInt(T[i]);
		if (T[i] == 1) readInt(L[i]), readInt(R[i]), readInt(C[i]), readLL(K[i]);
		else if (T[i] == 2) readInt(L[i]), readInt(R[i]), readLL(K[i]);
		else readInt(L[i]), readLL(K[i]);
		ops[ptr++] = ii(L[i], i);
		if (R[i] != N && T[i] != 3) ops[ptr++] = ii(R[i] + 1, -i);
	}
	sort(ops, ops + ptr);
	for (int h = 0; h < ptr; ++h) {
		int i = ops[h].second;
		if (i < 0 && T[-i] == 1) r1 -> update(-i, Q, -K[-i]), r2 -> update(-i, Q, -K[-i]);
		else if (i < 0 && T[-i] == 2) r1 -> update(-i, Q, K[-i]);
		else if (T[i] == 3) {
			long long curr = r1 -> query(i, i) - r1 -> query(0, i);
			int l = r2 -> descend(i, r2 -> query(i, i) - curr + K[i]);
			if (l == i) ans[i] = 0;
			else ans[i] = C[l + 1];
		} else if (T[i] == 1) r1 -> update(i, Q, K[i]), r2 -> update(i, Q, K[i]);
		else r1 -> update(i, Q, -K[i]);
	}
	for (int i = 1; i <= Q; ++i) {
		if (T[i] == 3) printf("%d\n", ans[i]);
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 588 KB Output is correct
2 Correct 3 ms 716 KB Output is correct
3 Correct 3 ms 588 KB Output is correct
4 Correct 3 ms 716 KB Output is correct
5 Correct 1 ms 716 KB Output is correct
6 Correct 2 ms 716 KB Output is correct
7 Correct 3 ms 716 KB Output is correct
8 Correct 3 ms 808 KB Output is correct
9 Correct 3 ms 716 KB Output is correct
10 Correct 3 ms 716 KB Output is correct
11 Correct 3 ms 716 KB Output is correct
12 Correct 3 ms 716 KB Output is correct
13 Correct 2 ms 680 KB Output is correct
14 Correct 2 ms 808 KB Output is correct
15 Correct 2 ms 552 KB Output is correct
16 Correct 3 ms 716 KB Output is correct
17 Correct 3 ms 716 KB Output is correct
18 Correct 3 ms 716 KB Output is correct
19 Correct 3 ms 716 KB Output is correct
20 Correct 4 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 588 KB Output is correct
2 Correct 3 ms 716 KB Output is correct
3 Correct 3 ms 588 KB Output is correct
4 Correct 3 ms 716 KB Output is correct
5 Correct 1 ms 716 KB Output is correct
6 Correct 2 ms 716 KB Output is correct
7 Correct 3 ms 716 KB Output is correct
8 Correct 3 ms 808 KB Output is correct
9 Correct 3 ms 716 KB Output is correct
10 Correct 3 ms 716 KB Output is correct
11 Correct 3 ms 716 KB Output is correct
12 Correct 3 ms 716 KB Output is correct
13 Correct 2 ms 680 KB Output is correct
14 Correct 2 ms 808 KB Output is correct
15 Correct 2 ms 552 KB Output is correct
16 Correct 3 ms 716 KB Output is correct
17 Correct 3 ms 716 KB Output is correct
18 Correct 3 ms 716 KB Output is correct
19 Correct 3 ms 716 KB Output is correct
20 Correct 4 ms 716 KB Output is correct
21 Correct 3 ms 716 KB Output is correct
22 Correct 4 ms 716 KB Output is correct
23 Correct 3 ms 684 KB Output is correct
24 Correct 4 ms 816 KB Output is correct
25 Correct 1 ms 684 KB Output is correct
26 Correct 3 ms 716 KB Output is correct
27 Correct 3 ms 716 KB Output is correct
28 Correct 3 ms 772 KB Output is correct
29 Correct 3 ms 716 KB Output is correct
30 Correct 3 ms 716 KB Output is correct
31 Correct 3 ms 716 KB Output is correct
32 Correct 3 ms 716 KB Output is correct
33 Correct 2 ms 716 KB Output is correct
34 Correct 2 ms 808 KB Output is correct
35 Correct 3 ms 716 KB Output is correct
36 Correct 3 ms 816 KB Output is correct
37 Correct 3 ms 588 KB Output is correct
38 Correct 4 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 197 ms 15388 KB Output is correct
2 Correct 185 ms 15852 KB Output is correct
3 Correct 148 ms 15772 KB Output is correct
4 Correct 165 ms 15824 KB Output is correct
5 Correct 174 ms 15888 KB Output is correct
6 Correct 178 ms 15808 KB Output is correct
7 Correct 44 ms 14788 KB Output is correct
8 Correct 64 ms 15072 KB Output is correct
9 Correct 150 ms 15712 KB Output is correct
10 Correct 156 ms 15816 KB Output is correct
11 Correct 171 ms 15780 KB Output is correct
12 Correct 161 ms 15820 KB Output is correct
13 Correct 134 ms 14316 KB Output is correct
14 Correct 158 ms 15844 KB Output is correct
15 Correct 224 ms 15688 KB Output is correct
16 Correct 212 ms 15796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 886 ms 53704 KB Output is correct
2 Correct 690 ms 43300 KB Output is correct
3 Correct 936 ms 58544 KB Output is correct
4 Correct 701 ms 42752 KB Output is correct
5 Correct 720 ms 43868 KB Output is correct
6 Execution timed out 1040 ms 59008 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 588 KB Output is correct
2 Correct 3 ms 716 KB Output is correct
3 Correct 3 ms 588 KB Output is correct
4 Correct 3 ms 716 KB Output is correct
5 Correct 1 ms 716 KB Output is correct
6 Correct 2 ms 716 KB Output is correct
7 Correct 3 ms 716 KB Output is correct
8 Correct 3 ms 808 KB Output is correct
9 Correct 3 ms 716 KB Output is correct
10 Correct 3 ms 716 KB Output is correct
11 Correct 3 ms 716 KB Output is correct
12 Correct 3 ms 716 KB Output is correct
13 Correct 2 ms 680 KB Output is correct
14 Correct 2 ms 808 KB Output is correct
15 Correct 2 ms 552 KB Output is correct
16 Correct 3 ms 716 KB Output is correct
17 Correct 3 ms 716 KB Output is correct
18 Correct 3 ms 716 KB Output is correct
19 Correct 3 ms 716 KB Output is correct
20 Correct 4 ms 716 KB Output is correct
21 Correct 197 ms 15388 KB Output is correct
22 Correct 185 ms 15852 KB Output is correct
23 Correct 148 ms 15772 KB Output is correct
24 Correct 165 ms 15824 KB Output is correct
25 Correct 174 ms 15888 KB Output is correct
26 Correct 178 ms 15808 KB Output is correct
27 Correct 44 ms 14788 KB Output is correct
28 Correct 64 ms 15072 KB Output is correct
29 Correct 150 ms 15712 KB Output is correct
30 Correct 156 ms 15816 KB Output is correct
31 Correct 171 ms 15780 KB Output is correct
32 Correct 161 ms 15820 KB Output is correct
33 Correct 134 ms 14316 KB Output is correct
34 Correct 158 ms 15844 KB Output is correct
35 Correct 224 ms 15688 KB Output is correct
36 Correct 212 ms 15796 KB Output is correct
37 Correct 168 ms 14252 KB Output is correct
38 Correct 152 ms 12552 KB Output is correct
39 Correct 39 ms 12912 KB Output is correct
40 Correct 60 ms 14740 KB Output is correct
41 Correct 183 ms 15556 KB Output is correct
42 Correct 176 ms 15676 KB Output is correct
43 Correct 185 ms 15680 KB Output is correct
44 Correct 173 ms 15684 KB Output is correct
45 Correct 182 ms 15696 KB Output is correct
46 Correct 180 ms 15680 KB Output is correct
47 Correct 72 ms 15780 KB Output is correct
48 Correct 164 ms 15688 KB Output is correct
49 Correct 112 ms 11388 KB Output is correct
50 Correct 140 ms 13376 KB Output is correct
51 Correct 216 ms 15716 KB Output is correct
52 Correct 180 ms 15812 KB Output is correct
53 Correct 139 ms 12368 KB Output is correct
54 Correct 194 ms 15680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 164 ms 14196 KB Output is correct
2 Correct 212 ms 15748 KB Output is correct
3 Correct 197 ms 15816 KB Output is correct
4 Correct 121 ms 11332 KB Output is correct
5 Correct 158 ms 13744 KB Output is correct
6 Correct 191 ms 15812 KB Output is correct
7 Correct 52 ms 14064 KB Output is correct
8 Correct 57 ms 13276 KB Output is correct
9 Correct 94 ms 15732 KB Output is correct
10 Correct 118 ms 11068 KB Output is correct
11 Correct 205 ms 15752 KB Output is correct
12 Correct 172 ms 15812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 588 KB Output is correct
2 Correct 3 ms 716 KB Output is correct
3 Correct 3 ms 588 KB Output is correct
4 Correct 3 ms 716 KB Output is correct
5 Correct 1 ms 716 KB Output is correct
6 Correct 2 ms 716 KB Output is correct
7 Correct 3 ms 716 KB Output is correct
8 Correct 3 ms 808 KB Output is correct
9 Correct 3 ms 716 KB Output is correct
10 Correct 3 ms 716 KB Output is correct
11 Correct 3 ms 716 KB Output is correct
12 Correct 3 ms 716 KB Output is correct
13 Correct 2 ms 680 KB Output is correct
14 Correct 2 ms 808 KB Output is correct
15 Correct 2 ms 552 KB Output is correct
16 Correct 3 ms 716 KB Output is correct
17 Correct 3 ms 716 KB Output is correct
18 Correct 3 ms 716 KB Output is correct
19 Correct 3 ms 716 KB Output is correct
20 Correct 4 ms 716 KB Output is correct
21 Correct 3 ms 716 KB Output is correct
22 Correct 4 ms 716 KB Output is correct
23 Correct 3 ms 684 KB Output is correct
24 Correct 4 ms 816 KB Output is correct
25 Correct 1 ms 684 KB Output is correct
26 Correct 3 ms 716 KB Output is correct
27 Correct 3 ms 716 KB Output is correct
28 Correct 3 ms 772 KB Output is correct
29 Correct 3 ms 716 KB Output is correct
30 Correct 3 ms 716 KB Output is correct
31 Correct 3 ms 716 KB Output is correct
32 Correct 3 ms 716 KB Output is correct
33 Correct 2 ms 716 KB Output is correct
34 Correct 2 ms 808 KB Output is correct
35 Correct 3 ms 716 KB Output is correct
36 Correct 3 ms 816 KB Output is correct
37 Correct 3 ms 588 KB Output is correct
38 Correct 4 ms 716 KB Output is correct
39 Correct 197 ms 15388 KB Output is correct
40 Correct 185 ms 15852 KB Output is correct
41 Correct 148 ms 15772 KB Output is correct
42 Correct 165 ms 15824 KB Output is correct
43 Correct 174 ms 15888 KB Output is correct
44 Correct 178 ms 15808 KB Output is correct
45 Correct 44 ms 14788 KB Output is correct
46 Correct 64 ms 15072 KB Output is correct
47 Correct 150 ms 15712 KB Output is correct
48 Correct 156 ms 15816 KB Output is correct
49 Correct 171 ms 15780 KB Output is correct
50 Correct 161 ms 15820 KB Output is correct
51 Correct 134 ms 14316 KB Output is correct
52 Correct 158 ms 15844 KB Output is correct
53 Correct 224 ms 15688 KB Output is correct
54 Correct 212 ms 15796 KB Output is correct
55 Correct 168 ms 14252 KB Output is correct
56 Correct 152 ms 12552 KB Output is correct
57 Correct 39 ms 12912 KB Output is correct
58 Correct 60 ms 14740 KB Output is correct
59 Correct 183 ms 15556 KB Output is correct
60 Correct 176 ms 15676 KB Output is correct
61 Correct 185 ms 15680 KB Output is correct
62 Correct 173 ms 15684 KB Output is correct
63 Correct 182 ms 15696 KB Output is correct
64 Correct 180 ms 15680 KB Output is correct
65 Correct 72 ms 15780 KB Output is correct
66 Correct 164 ms 15688 KB Output is correct
67 Correct 112 ms 11388 KB Output is correct
68 Correct 140 ms 13376 KB Output is correct
69 Correct 216 ms 15716 KB Output is correct
70 Correct 180 ms 15812 KB Output is correct
71 Correct 139 ms 12368 KB Output is correct
72 Correct 194 ms 15680 KB Output is correct
73 Correct 164 ms 14196 KB Output is correct
74 Correct 212 ms 15748 KB Output is correct
75 Correct 197 ms 15816 KB Output is correct
76 Correct 121 ms 11332 KB Output is correct
77 Correct 158 ms 13744 KB Output is correct
78 Correct 191 ms 15812 KB Output is correct
79 Correct 52 ms 14064 KB Output is correct
80 Correct 57 ms 13276 KB Output is correct
81 Correct 94 ms 15732 KB Output is correct
82 Correct 118 ms 11068 KB Output is correct
83 Correct 205 ms 15752 KB Output is correct
84 Correct 172 ms 15812 KB Output is correct
85 Correct 166 ms 14352 KB Output is correct
86 Correct 169 ms 15700 KB Output is correct
87 Correct 156 ms 13792 KB Output is correct
88 Correct 193 ms 15704 KB Output is correct
89 Correct 106 ms 10696 KB Output is correct
90 Correct 180 ms 15680 KB Output is correct
91 Correct 139 ms 13084 KB Output is correct
92 Correct 156 ms 12456 KB Output is correct
93 Correct 209 ms 15688 KB Output is correct
94 Correct 207 ms 15624 KB Output is correct
95 Correct 195 ms 15424 KB Output is correct
96 Correct 183 ms 15684 KB Output is correct
97 Correct 177 ms 15684 KB Output is correct
98 Correct 156 ms 13540 KB Output is correct
99 Correct 76 ms 15680 KB Output is correct
100 Correct 133 ms 13468 KB Output is correct
101 Correct 165 ms 15744 KB Output is correct
102 Correct 125 ms 15560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 588 KB Output is correct
2 Correct 3 ms 716 KB Output is correct
3 Correct 3 ms 588 KB Output is correct
4 Correct 3 ms 716 KB Output is correct
5 Correct 1 ms 716 KB Output is correct
6 Correct 2 ms 716 KB Output is correct
7 Correct 3 ms 716 KB Output is correct
8 Correct 3 ms 808 KB Output is correct
9 Correct 3 ms 716 KB Output is correct
10 Correct 3 ms 716 KB Output is correct
11 Correct 3 ms 716 KB Output is correct
12 Correct 3 ms 716 KB Output is correct
13 Correct 2 ms 680 KB Output is correct
14 Correct 2 ms 808 KB Output is correct
15 Correct 2 ms 552 KB Output is correct
16 Correct 3 ms 716 KB Output is correct
17 Correct 3 ms 716 KB Output is correct
18 Correct 3 ms 716 KB Output is correct
19 Correct 3 ms 716 KB Output is correct
20 Correct 4 ms 716 KB Output is correct
21 Correct 3 ms 716 KB Output is correct
22 Correct 4 ms 716 KB Output is correct
23 Correct 3 ms 684 KB Output is correct
24 Correct 4 ms 816 KB Output is correct
25 Correct 1 ms 684 KB Output is correct
26 Correct 3 ms 716 KB Output is correct
27 Correct 3 ms 716 KB Output is correct
28 Correct 3 ms 772 KB Output is correct
29 Correct 3 ms 716 KB Output is correct
30 Correct 3 ms 716 KB Output is correct
31 Correct 3 ms 716 KB Output is correct
32 Correct 3 ms 716 KB Output is correct
33 Correct 2 ms 716 KB Output is correct
34 Correct 2 ms 808 KB Output is correct
35 Correct 3 ms 716 KB Output is correct
36 Correct 3 ms 816 KB Output is correct
37 Correct 3 ms 588 KB Output is correct
38 Correct 4 ms 716 KB Output is correct
39 Correct 197 ms 15388 KB Output is correct
40 Correct 185 ms 15852 KB Output is correct
41 Correct 148 ms 15772 KB Output is correct
42 Correct 165 ms 15824 KB Output is correct
43 Correct 174 ms 15888 KB Output is correct
44 Correct 178 ms 15808 KB Output is correct
45 Correct 44 ms 14788 KB Output is correct
46 Correct 64 ms 15072 KB Output is correct
47 Correct 150 ms 15712 KB Output is correct
48 Correct 156 ms 15816 KB Output is correct
49 Correct 171 ms 15780 KB Output is correct
50 Correct 161 ms 15820 KB Output is correct
51 Correct 134 ms 14316 KB Output is correct
52 Correct 158 ms 15844 KB Output is correct
53 Correct 224 ms 15688 KB Output is correct
54 Correct 212 ms 15796 KB Output is correct
55 Correct 886 ms 53704 KB Output is correct
56 Correct 690 ms 43300 KB Output is correct
57 Correct 936 ms 58544 KB Output is correct
58 Correct 701 ms 42752 KB Output is correct
59 Correct 720 ms 43868 KB Output is correct
60 Execution timed out 1040 ms 59008 KB Time limit exceeded
61 Halted 0 ms 0 KB -