답안 #421796

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
421796 2021-06-09T12:12:42 Z shenxy 푸드 코트 (JOI21_foodcourt) C++11
14 / 100
1000 ms 97208 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(long long k) {
		prop();
		if (s == e) return s;
		if (r -> lazy + r -> v < k) return r -> descend(k);
		return l -> descend(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 a, int b, int i) {
		if (s != a || e != b) {
			if (a > m) r -> update(a, b, i);
			else if (b <= m) l -> update(a, b, i);
			else l -> update(a, m, i), r -> update(m + 1, b, i);
		} else ops.push_back(i);
	}
	void query() {
		for (int i: ops) {
			if (T[i] == 3) {
				long long curr = r1 -> query(i, i) - r1 -> query(0, i);
				int l = 0, r = i;
				while (l != r) {
					int x = (l + r) / 2 + 1;
					if (r2 -> query(x, x) < r2 -> query(i, i) - curr + K[i]) l = x;
					else r = x - 1;
				}
				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();
		}
		for (int i: ops) {
			if (T[i] == 1) r1 -> update(i, Q, -K[i]), r2 -> update(i, Q, -K[i]);
			else if (T[i] == 2) r1 -> update(i, Q, K[i]);
		}
	}
} *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], R[i], 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:99:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   99 |  scanf("%d %d %d", &N, &M, &Q);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
foodcourt.cpp:104:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  104 |   scanf("%d", &T[i]);
      |   ~~~~~^~~~~~~~~~~~~
foodcourt.cpp:105:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  105 |   if (T[i] == 1) scanf("%d %d %d %lld", &L[i], &R[i], &C[i], &K[i]);
      |                  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
foodcourt.cpp:106:28: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  106 |   else if (T[i] == 2) scanf("%d %d %lld", &L[i], &R[i], &K[i]);
      |                       ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
foodcourt.cpp:107:13: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  107 |   else scanf("%d %lld", &L[i], &K[i]), R[i] = L[i];
      |        ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 844 KB Output is correct
