Submission #421798

# Submission time Handle Problem Language Result Execution time Memory
421798 2021-06-09T12:16:06 Z shenxy Food Court (JOI21_foodcourt) C++11
14 / 100
1000 ms 97116 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 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 = 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();
		}
		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:94:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   94 |  scanf("%d %d %d", &N, &M, &Q);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
foodcourt.cpp:99:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   99 |   scanf("%d", &T[i]);
      |   ~~~~~^~~~~~~~~~~~~
foodcourt.cpp:100:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  100 |   if (T[i] == 1) scanf("%d %d %d %lld", &L[i], &R[i], &C[i], &K[i]);
      |                  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
foodcourt.cpp:101:28: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  101 |   else if (T[i] == 2) scanf("%d %d %lld", &L[i], &R[i], &K[i]);
      |                       ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
foodcourt.cpp:102:13: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  102 |   else scanf("%d %lld", &L[i], &K[i]), R[i] = L[i];
      |        ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 844 KB Output is correct
2 Correct 13 ms 1116 KB Output is correct
3 Correct 10 ms 944 KB Output is correct
4 Correct 16 ms 1100 KB Output is correct
5 Correct 2 ms 588 KB Output is correct
6 Correct 2 ms 588 KB Output is correct
7 Correct 14 ms 1128 KB Output is correct
8 Correct 14 ms 1100 KB Output is correct
9 Correct 14 ms 1100 KB Output is correct
10 Correct 14 ms 1100 KB Output is correct
11 Correct 14 ms 1136 KB Output is correct
12 Correct 14 ms 1132 KB Output is correct
13 Correct 2 ms 844 KB Output is correct
14 Correct 3 ms 972 KB Output is correct
15 Correct 10 ms 844 KB Output is correct
16 Correct 14 ms 1148 KB Output is correct
17 Correct 11 ms 844 KB Output is correct
18 Correct 14 ms 1132 KB Output is correct
19 Correct 7 ms 844 KB Output is correct
20 Correct 8 ms 1072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 844 KB Output is correct
2 Correct 13 ms 1116 KB Output is correct
3 Correct 10 ms 944 KB Output is correct
4 Correct 16 ms 1100 KB Output is correct
5 Correct 2 ms 588 KB Output is correct
6 Correct 2 ms 588 KB Output is correct
7 Correct 14 ms 1128 KB Output is correct
8 Correct 14 ms 1100 KB Output is correct
9 Correct 14 ms 1100 KB Output is correct
10 Correct 14 ms 1100 KB Output is correct
11 Correct 14 ms 1136 KB Output is correct
12 Correct 14 ms 1132 KB Output is correct
13 Correct 2 ms 844 KB Output is correct
14 Correct 3 ms 972 KB Output is correct
15 Correct 10 ms 844 KB Output is correct
16 Correct 14 ms 1148 KB Output is correct
17 Correct 11 ms 844 KB Output is correct
18 Correct 14 ms 1132 KB Output is correct
19 Correct 7 ms 844 KB Output is correct
20 Correct 8 ms 1072 KB Output is correct
21 Correct 12 ms 972 KB Output is correct
22 Correct 13 ms 1120 KB Output is correct
23 Correct 14 ms 1000 KB Output is correct
24 Correct 15 ms 1128 KB Output is correct
25 Correct 2 ms 588 KB Output is correct
26 Correct 3 ms 716 KB Output is correct
27 Correct 14 ms 1100 KB Output is correct
28 Correct 15 ms 1016 KB Output is correct
29 Correct 14 ms 1128 KB Output is correct
30 Correct 14 ms 1140 KB Output is correct
31 Correct 14 ms 1136 KB Output is correct
32 Correct 14 ms 1136 KB Output is correct
33 Correct 3 ms 844 KB Output is correct
34 Correct 4 ms 972 KB Output is correct
35 Correct 12 ms 972 KB Output is correct
36 Correct 14 ms 1160 KB Output is correct
37 Correct 5 ms 844 KB Output is correct
38 Correct 8 ms 972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 543 ms 26524 KB Output is correct
2 Correct 537 ms 26132 KB Output is correct
3 Correct 580 ms 26576 KB Output is correct
4 Correct 616 ms 26564 KB Output is correct
5 Correct 594 ms 26268 KB Output is correct
6 Correct 595 ms 26436 KB Output is correct
7 Correct 80 ms 13760 KB Output is correct
8 Correct 88 ms 13972 KB Output is correct
9 Correct 586 ms 26532 KB Output is correct
10 Correct 596 ms 26704 KB Output is correct
11 Correct 625 ms 26668 KB Output is correct
12 Correct 632 ms 26716 KB Output is correct
13 Correct 382 ms 20952 KB Output is correct
14 Correct 437 ms 25732 KB Output is correct
15 Correct 438 ms 21936 KB Output is correct
16 Correct 453 ms 25156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1092 ms 97116 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 844 KB Output is correct
2 Correct 13 ms 1116 KB Output is correct
3 Correct 10 ms 944 KB Output is correct
4 Correct 16 ms 1100 KB Output is correct
5 Correct 2 ms 588 KB Output is correct
6 Correct 2 ms 588 KB Output is correct
7 Correct 14 ms 1128 KB Output is correct
8 Correct 14 ms 1100 KB Output is correct
9 Correct 14 ms 1100 KB Output is correct
10 Correct 14 ms 1100 KB Output is correct
11 Correct 14 ms 1136 KB Output is correct
12 Correct 14 ms 1132 KB Output is correct
13 Correct 2 ms 844 KB Output is correct
14 Correct 3 ms 972 KB Output is correct
15 Correct 10 ms 844 KB Output is correct
16 Correct 14 ms 1148 KB Output is correct
17 Correct 11 ms 844 KB Output is correct
18 Correct 14 ms 1132 KB Output is correct
19 Correct 7 ms 844 KB Output is correct
20 Correct 8 ms 1072 KB Output is correct
21 Correct 543 ms 26524 KB Output is correct
22 Correct 537 ms 26132 KB Output is correct
23 Correct 580 ms 26576 KB Output is correct
24 Correct 616 ms 26564 KB Output is correct
25 Correct 594 ms 26268 KB Output is correct
26 Correct 595 ms 26436 KB Output is correct
27 Correct 80 ms 13760 KB Output is correct
28 Correct 88 ms 13972 KB Output is correct
29 Correct 586 ms 26532 KB Output is correct
30 Correct 596 ms 26704 KB Output is correct
31 Correct 625 ms 26668 KB Output is correct
32 Correct 632 ms 26716 KB Output is correct
33 Correct 382 ms 20952 KB Output is correct
34 Correct 437 ms 25732 KB Output is correct
35 Correct 438 ms 21936 KB Output is correct
36 Correct 453 ms 25156 KB Output is correct
37 Execution timed out 1006 ms 24880 KB Time limit exceeded
38 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 969 ms 24784 KB Output is correct
2 Execution timed out 1039 ms 26776 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 844 KB Output is correct
2 Correct 13 ms 1116 KB Output is correct
3 Correct 10 ms 944 KB Output is correct
4 Correct 16 ms 1100 KB Output is correct
5 Correct 2 ms 588 KB Output is correct
6 Correct 2 ms 588 KB Output is correct
7 Correct 14 ms 1128 KB Output is correct
8 Correct 14 ms 1100 KB Output is correct
9 Correct 14 ms 1100 KB Output is correct
10 Correct 14 ms 1100 KB Output is correct
11 Correct 14 ms 1136 KB Output is correct
12 Correct 14 ms 1132 KB Output is correct
13 Correct 2 ms 844 KB Output is correct
14 Correct 3 ms 972 KB Output is correct
15 Correct 10 ms 844 KB Output is correct
16 Correct 14 ms 1148 KB Output is correct
17 Correct 11 ms 844 KB Output is correct
18 Correct 14 ms 1132 KB Output is correct
19 Correct 7 ms 844 KB Output is correct
20 Correct 8 ms 1072 KB Output is correct
21 Correct 12 ms 972 KB Output is correct
22 Correct 13 ms 1120 KB Output is correct
23 Correct 14 ms 1000 KB Output is correct
24 Correct 15 ms 1128 KB Output is correct
25 Correct 2 ms 588 KB Output is correct
26 Correct 3 ms 716 KB Output is correct
27 Correct 14 ms 1100 KB Output is correct
28 Correct 15 ms 1016 KB Output is correct
29 Correct 14 ms 1128 KB Output is correct
30 Correct 14 ms 1140 KB Output is correct
31 Correct 14 ms 1136 KB Output is correct
32 Correct 14 ms 1136 KB Output is correct
33 Correct 3 ms 844 KB Output is correct
34 Correct 4 ms 972 KB Output is correct
35 Correct 12 ms 972 KB Output is correct
36 Correct 14 ms 1160 KB Output is correct
37 Correct 5 ms 844 KB Output is correct
38 Correct 8 ms 972 KB Output is correct
39 Correct 543 ms 26524 KB Output is correct
40 Correct 537 ms 26132 KB Output is correct
41 Correct 580 ms 26576 KB Output is correct
42 Correct 616 ms 26564 KB Output is correct
43 Correct 594 ms 26268 KB Output is correct
44 Correct 595 ms 26436 KB Output is correct
45 Correct 80 ms 13760 KB Output is correct
46 Correct 88 ms 13972 KB Output is correct
47 Correct 586 ms 26532 KB Output is correct
48 Correct 596 ms 26704 KB Output is correct
49 Correct 625 ms 26668 KB Output is correct
50 Correct 632 ms 26716 KB Output is correct
51 Correct 382 ms 20952 KB Output is correct
52 Correct 437 ms 25732 KB Output is correct
53 Correct 438 ms 21936 KB Output is correct
54 Correct 453 ms 25156 KB Output is correct
55 Execution timed out 1006 ms 24880 KB Time limit exceeded
56 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 844 KB Output is correct
2 Correct 13 ms 1116 KB Output is correct
3 Correct 10 ms 944 KB Output is correct
4 Correct 16 ms 1100 KB Output is correct
5 Correct 2 ms 588 KB Output is correct
6 Correct 2 ms 588 KB Output is correct
7 Correct 14 ms 1128 KB Output is correct
8 Correct 14 ms 1100 KB Output is correct
9 Correct 14 ms 1100 KB Output is correct
10 Correct 14 ms 1100 KB Output is correct
11 Correct 14 ms 1136 KB Output is correct
12 Correct 14 ms 1132 KB Output is correct
13 Correct 2 ms 844 KB Output is correct
14 Correct 3 ms 972 KB Output is correct
15 Correct 10 ms 844 KB Output is correct
16 Correct 14 ms 1148 KB Output is correct
17 Correct 11 ms 844 KB Output is correct
18 Correct 14 ms 1132 KB Output is correct
19 Correct 7 ms 844 KB Output is correct
20 Correct 8 ms 1072 KB Output is correct
21 Correct 12 ms 972 KB Output is correct
22 Correct 13 ms 1120 KB Output is correct
23 Correct 14 ms 1000 KB Output is correct
24 Correct 15 ms 1128 KB Output is correct
25 Correct 2 ms 588 KB Output is correct
26 Correct 3 ms 716 KB Output is correct
27 Correct 14 ms 1100 KB Output is correct
28 Correct 15 ms 1016 KB Output is correct
29 Correct 14 ms 1128 KB Output is correct
30 Correct 14 ms 1140 KB Output is correct
31 Correct 14 ms 1136 KB Output is correct
32 Correct 14 ms 1136 KB Output is correct
33 Correct 3 ms 844 KB Output is correct
34 Correct 4 ms 972 KB Output is correct
35 Correct 12 ms 972 KB Output is correct
36 Correct 14 ms 1160 KB Output is correct
37 Correct 5 ms 844 KB Output is correct
38 Correct 8 ms 972 KB Output is correct
39 Correct 543 ms 26524 KB Output is correct
40 Correct 537 ms 26132 KB Output is correct
41 Correct 580 ms 26576 KB Output is correct
42 Correct 616 ms 26564 KB Output is correct
43 Correct 594 ms 26268 KB Output is correct
44 Correct 595 ms 26436 KB Output is correct
45 Correct 80 ms 13760 KB Output is correct
46 Correct 88 ms 13972 KB Output is correct
47 Correct 586 ms 26532 KB Output is correct
48 Correct 596 ms 26704 KB Output is correct
49 Correct 625 ms 26668 KB Output is correct
50 Correct 632 ms 26716 KB Output is correct
51 Correct 382 ms 20952 KB Output is correct
52 Correct 437 ms 25732 KB Output is correct
53 Correct 438 ms 21936 KB Output is correct
54 Correct 453 ms 25156 KB Output is correct
55 Execution timed out 1092 ms 97116 KB Time limit exceeded
56 Halted 0 ms 0 KB -