답안 #421812

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
421812 2021-06-09T12:33:10 Z shenxy 푸드 코트 (JOI21_foodcourt) C++11
68 / 100
1000 ms 83532 KB
#include <cstdio>
#include <algorithm>
#include <vector>
#define m (s+e)/2
using namespace std;
typedef pair<long long, 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;
struct dnc {
	int s, e;
	vector<int> ops;
	dnc *l, *r;
	dnc(int _s, int _e) {
		s = _s, e = _e;
		if (s != e) {
			l = new dnc(s, m);
			r = new dnc(m + 1, e);
		}
	}
	void update(int x, int i) {
		if (s != e) {
			if (x > m) r -> update(x, i);
			else l -> update(x, i);
		} else ops.push_back(i);
	}
	void query() {
		for (int i: ops) {
			//printf("%d %d %d\n", s, e, i);
			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);
				//printf("%lld\n", curr);
				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]);
		}
		if (s != e) {
			l -> query();
			r -> query();
		}
	}
} *dc;
int main() {
	scanf("%d %d %d", &N, &M, &Q);
	r1 = new seg(0, Q);
	r2 = new seg(0, Q);
	dc = new dnc(1, N);
	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];
		dc -> update(L[i], i);
		if (T[i] != 3 && R[i] != N) dc -> update(R[i] + 1, -i);
	}
	dc -> query();
	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:93:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   93 |  scanf("%d %d %d", &N, &M, &Q);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
foodcourt.cpp:98:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   98 |   scanf("%d", &T[i]);
      |   ~~~~~^~~~~~~~~~~~~
foodcourt.cpp:99:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   99 |   if (T[i] == 1) scanf("%d %d %d %lld", &L[i], &R[i], &C[i], &K[i]);
      |                  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
foodcourt.cpp:100:28: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  100 |   else if (T[i] == 2) scanf("%d %d %lld", &L[i], &R[i], &K[i]);
      |                       ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
foodcourt.cpp:101:13: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  101 |   else scanf("%d %lld", &L[i], &K[i]), R[i] = L[i];
      |        ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 844 KB Output is correct
