Submission #421824

# Submission time Handle Problem Language Result Execution time Memory
421824 2021-06-09T12:41:10 Z shenxy Food Court (JOI21_foodcourt) C++11
68 / 100
1000 ms 58284 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);
	vector<ii> ops;
	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.push_back(ii(L[i], i));
		if (R[i] != N && T[i] != 3) ops.push_back(ii(R[i] + 1, -i));
	}
	sort(ops.begin(), ops.end());
	for (ii h: ops) {
		int i = 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 2 ms 588 KB Output is correct
4 Correct 4 ms 844 KB Output is correct
5 Correct 1 ms 588 KB Output is correct
6 Correct 2 ms 588 KB Output is correct
7 Correct 3 ms 716 KB Output is correct
8 Correct 3 ms 716 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 588 KB Output is correct
14 Correct 2 ms 716 KB Output is correct
15 Correct 2 ms 588 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 788 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 2 ms 588 KB Output is correct
4 Correct 4 ms 844 KB Output is correct
5 Correct 1 ms 588 KB Output is correct
6 Correct 2 ms 588 KB Output is correct
7 Correct 3 ms 716 KB Output is correct
8 Correct 3 ms 716 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 588 KB Output is correct
14 Correct 2 ms 716 KB Output is correct
15 Correct 2 ms 588 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 788 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 3 ms 716 KB Output is correct
23 Correct 3 ms 716 KB Output is correct
24 Correct 3 ms 716 KB Output is correct
25 Correct 1 ms 588 KB Output is correct
26 Correct 2 ms 716 KB Output is correct
27 Correct 4 ms 716 KB Output is correct
28 Correct 3 ms 716 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 716 KB Output is correct
35 Correct 3 ms 716 KB Output is correct
36 Correct 3 ms 716 KB Output is correct
37 Correct 3 ms 716 KB Output is correct
38 Correct 4 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 156 ms 15272 KB Output is correct
2 Correct 168 ms 15284 KB Output is correct
3 Correct 156 ms 15272 KB Output is correct
4 Correct 160 ms 15276 KB Output is correct
5 Correct 178 ms 15320 KB Output is correct
6 Correct 181 ms 15280 KB Output is correct
7 Correct 44 ms 13980 KB Output is correct
8 Correct 53 ms 14420 KB Output is correct
9 Correct 165 ms 15160 KB Output is correct
10 Correct 168 ms 15328 KB Output is correct
11 Correct 159 ms 15388 KB Output is correct
12 Correct 169 ms 15332 KB Output is correct
13 Correct 132 ms 13752 KB Output is correct
14 Correct 151 ms 15296 KB Output is correct
15 Correct 198 ms 15164 KB Output is correct
16 Correct 193 ms 15288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 851 ms 53028 KB Output is correct
2 Correct 640 ms 43220 KB Output is correct
3 Execution timed out 1022 ms 58284 KB Time limit exceeded
4 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 2 ms 588 KB Output is correct
4 Correct 4 ms 844 KB Output is correct
5 Correct 1 ms 588 KB Output is correct
6 Correct 2 ms 588 KB Output is correct
7 Correct 3 ms 716 KB Output is correct
8 Correct 3 ms 716 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 588 KB Output is correct
14 Correct 2 ms 716 KB Output is correct
15 Correct 2 ms 588 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 788 KB Output is correct
19 Correct 3 ms 716 KB Output is correct
20 Correct 4 ms 716 KB Output is correct
21 Correct 156 ms 15272 KB Output is correct
22 Correct 168 ms 15284 KB Output is correct
23 Correct 156 ms 15272 KB Output is correct
24 Correct 160 ms 15276 KB Output is correct
25 Correct 178 ms 15320 KB Output is correct
26 Correct 181 ms 15280 KB Output is correct
27 Correct 44 ms 13980 KB Output is correct
28 Correct 53 ms 14420 KB Output is correct
29 Correct 165 ms 15160 KB Output is correct
30 Correct 168 ms 15328 KB Output is correct
31 Correct 159 ms 15388 KB Output is correct
32 Correct 169 ms 15332 KB Output is correct
33 Correct 132 ms 13752 KB Output is correct
34 Correct 151 ms 15296 KB Output is correct
35 Correct 198 ms 15164 KB Output is correct
36 Correct 193 ms 15288 KB Output is correct
37 Correct 162 ms 13736 KB Output is correct
38 Correct 154 ms 12204 KB Output is correct
39 Correct 38 ms 12220 KB Output is correct
40 Correct 55 ms 14076 KB Output is correct
41 Correct 165 ms 15264 KB Output is correct
42 Correct 193 ms 15368 KB Output is correct
43 Correct 175 ms 15296 KB Output is correct
44 Correct 209 ms 15256 KB Output is correct
45 Correct 177 ms 15380 KB Output is correct
46 Correct 188 ms 15316 KB Output is correct
47 Correct 70 ms 15036 KB Output is correct
48 Correct 173 ms 15280 KB Output is correct
49 Correct 119 ms 10936 KB Output is correct
50 Correct 140 ms 13100 KB Output is correct
51 Correct 181 ms 15332 KB Output is correct
52 Correct 185 ms 15288 KB Output is correct
53 Correct 157 ms 12128 KB Output is correct
54 Correct 198 ms 15404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 174 ms 13720 KB Output is correct
2 Correct 202 ms 15132 KB Output is correct
3 Correct 215 ms 15320 KB Output is correct
4 Correct 117 ms 11076 KB Output is correct
5 Correct 154 ms 13252 KB Output is correct
6 Correct 192 ms 15348 KB Output is correct
7 Correct 52 ms 13372 KB Output is correct
8 Correct 58 ms 12648 KB Output is correct
9 Correct 90 ms 15016 KB Output is correct
10 Correct 114 ms 10868 KB Output is correct
11 Correct 186 ms 15300 KB Output is correct
12 Correct 195 ms 15236 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 2 ms 588 KB Output is correct
4 Correct 4 ms 844 KB Output is correct
5 Correct 1 ms 588 KB Output is correct
6 Correct 2 ms 588 KB Output is correct
7 Correct 3 ms 716 KB Output is correct
8 Correct 3 ms 716 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 588 KB Output is correct
14 Correct 2 ms 716 KB Output is correct
15 Correct 2 ms 588 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 788 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 3 ms 716 KB Output is correct
23 Correct 3 ms 716 KB Output is correct
24 Correct 3 ms 716 KB Output is correct
25 Correct 1 ms 588 KB Output is correct
26 Correct 2 ms 716 KB Output is correct
27 Correct 4 ms 716 KB Output is correct
28 Correct 3 ms 716 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 716 KB Output is correct
35 Correct 3 ms 716 KB Output is correct
36 Correct 3 ms 716 KB Output is correct
37 Correct 3 ms 716 KB Output is correct
38 Correct 4 ms 716 KB Output is correct
39 Correct 156 ms 15272 KB Output is correct
40 Correct 168 ms 15284 KB Output is correct
41 Correct 156 ms 15272 KB Output is correct
42 Correct 160 ms 15276 KB Output is correct
43 Correct 178 ms 15320 KB Output is correct
44 Correct 181 ms 15280 KB Output is correct
45 Correct 44 ms 13980 KB Output is correct
46 Correct 53 ms 14420 KB Output is correct
47 Correct 165 ms 15160 KB Output is correct
48 Correct 168 ms 15328 KB Output is correct
49 Correct 159 ms 15388 KB Output is correct
50 Correct 169 ms 15332 KB Output is correct
51 Correct 132 ms 13752 KB Output is correct
52 Correct 151 ms 15296 KB Output is correct
53 Correct 198 ms 15164 KB Output is correct
54 Correct 193 ms 15288 KB Output is correct
55 Correct 162 ms 13736 KB Output is correct
56 Correct 154 ms 12204 KB Output is correct
57 Correct 38 ms 12220 KB Output is correct
58 Correct 55 ms 14076 KB Output is correct
59 Correct 165 ms 15264 KB Output is correct
60 Correct 193 ms 15368 KB Output is correct
61 Correct 175 ms 15296 KB Output is correct
62 Correct 209 ms 15256 KB Output is correct
63 Correct 177 ms 15380 KB Output is correct
64 Correct 188 ms 15316 KB Output is correct
65 Correct 70 ms 15036 KB Output is correct
66 Correct 173 ms 15280 KB Output is correct
67 Correct 119 ms 10936 KB Output is correct
68 Correct 140 ms 13100 KB Output is correct
69 Correct 181 ms 15332 KB Output is correct
70 Correct 185 ms 15288 KB Output is correct
71 Correct 157 ms 12128 KB Output is correct
72 Correct 198 ms 15404 KB Output is correct
73 Correct 174 ms 13720 KB Output is correct
74 Correct 202 ms 15132 KB Output is correct
75 Correct 215 ms 15320 KB Output is correct
76 Correct 117 ms 11076 KB Output is correct
77 Correct 154 ms 13252 KB Output is correct
78 Correct 192 ms 15348 KB Output is correct
79 Correct 52 ms 13372 KB Output is correct
80 Correct 58 ms 12648 KB Output is correct
81 Correct 90 ms 15016 KB Output is correct
82 Correct 114 ms 10868 KB Output is correct
83 Correct 186 ms 15300 KB Output is correct
84 Correct 195 ms 15236 KB Output is correct
85 Correct 175 ms 13976 KB Output is correct
86 Correct 181 ms 15272 KB Output is correct
87 Correct 166 ms 13448 KB Output is correct
88 Correct 198 ms 15312 KB Output is correct
89 Correct 110 ms 10436 KB Output is correct
90 Correct 181 ms 15328 KB Output is correct
91 Correct 146 ms 12740 KB Output is correct
92 Correct 133 ms 12084 KB Output is correct
93 Correct 188 ms 15312 KB Output is correct
94 Correct 183 ms 15252 KB Output is correct
95 Correct 179 ms 14980 KB Output is correct
96 Correct 179 ms 15340 KB Output is correct
97 Correct 183 ms 15320 KB Output is correct
98 Correct 160 ms 13240 KB Output is correct
99 Correct 75 ms 14984 KB Output is correct
100 Correct 141 ms 12960 KB Output is correct
101 Correct 165 ms 15280 KB Output is correct
102 Correct 124 ms 15164 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 2 ms 588 KB Output is correct
4 Correct 4 ms 844 KB Output is correct
5 Correct 1 ms 588 KB Output is correct
6 Correct 2 ms 588 KB Output is correct
7 Correct 3 ms 716 KB Output is correct
8 Correct 3 ms 716 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 588 KB Output is correct
14 Correct 2 ms 716 KB Output is correct
15 Correct 2 ms 588 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 788 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 3 ms 716 KB Output is correct
23 Correct 3 ms 716 KB Output is correct
24 Correct 3 ms 716 KB Output is correct
25 Correct 1 ms 588 KB Output is correct
26 Correct 2 ms 716 KB Output is correct
27 Correct 4 ms 716 KB Output is correct
28 Correct 3 ms 716 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 716 KB Output is correct
35 Correct 3 ms 716 KB Output is correct
36 Correct 3 ms 716 KB Output is correct
37 Correct 3 ms 716 KB Output is correct
38 Correct 4 ms 716 KB Output is correct
39 Correct 156 ms 15272 KB Output is correct
40 Correct 168 ms 15284 KB Output is correct
41 Correct 156 ms 15272 KB Output is correct
42 Correct 160 ms 15276 KB Output is correct
43 Correct 178 ms 15320 KB Output is correct
44 Correct 181 ms 15280 KB Output is correct
45 Correct 44 ms 13980 KB Output is correct
46 Correct 53 ms 14420 KB Output is correct
47 Correct 165 ms 15160 KB Output is correct
48 Correct 168 ms 15328 KB Output is correct
49 Correct 159 ms 15388 KB Output is correct
50 Correct 169 ms 15332 KB Output is correct
51 Correct 132 ms 13752 KB Output is correct
52 Correct 151 ms 15296 KB Output is correct
53 Correct 198 ms 15164 KB Output is correct
54 Correct 193 ms 15288 KB Output is correct
55 Correct 851 ms 53028 KB Output is correct
56 Correct 640 ms 43220 KB Output is correct
57 Execution timed out 1022 ms 58284 KB Time limit exceeded
58 Halted 0 ms 0 KB -