답안 #421819

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
421819 2021-06-09T12:37:21 Z shenxy 푸드 코트 (JOI21_foodcourt) C++11
68 / 100
1000 ms 52928 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];
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() {
	scanf("%d %d %d", &N, &M, &Q);
	r1 = new seg(0, Q);
	r2 = new seg(0, Q);
	vector<ii> ops;
	for (int i = 1; i <= Q; ++i) {
		scanf("%d", &T[i]);
		if (T[i] == 1) scanf("%d %d %d %lld", &L[i], &R[i], &C[i], &K[i]);
		else if (T[i] == 2) scanf("%d %d %lld", &L[i], &R[i], &K[i]);
		else scanf("%d %lld", &L[i], &K[i]), R[i] = L[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;
}

Compilation message

foodcourt.cpp: In function 'int main()':
foodcourt.cpp:56:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |  scanf("%d %d %d", &N, &M, &Q);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
foodcourt.cpp:61:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |   scanf("%d", &T[i]);
      |   ~~~~~^~~~~~~~~~~~~
foodcourt.cpp:62:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |   if (T[i] == 1) scanf("%d %d %d %lld", &L[i], &R[i], &C[i], &K[i]);
      |                  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
foodcourt.cpp:63:28: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |   else if (T[i] == 2) scanf("%d %d %lld", &L[i], &R[i], &K[i]);
      |                       ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
foodcourt.cpp:64:13: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |   else scanf("%d %lld", &L[i], &K[i]), R[i] = L[i];
      |        ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 588 KB Output is correct
2 Correct 5 ms 716 KB Output is correct
3 Correct 3 ms 588 KB Output is correct
4 Correct 5 ms 716 KB Output is correct
5 Correct 3 ms 588 KB Output is correct
6 Correct 3 ms 588 KB Output is correct
7 Correct 4 ms 716 KB Output is correct
8 Correct 5 ms 768 KB Output is correct
9 Correct 6 ms 716 KB Output is correct
10 Correct 5 ms 808 KB Output is correct
11 Correct 4 ms 808 KB Output is correct
12 Correct 4 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 3 ms 588 KB Output is correct
16 Correct 4 ms 716 KB Output is correct
17 Correct 4 ms 740 KB Output is correct
18 Correct 4 ms 716 KB Output is correct
19 Correct 4 ms 716 KB Output is correct
20 Correct 4 ms 716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 588 KB Output is correct
2 Correct 5 ms 716 KB Output is correct
3 Correct 3 ms 588 KB Output is correct
4 Correct 5 ms 716 KB Output is correct
5 Correct 3 ms 588 KB Output is correct
6 Correct 3 ms 588 KB Output is correct
7 Correct 4 ms 716 KB Output is correct
8 Correct 5 ms 768 KB Output is correct
9 Correct 6 ms 716 KB Output is correct
10 Correct 5 ms 808 KB Output is correct
11 Correct 4 ms 808 KB Output is correct
12 Correct 4 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 3 ms 588 KB Output is correct
16 Correct 4 ms 716 KB Output is correct
17 Correct 4 ms 740 KB Output is correct
18 Correct 4 ms 716 KB Output is correct
19 Correct 4 ms 716 KB Output is correct
20 Correct 4 ms 716 KB Output is correct
21 Correct 5 ms 836 KB Output is correct
22 Correct 5 ms 716 KB Output is correct
23 Correct 5 ms 716 KB Output is correct
24 Correct 4 ms 804 KB Output is correct
25 Correct 3 ms 588 KB Output is correct
26 Correct 3 ms 716 KB Output is correct
27 Correct 4 ms 804 KB Output is correct
28 Correct 6 ms 716 KB Output is correct
29 Correct 5 ms 800 KB Output is correct
30 Correct 5 ms 716 KB Output is correct
31 Correct 4 ms 716 KB Output is correct
32 Correct 6 ms 716 KB Output is correct
33 Correct 3 ms 716 KB Output is correct
34 Correct 3 ms 716 KB Output is correct
35 Correct 3 ms 748 KB Output is correct
36 Correct 5 ms 716 KB Output is correct
37 Correct 3 ms 588 KB Output is correct
38 Correct 5 ms 804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 236 ms 15280 KB Output is correct
2 Correct 250 ms 15324 KB Output is correct
3 Correct 206 ms 15324 KB Output is correct
4 Correct 249 ms 15268 KB Output is correct
5 Correct 211 ms 15316 KB Output is correct
6 Correct 225 ms 15288 KB Output is correct
7 Correct 93 ms 13904 KB Output is correct
8 Correct 80 ms 14348 KB Output is correct
9 Correct 214 ms 15212 KB Output is correct
10 Correct 201 ms 15312 KB Output is correct
11 Correct 220 ms 15284 KB Output is correct
12 Correct 200 ms 15316 KB Output is correct
13 Correct 164 ms 13776 KB Output is correct
14 Correct 224 ms 15280 KB Output is correct
15 Correct 266 ms 15200 KB Output is correct
16 Correct 274 ms 15368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1075 ms 52928 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 588 KB Output is correct
2 Correct 5 ms 716 KB Output is correct
3 Correct 3 ms 588 KB Output is correct
4 Correct 5 ms 716 KB Output is correct
5 Correct 3 ms 588 KB Output is correct
6 Correct 3 ms 588 KB Output is correct
7 Correct 4 ms 716 KB Output is correct
8 Correct 5 ms 768 KB Output is correct
9 Correct 6 ms 716 KB Output is correct
10 Correct 5 ms 808 KB Output is correct
11 Correct 4 ms 808 KB Output is correct
12 Correct 4 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 3 ms 588 KB Output is correct
16 Correct 4 ms 716 KB Output is correct
17 Correct 4 ms 740 KB Output is correct
18 Correct 4 ms 716 KB Output is correct
19 Correct 4 ms 716 KB Output is correct
20 Correct 4 ms 716 KB Output is correct
21 Correct 236 ms 15280 KB Output is correct
22 Correct 250 ms 15324 KB Output is correct
23 Correct 206 ms 15324 KB Output is correct
24 Correct 249 ms 15268 KB Output is correct
25 Correct 211 ms 15316 KB Output is correct
26 Correct 225 ms 15288 KB Output is correct
27 Correct 93 ms 13904 KB Output is correct
28 Correct 80 ms 14348 KB Output is correct
29 Correct 214 ms 15212 KB Output is correct
30 Correct 201 ms 15312 KB Output is correct
31 Correct 220 ms 15284 KB Output is correct
32 Correct 200 ms 15316 KB Output is correct
33 Correct 164 ms 13776 KB Output is correct
34 Correct 224 ms 15280 KB Output is correct
35 Correct 266 ms 15200 KB Output is correct
36 Correct 274 ms 15368 KB Output is correct
37 Correct 183 ms 13864 KB Output is correct
38 Correct 190 ms 12292 KB Output is correct
39 Correct 58 ms 12348 KB Output is correct
40 Correct 78 ms 14132 KB Output is correct
41 Correct 204 ms 15320 KB Output is correct
42 Correct 223 ms 15444 KB Output is correct
43 Correct 244 ms 15456 KB Output is correct
44 Correct 253 ms 15412 KB Output is correct
45 Correct 216 ms 15452 KB Output is correct
46 Correct 202 ms 15504 KB Output is correct
47 Correct 99 ms 15060 KB Output is correct
48 Correct 224 ms 15408 KB Output is correct
49 Correct 132 ms 11064 KB Output is correct
50 Correct 175 ms 13112 KB Output is correct
51 Correct 205 ms 15460 KB Output is correct
52 Correct 213 ms 15460 KB Output is correct
53 Correct 204 ms 12320 KB Output is correct
54 Correct 217 ms 15488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 189 ms 13696 KB Output is correct
2 Correct 219 ms 15160 KB Output is correct
3 Correct 244 ms 15232 KB Output is correct
4 Correct 157 ms 11196 KB Output is correct
5 Correct 210 ms 13508 KB Output is correct
6 Correct 234 ms 15460 KB Output is correct
7 Correct 77 ms 13472 KB Output is correct
8 Correct 81 ms 12736 KB Output is correct
9 Correct 122 ms 15216 KB Output is correct
10 Correct 137 ms 10944 KB Output is correct
11 Correct 249 ms 15388 KB Output is correct
12 Correct 221 ms 15440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 588 KB Output is correct
2 Correct 5 ms 716 KB Output is correct
3 Correct 3 ms 588 KB Output is correct
4 Correct 5 ms 716 KB Output is correct
5 Correct 3 ms 588 KB Output is correct
6 Correct 3 ms 588 KB Output is correct
7 Correct 4 ms 716 KB Output is correct
8 Correct 5 ms 768 KB Output is correct
9 Correct 6 ms 716 KB Output is correct
10 Correct 5 ms 808 KB Output is correct
11 Correct 4 ms 808 KB Output is correct
12 Correct 4 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 3 ms 588 KB Output is correct
16 Correct 4 ms 716 KB Output is correct
17 Correct 4 ms 740 KB Output is correct
18 Correct 4 ms 716 KB Output is correct
19 Correct 4 ms 716 KB Output is correct
20 Correct 4 ms 716 KB Output is correct
21 Correct 5 ms 836 KB Output is correct
22 Correct 5 ms 716 KB Output is correct
23 Correct 5 ms 716 KB Output is correct
24 Correct 4 ms 804 KB Output is correct
25 Correct 3 ms 588 KB Output is correct
26 Correct 3 ms 716 KB Output is correct
27 Correct 4 ms 804 KB Output is correct
28 Correct 6 ms 716 KB Output is correct
29 Correct 5 ms 800 KB Output is correct
30 Correct 5 ms 716 KB Output is correct
31 Correct 4 ms 716 KB Output is correct
32 Correct 6 ms 716 KB Output is correct
33 Correct 3 ms 716 KB Output is correct
34 Correct 3 ms 716 KB Output is correct
35 Correct 3 ms 748 KB Output is correct
36 Correct 5 ms 716 KB Output is correct
37 Correct 3 ms 588 KB Output is correct
38 Correct 5 ms 804 KB Output is correct
39 Correct 236 ms 15280 KB Output is correct
40 Correct 250 ms 15324 KB Output is correct
41 Correct 206 ms 15324 KB Output is correct
42 Correct 249 ms 15268 KB Output is correct
43 Correct 211 ms 15316 KB Output is correct
44 Correct 225 ms 15288 KB Output is correct
45 Correct 93 ms 13904 KB Output is correct
46 Correct 80 ms 14348 KB Output is correct
47 Correct 214 ms 15212 KB Output is correct
48 Correct 201 ms 15312 KB Output is correct
49 Correct 220 ms 15284 KB Output is correct
50 Correct 200 ms 15316 KB Output is correct
51 Correct 164 ms 13776 KB Output is correct
52 Correct 224 ms 15280 KB Output is correct
53 Correct 266 ms 15200 KB Output is correct
54 Correct 274 ms 15368 KB Output is correct
55 Correct 183 ms 13864 KB Output is correct
56 Correct 190 ms 12292 KB Output is correct
57 Correct 58 ms 12348 KB Output is correct
58 Correct 78 ms 14132 KB Output is correct
59 Correct 204 ms 15320 KB Output is correct
60 Correct 223 ms 15444 KB Output is correct
61 Correct 244 ms 15456 KB Output is correct
62 Correct 253 ms 15412 KB Output is correct
63 Correct 216 ms 15452 KB Output is correct
64 Correct 202 ms 15504 KB Output is correct
65 Correct 99 ms 15060 KB Output is correct
66 Correct 224 ms 15408 KB Output is correct
67 Correct 132 ms 11064 KB Output is correct
68 Correct 175 ms 13112 KB Output is correct
69 Correct 205 ms 15460 KB Output is correct
70 Correct 213 ms 15460 KB Output is correct
71 Correct 204 ms 12320 KB Output is correct
72 Correct 217 ms 15488 KB Output is correct
73 Correct 189 ms 13696 KB Output is correct
74 Correct 219 ms 15160 KB Output is correct
75 Correct 244 ms 15232 KB Output is correct
76 Correct 157 ms 11196 KB Output is correct
77 Correct 210 ms 13508 KB Output is correct
78 Correct 234 ms 15460 KB Output is correct
79 Correct 77 ms 13472 KB Output is correct
80 Correct 81 ms 12736 KB Output is correct
81 Correct 122 ms 15216 KB Output is correct
82 Correct 137 ms 10944 KB Output is correct
83 Correct 249 ms 15388 KB Output is correct
84 Correct 221 ms 15440 KB Output is correct
85 Correct 205 ms 14128 KB Output is correct
86 Correct 202 ms 15404 KB Output is correct
87 Correct 190 ms 13628 KB Output is correct
88 Correct 230 ms 15520 KB Output is correct
89 Correct 123 ms 10556 KB Output is correct
90 Correct 232 ms 15564 KB Output is correct
91 Correct 190 ms 12860 KB Output is correct
92 Correct 155 ms 12156 KB Output is correct
93 Correct 230 ms 15456 KB Output is correct
94 Correct 219 ms 15372 KB Output is correct
95 Correct 210 ms 15112 KB Output is correct
96 Correct 237 ms 15416 KB Output is correct
97 Correct 240 ms 15444 KB Output is correct
98 Correct 183 ms 13328 KB Output is correct
99 Correct 103 ms 15104 KB Output is correct
100 Correct 153 ms 13284 KB Output is correct
101 Correct 192 ms 15468 KB Output is correct
102 Correct 195 ms 15320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 588 KB Output is correct
2 Correct 5 ms 716 KB Output is correct
3 Correct 3 ms 588 KB Output is correct
4 Correct 5 ms 716 KB Output is correct
5 Correct 3 ms 588 KB Output is correct
6 Correct 3 ms 588 KB Output is correct
7 Correct 4 ms 716 KB Output is correct
8 Correct 5 ms 768 KB Output is correct
9 Correct 6 ms 716 KB Output is correct
10 Correct 5 ms 808 KB Output is correct
11 Correct 4 ms 808 KB Output is correct
12 Correct 4 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 3 ms 588 KB Output is correct
16 Correct 4 ms 716 KB Output is correct
17 Correct 4 ms 740 KB Output is correct
18 Correct 4 ms 716 KB Output is correct
19 Correct 4 ms 716 KB Output is correct
20 Correct 4 ms 716 KB Output is correct
21 Correct 5 ms 836 KB Output is correct
22 Correct 5 ms 716 KB Output is correct
23 Correct 5 ms 716 KB Output is correct
24 Correct 4 ms 804 KB Output is correct
25 Correct 3 ms 588 KB Output is correct
26 Correct 3 ms 716 KB Output is correct
27 Correct 4 ms 804 KB Output is correct
28 Correct 6 ms 716 KB Output is correct
29 Correct 5 ms 800 KB Output is correct
30 Correct 5 ms 716 KB Output is correct
31 Correct 4 ms 716 KB Output is correct
32 Correct 6 ms 716 KB Output is correct
33 Correct 3 ms 716 KB Output is correct
34 Correct 3 ms 716 KB Output is correct
35 Correct 3 ms 748 KB Output is correct
36 Correct 5 ms 716 KB Output is correct
37 Correct 3 ms 588 KB Output is correct
38 Correct 5 ms 804 KB Output is correct
39 Correct 236 ms 15280 KB Output is correct
40 Correct 250 ms 15324 KB Output is correct
41 Correct 206 ms 15324 KB Output is correct
42 Correct 249 ms 15268 KB Output is correct
43 Correct 211 ms 15316 KB Output is correct
44 Correct 225 ms 15288 KB Output is correct
45 Correct 93 ms 13904 KB Output is correct
46 Correct 80 ms 14348 KB Output is correct
47 Correct 214 ms 15212 KB Output is correct
48 Correct 201 ms 15312 KB Output is correct
49 Correct 220 ms 15284 KB Output is correct
50 Correct 200 ms 15316 KB Output is correct
51 Correct 164 ms 13776 KB Output is correct
52 Correct 224 ms 15280 KB Output is correct
53 Correct 266 ms 15200 KB Output is correct
54 Correct 274 ms 15368 KB Output is correct
55 Execution timed out 1075 ms 52928 KB Time limit exceeded
56 Halted 0 ms 0 KB -