2 Correct 4 ms 972 KB Output is correct
3 Correct 4 ms 844 KB Output is correct
4 Correct 5 ms 972 KB Output is correct
5 Correct 2 ms 688 KB Output is correct
6 Correct 2 ms 688 KB Output is correct
7 Correct 4 ms 972 KB Output is correct
8 Correct 4 ms 972 KB Output is correct
9 Correct 4 ms 972 KB Output is correct
10 Correct 4 ms 972 KB Output is correct
11 Correct 4 ms 972 KB Output is correct
12 Correct 4 ms 972 KB Output is correct
13 Correct 2 ms 940 KB Output is correct
14 Correct 3 ms 972 KB Output is correct
15 Correct 3 ms 812 KB Output is correct
16 Correct 4 ms 972 KB Output is correct
17 Correct 4 ms 844 KB Output is correct
18 Correct 5 ms 1068 KB Output is correct
19 Correct 4 ms 972 KB Output is correct
20 Correct 5 ms 972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 844 KB Output is correct
2 Correct 4 ms 972 KB Output is correct
3 Correct 4 ms 844 KB Output is correct
4 Correct 5 ms 972 KB Output is correct
5 Correct 2 ms 688 KB Output is correct
6 Correct 2 ms 688 KB Output is correct
7 Correct 4 ms 972 KB Output is correct
8 Correct 4 ms 972 KB Output is correct
9 Correct 4 ms 972 KB Output is correct
10 Correct 4 ms 972 KB Output is correct
11 Correct 4 ms 972 KB Output is correct
12 Correct 4 ms 972 KB Output is correct
13 Correct 2 ms 940 KB Output is correct
14 Correct 3 ms 972 KB Output is correct
15 Correct 3 ms 812 KB Output is correct
16 Correct 4 ms 972 KB Output is correct
17 Correct 4 ms 844 KB Output is correct
18 Correct 5 ms 1068 KB Output is correct
19 Correct 4 ms 972 KB Output is correct
20 Correct 5 ms 972 KB Output is correct
21 Correct 5 ms 1024 KB Output is correct
22 Correct 4 ms 972 KB Output is correct
23 Correct 4 ms 940 KB Output is correct
24 Correct 5 ms 972 KB Output is correct
25 Correct 2 ms 716 KB Output is correct
26 Correct 2 ms 700 KB Output is correct
27 Correct 4 ms 972 KB Output is correct
28 Correct 4 ms 972 KB Output is correct
29 Correct 5 ms 1072 KB Output is correct
30 Correct 4 ms 1064 KB Output is correct
31 Correct 4 ms 1100 KB Output is correct
32 Correct 5 ms 972 KB Output is correct
33 Correct 3 ms 972 KB Output is correct
34 Correct 3 ms 1068 KB Output is correct
35 Correct 3 ms 972 KB Output is correct
36 Correct 4 ms 972 KB Output is correct
37 Correct 4 ms 844 KB Output is correct
38 Correct 5 ms 972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 221 ms 24052 KB Output is correct
2 Correct 237 ms 24360 KB Output is correct
3 Correct 244 ms 24228 KB Output is correct
4 Correct 225 ms 24260 KB Output is correct
5 Correct 247 ms 24388 KB Output is correct
6 Correct 278 ms 24268 KB Output is correct
7 Correct 64 ms 13884 KB Output is correct
8 Correct 66 ms 14084 KB Output is correct
9 Correct 232 ms 24160 KB Output is correct
10 Correct 232 ms 24176 KB Output is correct
11 Correct 218 ms 24256 KB Output is correct
12 Correct 219 ms 24384 KB Output is correct
13 Correct 177 ms 19908 KB Output is correct
14 Correct 216 ms 24192 KB Output is correct
15 Correct 263 ms 21200 KB Output is correct
16 Correct 274 ms 24272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1080 ms 83532 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 844 KB Output is correct
2 Correct 4 ms 972 KB Output is correct
3 Correct 4 ms 844 KB Output is correct
4 Correct 5 ms 972 KB Output is correct
5 Correct 2 ms 688 KB Output is correct
6 Correct 2 ms 688 KB Output is correct
7 Correct 4 ms 972 KB Output is correct
8 Correct 4 ms 972 KB Output is correct
9 Correct 4 ms 972 KB Output is correct
10 Correct 4 ms 972 KB Output is correct
11 Correct 4 ms 972 KB Output is correct
12 Correct 4 ms 972 KB Output is correct
13 Correct 2 ms 940 KB Output is correct
14 Correct 3 ms 972 KB Output is correct
15 Correct 3 ms 812 KB Output is correct
16 Correct 4 ms 972 KB Output is correct
17 Correct 4 ms 844 KB Output is correct
18 Correct 5 ms 1068 KB Output is correct
19 Correct 4 ms 972 KB Output is correct
20 Correct 5 ms 972 KB Output is correct
21 Correct 221 ms 24052 KB Output is correct
22 Correct 237 ms 24360 KB Output is correct
23 Correct 244 ms 24228 KB Output is correct
24 Correct 225 ms 24260 KB Output is correct
25 Correct 247 ms 24388 KB Output is correct
26 Correct 278 ms 24268 KB Output is correct
27 Correct 64 ms 13884 KB Output is correct
28 Correct 66 ms 14084 KB Output is correct
29 Correct 232 ms 24160 KB Output is correct
30 Correct 232 ms 24176 KB Output is correct
31 Correct 218 ms 24256 KB Output is correct
32 Correct 219 ms 24384 KB Output is correct
33 Correct 177 ms 19908 KB Output is correct
34 Correct 216 ms 24192 KB Output is correct
35 Correct 263 ms 21200 KB Output is correct
36 Correct 274 ms 24272 KB Output is correct
37 Correct 264 ms 21912 KB Output is correct
38 Correct 242 ms 21072 KB Output is correct
39 Correct 58 ms 12560 KB Output is correct
40 Correct 75 ms 14336 KB Output is correct
41 Correct 263 ms 25112 KB Output is correct
42 Correct 259 ms 25200 KB Output is correct
43 Correct 267 ms 25148 KB Output is correct
44 Correct 270 ms 25152 KB Output is correct
45 Correct 256 ms 25252 KB Output is correct
46 Correct 258 ms 25168 KB Output is correct
47 Correct 107 ms 24072 KB Output is correct
48 Correct 216 ms 24588 KB Output is correct
49 Correct 158 ms 17860 KB Output is correct
50 Correct 205 ms 22624 KB Output is correct
51 Correct 277 ms 25276 KB Output is correct
52 Correct 265 ms 25284 KB Output is correct
53 Correct 205 ms 20664 KB Output is correct
54 Correct 273 ms 25420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 236 ms 22232 KB Output is correct
2 Correct 247 ms 22728 KB Output is correct
3 Correct 297 ms 25792 KB Output is correct
4 Correct 165 ms 20400 KB Output is correct
5 Correct 225 ms 23192 KB Output is correct
6 Correct 269 ms 25816 KB Output is correct
7 Correct 71 ms 14352 KB Output is correct
8 Correct 70 ms 13476 KB Output is correct
9 Correct 134 ms 25032 KB Output is correct
10 Correct 144 ms 19176 KB Output is correct
11 Correct 213 ms 25448 KB Output is correct
12 Correct 249 ms 25336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 844 KB Output is correct
2 Correct 4 ms 972 KB Output is correct
3 Correct 4 ms 844 KB Output is correct
4 Correct 5 ms 972 KB Output is correct
5 Correct 2 ms 688 KB Output is correct
6 Correct 2 ms 688 KB Output is correct
7 Correct 4 ms 972 KB Output is correct
8 Correct 4 ms 972 KB Output is correct
9 Correct 4 ms 972 KB Output is correct
10 Correct 4 ms 972 KB Output is correct
11 Correct 4 ms 972 KB Output is correct
12 Correct 4 ms 972 KB Output is correct
13 Correct 2 ms 940 KB Output is correct
14 Correct 3 ms 972 KB Output is correct
15 Correct 3 ms 812 KB Output is correct
16 Correct 4 ms 972 KB Output is correct
17 Correct 4 ms 844 KB Output is correct
18 Correct 5 ms 1068 KB Output is correct
19 Correct 4 ms 972 KB Output is correct
20 Correct 5 ms 972 KB Output is correct
21 Correct 5 ms 1024 KB Output is correct
22 Correct 4 ms 972 KB Output is correct
23 Correct 4 ms 940 KB Output is correct
24 Correct 5 ms 972 KB Output is correct
25 Correct 2 ms 716 KB Output is correct
26 Correct 2 ms 700 KB Output is correct
27 Correct 4 ms 972 KB Output is correct
28 Correct 4 ms 972 KB Output is correct
29 Correct 5 ms 1072 KB Output is correct
30 Correct 4 ms 1064 KB Output is correct
31 Correct 4 ms 1100 KB Output is correct
32 Correct 5 ms 972 KB Output is correct
33 Correct 3 ms 972 KB Output is correct
34 Correct 3 ms 1068 KB Output is correct
35 Correct 3 ms 972 KB Output is correct
36 Correct 4 ms 972 KB Output is correct
37 Correct 4 ms 844 KB Output is correct
38 Correct 5 ms 972 KB Output is correct
39 Correct 221 ms 24052 KB Output is correct
40 Correct 237 ms 24360 KB Output is correct
41 Correct 244 ms 24228 KB Output is correct
42 Correct 225 ms 24260 KB Output is correct
43 Correct 247 ms 24388 KB Output is correct
44 Correct 278 ms 24268 KB Output is correct
45 Correct 64 ms 13884 KB Output is correct
46 Correct 66 ms 14084 KB Output is correct
47 Correct 232 ms 24160 KB Output is correct
48 Correct 232 ms 24176 KB Output is correct
49 Correct 218 ms 24256 KB Output is correct
50 Correct 219 ms 24384 KB Output is correct
51 Correct 177 ms 19908 KB Output is correct
52 Correct 216 ms 24192 KB Output is correct
53 Correct 263 ms 21200 KB Output is correct
54 Correct 274 ms 24272 KB Output is correct
55 Correct 264 ms 21912 KB Output is correct
56 Correct 242 ms 21072 KB Output is correct
57 Correct 58 ms 12560 KB Output is correct
58 Correct 75 ms 14336 KB Output is correct
59 Correct 263 ms 25112 KB Output is correct
60 Correct 259 ms 25200 KB Output is correct
61 Correct 267 ms 25148 KB Output is correct
62 Correct 270 ms 25152 KB Output is correct
63 Correct 256 ms 25252 KB Output is correct
64 Correct 258 ms 25168 KB Output is correct
65 Correct 107 ms 24072 KB Output is correct
66 Correct 216 ms 24588 KB Output is correct
67 Correct 158 ms 17860 KB Output is correct
68 Correct 205 ms 22624 KB Output is correct
69 Correct 277 ms 25276 KB Output is correct
70 Correct 265 ms 25284 KB Output is correct
71 Correct 205 ms 20664 KB Output is correct
72 Correct 273 ms 25420 KB Output is correct
73 Correct 236 ms 22232 KB Output is correct
74 Correct 247 ms 22728 KB Output is correct
75 Correct 297 ms 25792 KB Output is correct
76 Correct 165 ms 20400 KB Output is correct
77 Correct 225 ms 23192 KB Output is correct
78 Correct 269 ms 25816 KB Output is correct
79 Correct 71 ms 14352 KB Output is correct
80 Correct 70 ms 13476 KB Output is correct
81 Correct 134 ms 25032 KB Output is correct
82 Correct 144 ms 19176 KB Output is correct
83 Correct 213 ms 25448 KB Output is correct
84 Correct 249 ms 25336 KB Output is correct
85 Correct 235 ms 22424 KB Output is correct
86 Correct 253 ms 25748 KB Output is correct
87 Correct 241 ms 23088 KB Output is correct
88 Correct 268 ms 25756 KB Output is correct
89 Correct 162 ms 18376 KB Output is correct
90 Correct 315 ms 25724 KB Output is correct
91 Correct 194 ms 19840 KB Output is correct
92 Correct 181 ms 19180 KB Output is correct
93 Correct 300 ms 25704 KB Output is correct
94 Correct 290 ms 25652 KB Output is correct
95 Correct 306 ms 24492 KB Output is correct
96 Correct 269 ms 25764 KB Output is correct
97 Correct 285 ms 25708 KB Output is correct
98 Correct 244 ms 20844 KB Output is correct
99 Correct 121 ms 24604 KB Output is correct
100 Correct 194 ms 21328 KB Output is correct
101 Correct 230 ms 25144 KB Output is correct
102 Correct 181 ms 25572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 844 KB Output is correct
2 Correct 4 ms 972 KB Output is correct
3 Correct 4 ms 844 KB Output is correct
4 Correct 5 ms 972 KB Output is correct
5 Correct 2 ms 688 KB Output is correct
6 Correct 2 ms 688 KB Output is correct
7 Correct 4 ms 972 KB Output is correct
8 Correct 4 ms 972 KB Output is correct
9 Correct 4 ms 972 KB Output is correct
10 Correct 4 ms 972 KB Output is correct
11 Correct 4 ms 972 KB Output is correct
12 Correct 4 ms 972 KB Output is correct
13 Correct 2 ms 940 KB Output is correct
14 Correct 3 ms 972 KB Output is correct
15 Correct 3 ms 812 KB Output is correct
16 Correct 4 ms 972 KB Output is correct
17 Correct 4 ms 844 KB Output is correct
18 Correct 5 ms 1068 KB Output is correct
19 Correct 4 ms 972 KB Output is correct
20 Correct 5 ms 972 KB Output is correct
21 Correct 5 ms 1024 KB Output is correct
22 Correct 4 ms 972 KB Output is correct
23 Correct 4 ms 940 KB Output is correct
24 Correct 5 ms 972 KB Output is correct
25 Correct 2 ms 716 KB Output is correct
26 Correct 2 ms 700 KB Output is correct
27 Correct 4 ms 972 KB Output is correct
28 Correct 4 ms 972 KB Output is correct
29 Correct 5 ms 1072 KB Output is correct
30 Correct 4 ms 1064 KB Output is correct
31 Correct 4 ms 1100 KB Output is correct
32 Correct 5 ms 972 KB Output is correct
33 Correct 3 ms 972 KB Output is correct
34 Correct 3 ms 1068 KB Output is correct
35 Correct 3 ms 972 KB Output is correct
36 Correct 4 ms 972 KB Output is correct
37 Correct 4 ms 844 KB Output is correct
38 Correct 5 ms 972 KB Output is correct
39 Correct 221 ms 24052 KB Output is correct
40 Correct 237 ms 24360 KB Output is correct
41 Correct 244 ms 24228 KB Output is correct
42 Correct 225 ms 24260 KB Output is correct
43 Correct 247 ms 24388 KB Output is correct
44 Correct 278 ms 24268 KB Output is correct
45 Correct 64 ms 13884 KB Output is correct
46 Correct 66 ms 14084 KB Output is correct
47 Correct 232 ms 24160 KB Output is correct
48 Correct 232 ms 24176 KB Output is correct
49 Correct 218 ms 24256 KB Output is correct
50 Correct 219 ms 24384 KB Output is correct
51 Correct 177 ms 19908 KB Output is correct
52 Correct 216 ms 24192 KB Output is correct
53 Correct 263 ms 21200 KB Output is correct
54 Correct 274 ms 24272 KB Output is correct
55 Execution timed out 1080 ms 83532 KB Time limit exceeded
56 Halted 0 ms 0 KB -