2 Correct 13 ms 1148 KB Output is correct
3 Correct 11 ms 976 KB Output is correct
4 Correct 17 ms 1164 KB Output is correct
5 Correct 3 ms 716 KB Output is correct
6 Correct 3 ms 588 KB Output is correct
7 Correct 15 ms 1100 KB Output is correct
8 Correct 15 ms 1160 KB Output is correct
9 Correct 15 ms 1100 KB Output is correct
10 Correct 15 ms 1164 KB Output is correct
11 Correct 15 ms 1064 KB Output is correct
12 Correct 15 ms 1160 KB Output is correct
13 Correct 3 ms 844 KB Output is correct
14 Correct 4 ms 968 KB Output is correct
15 Correct 12 ms 972 KB Output is correct
16 Correct 18 ms 1172 KB Output is correct
17 Correct 15 ms 980 KB Output is correct
18 Correct 15 ms 1100 KB Output is correct
19 Correct 8 ms 972 KB Output is correct
20 Correct 8 ms 1100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 844 KB Output is correct
2 Correct 13 ms 1148 KB Output is correct
3 Correct 11 ms 976 KB Output is correct
4 Correct 17 ms 1164 KB Output is correct
5 Correct 3 ms 716 KB Output is correct
6 Correct 3 ms 588 KB Output is correct
7 Correct 15 ms 1100 KB Output is correct
8 Correct 15 ms 1160 KB Output is correct
9 Correct 15 ms 1100 KB Output is correct
10 Correct 15 ms 1164 KB Output is correct
11 Correct 15 ms 1064 KB Output is correct
12 Correct 15 ms 1160 KB Output is correct
13 Correct 3 ms 844 KB Output is correct
14 Correct 4 ms 968 KB Output is correct
15 Correct 12 ms 972 KB Output is correct
16 Correct 18 ms 1172 KB Output is correct
17 Correct 15 ms 980 KB Output is correct
18 Correct 15 ms 1100 KB Output is correct
19 Correct 8 ms 972 KB Output is correct
20 Correct 8 ms 1100 KB Output is correct
21 Correct 13 ms 1108 KB Output is correct
22 Correct 13 ms 1100 KB Output is correct
23 Correct 14 ms 972 KB Output is correct
24 Correct 16 ms 1212 KB Output is correct
25 Correct 3 ms 716 KB Output is correct
26 Correct 3 ms 716 KB Output is correct
27 Correct 16 ms 1176 KB Output is correct
28 Correct 16 ms 1184 KB Output is correct
29 Correct 15 ms 1176 KB Output is correct
30 Correct 16 ms 1184 KB Output is correct
31 Correct 15 ms 1100 KB Output is correct
32 Correct 15 ms 1100 KB Output is correct
33 Correct 3 ms 972 KB Output is correct
34 Correct 4 ms 1040 KB Output is correct
35 Correct 13 ms 1072 KB Output is correct
36 Correct 15 ms 1196 KB Output is correct
37 Correct 6 ms 844 KB Output is correct
38 Correct 8 ms 1116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 701 ms 26460 KB Output is correct
2 Correct 618 ms 27508 KB Output is correct
3 Correct 739 ms 27824 KB Output is correct
4 Correct 743 ms 27756 KB Output is correct
5 Correct 701 ms 27480 KB Output is correct
6 Correct 685 ms 27588 KB Output is correct
7 Correct 124 ms 14600 KB Output is correct
8 Correct 136 ms 14648 KB Output is correct
9 Correct 694 ms 27928 KB Output is correct
10 Correct 708 ms 27972 KB Output is correct
11 Correct 700 ms 27920 KB Output is correct
12 Correct 745 ms 27968 KB Output is correct
13 Correct 488 ms 21924 KB Output is correct
14 Correct 604 ms 26820 KB Output is correct
15 Correct 484 ms 23204 KB Output is correct
16 Correct 516 ms 26456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1063 ms 97208 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 844 KB Output is correct
2 Correct 13 ms 1148 KB Output is correct
3 Correct 11 ms 976 KB Output is correct
4 Correct 17 ms 1164 KB Output is correct
5 Correct 3 ms 716 KB Output is correct
6 Correct 3 ms 588 KB Output is correct
7 Correct 15 ms 1100 KB Output is correct
8 Correct 15 ms 1160 KB Output is correct
9 Correct 15 ms 1100 KB Output is correct
10 Correct 15 ms 1164 KB Output is correct
11 Correct 15 ms 1064 KB Output is correct
12 Correct 15 ms 1160 KB Output is correct
13 Correct 3 ms 844 KB Output is correct
14 Correct 4 ms 968 KB Output is correct
15 Correct 12 ms 972 KB Output is correct
16 Correct 18 ms 1172 KB Output is correct
17 Correct 15 ms 980 KB Output is correct
18 Correct 15 ms 1100 KB Output is correct
19 Correct 8 ms 972 KB Output is correct
20 Correct 8 ms 1100 KB Output is correct
21 Correct 701 ms 26460 KB Output is correct
22 Correct 618 ms 27508 KB Output is correct
23 Correct 739 ms 27824 KB Output is correct
24 Correct 743 ms 27756 KB Output is correct
25 Correct 701 ms 27480 KB Output is correct
26 Correct 685 ms 27588 KB Output is correct
27 Correct 124 ms 14600 KB Output is correct
28 Correct 136 ms 14648 KB Output is correct
29 Correct 694 ms 27928 KB Output is correct
30 Correct 708 ms 27972 KB Output is correct
31 Correct 700 ms 27920 KB Output is correct
32 Correct 745 ms 27968 KB Output is correct
33 Correct 488 ms 21924 KB Output is correct
34 Correct 604 ms 26820 KB Output is correct
35 Correct 484 ms 23204 KB Output is correct
36 Correct 516 ms 26456 KB Output is correct
37 Execution timed out 1077 ms 25740 KB Time limit exceeded
38 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1076 ms 24536 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 844 KB Output is correct
2 Correct 13 ms 1148 KB Output is correct
3 Correct 11 ms 976 KB Output is correct
4 Correct 17 ms 1164 KB Output is correct
5 Correct 3 ms 716 KB Output is correct
6 Correct 3 ms 588 KB Output is correct
7 Correct 15 ms 1100 KB Output is correct
8 Correct 15 ms 1160 KB Output is correct
9 Correct 15 ms 1100 KB Output is correct
10 Correct 15 ms 1164 KB Output is correct
11 Correct 15 ms 1064 KB Output is correct
12 Correct 15 ms 1160 KB Output is correct
13 Correct 3 ms 844 KB Output is correct
14 Correct 4 ms 968 KB Output is correct
15 Correct 12 ms 972 KB Output is correct
16 Correct 18 ms 1172 KB Output is correct
17 Correct 15 ms 980 KB Output is correct
18 Correct 15 ms 1100 KB Output is correct
19 Correct 8 ms 972 KB Output is correct
20 Correct 8 ms 1100 KB Output is correct
21 Correct 13 ms 1108 KB Output is correct
22 Correct 13 ms 1100 KB Output is correct
23 Correct 14 ms 972 KB Output is correct
24 Correct 16 ms 1212 KB Output is correct
25 Correct 3 ms 716 KB Output is correct
26 Correct 3 ms 716 KB Output is correct
27 Correct 16 ms 1176 KB Output is correct
28 Correct 16 ms 1184 KB Output is correct
29 Correct 15 ms 1176 KB Output is correct
30 Correct 16 ms 1184 KB Output is correct
31 Correct 15 ms 1100 KB Output is correct
32 Correct 15 ms 1100 KB Output is correct
33 Correct 3 ms 972 KB Output is correct
34 Correct 4 ms 1040 KB Output is correct
35 Correct 13 ms 1072 KB Output is correct
36 Correct 15 ms 1196 KB Output is correct
37 Correct 6 ms 844 KB Output is correct
38 Correct 8 ms 1116 KB Output is correct
39 Correct 701 ms 26460 KB Output is correct
40 Correct 618 ms 27508 KB Output is correct
41 Correct 739 ms 27824 KB Output is correct
42 Correct 743 ms 27756 KB Output is correct
43 Correct 701 ms 27480 KB Output is correct
44 Correct 685 ms 27588 KB Output is correct
45 Correct 124 ms 14600 KB Output is correct
46 Correct 136 ms 14648 KB Output is correct
47 Correct 694 ms 27928 KB Output is correct
48 Correct 708 ms 27972 KB Output is correct
49 Correct 700 ms 27920 KB Output is correct
50 Correct 745 ms 27968 KB Output is correct
51 Correct 488 ms 21924 KB Output is correct
52 Correct 604 ms 26820 KB Output is correct
53 Correct 484 ms 23204 KB Output is correct
54 Correct 516 ms 26456 KB Output is correct
55 Execution timed out 1077 ms 25740 KB Time limit exceeded
56 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 844 KB Output is correct
2 Correct 13 ms 1148 KB Output is correct
3 Correct 11 ms 976 KB Output is correct
4 Correct 17 ms 1164 KB Output is correct
5 Correct 3 ms 716 KB Output is correct
6 Correct 3 ms 588 KB Output is correct
7 Correct 15 ms 1100 KB Output is correct
8 Correct 15 ms 1160 KB Output is correct
9 Correct 15 ms 1100 KB Output is correct
10 Correct 15 ms 1164 KB Output is correct
11 Correct 15 ms 1064 KB Output is correct
12 Correct 15 ms 1160 KB Output is correct
13 Correct 3 ms 844 KB Output is correct
14 Correct 4 ms 968 KB Output is correct
15 Correct 12 ms 972 KB Output is correct
16 Correct 18 ms 1172 KB Output is correct
17 Correct 15 ms 980 KB Output is correct
18 Correct 15 ms 1100 KB Output is correct
19 Correct 8 ms 972 KB Output is correct
20 Correct 8 ms 1100 KB Output is correct
21 Correct 13 ms 1108 KB Output is correct
22 Correct 13 ms 1100 KB Output is correct
23 Correct 14 ms 972 KB Output is correct
24 Correct 16 ms 1212 KB Output is correct
25 Correct 3 ms 716 KB Output is correct
26 Correct 3 ms 716 KB Output is correct
27 Correct 16 ms 1176 KB Output is correct
28 Correct 16 ms 1184 KB Output is correct
29 Correct 15 ms 1176 KB Output is correct
30 Correct 16 ms 1184 KB Output is correct
31 Correct 15 ms 1100 KB Output is correct
32 Correct 15 ms 1100 KB Output is correct
33 Correct 3 ms 972 KB Output is correct
34 Correct 4 ms 1040 KB Output is correct
35 Correct 13 ms 1072 KB Output is correct
36 Correct 15 ms 1196 KB Output is correct
37 Correct 6 ms 844 KB Output is correct
38 Correct 8 ms 1116 KB Output is correct
39 Correct 701 ms 26460 KB Output is correct
40 Correct 618 ms 27508 KB Output is correct
41 Correct 739 ms 27824 KB Output is correct
42 Correct 743 ms 27756 KB Output is correct
43 Correct 701 ms 27480 KB Output is correct
44 Correct 685 ms 27588 KB Output is correct
45 Correct 124 ms 14600 KB Output is correct
46 Correct 136 ms 14648 KB Output is correct
47 Correct 694 ms 27928 KB Output is correct
48 Correct 708 ms 27972 KB Output is correct
49 Correct 700 ms 27920 KB Output is correct
50 Correct 745 ms 27968 KB Output is correct
51 Correct 488 ms 21924 KB Output is correct
52 Correct 604 ms 26820 KB Output is correct
53 Correct 484 ms 23204 KB Output is correct
54 Correct 516 ms 26456 KB Output is correct
55 Execution timed out 1063 ms 97208 KB Time limit exceeded
56 Halted 0 ms 0 KB -