Submission #421962

# Submission time Handle Problem Language Result Execution time Memory
421962 2021-06-09T14:14:08 Z pavement Food Court (JOI21_foodcourt) C++17
68 / 100
847 ms 210020 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif
#define int long long
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define g0(a) get<0>(a)
#define g1(a) get<1>(a)
#define g2(a) get<2>(a)
#define g3(a) get<3>(a)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef double db;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef tree<iii, null_type, greater<iii>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

void read(int &v) {
	v = 0;
	char ch = getchar_unlocked();
	for (; ch < '0' || ch > '9'; ch = getchar_unlocked());
	for (; '0' <= ch && ch <= '9'; ch = getchar_unlocked())
		v = (v << 3ll) + (v << 1ll) + (ch & 15ll);
}

int N, M, Q, T, L, R, C, K, A, curq, q1, B, out[100005], ft[250005];
iiii vq1[250005];

struct node {
	node *left, *right;
	int S, E, val, pv, pmx;
	bool hasmx;
	node(int _s, int _e) : S(_s), E(_e),val(0), pv(0), pmx(-1e18), hasmx(0) {
		if (S == E) return;
		int M = (S + E) >> 1;
		left = new node(S, M);
		right = new node(M + 1, E);
	}
	void add_prop(bool t, int x) {
		if (t == 0) {
			pv += x;
			if (hasmx) pmx += x;
		} else {
			pmx = max(pmx, x);
			hasmx = 1;
		}
	}
	void prop() {
		if (S == E) return;
		left->val += pv;
		right->val += pv;
		left->add_prop(0, pv);
		right->add_prop(0, pv);
		pv = 0;
		if (hasmx) {
			left->val = max(left->val, pmx);
			right->val = max(right->val, pmx);
			left->add_prop(1, pmx);
			right->add_prop(1, pmx);
			pmx = -1e18;
		} else assert(pmx == -1e18);
		hasmx = 0;
	}
	void add(int l, int r, int v) {
		if (l > E || r < S) return;
		if (l <= S && E <= r) {
			add_prop(0, v);
			val += v;
			return;
		}
		prop();
		left->add(l, r, v);
		right->add(l, r, v);
	}
	int qry(int p) {
		if (S == E) return val;
		int M = (S + E) >> 1;
		prop();
		if (p <= M) return left->qry(p);
		else return right->qry(p);
	}
} *root;

inline int ls(int x) { return x & -x; }

void upd(int l, int r, int v) {
	for (; l <= N; l += ls(l)) ft[l] += v;
	for (r++; r <= N; r += ls(r)) ft[r] -= v;
}

int qry(int p) {
	int r = 0;
	for (; p; p -= ls(p)) r += ft[p];
	return r;
}

struct node2 {
	node2 *left, *right;
	int S, E, pos, pv;
	vector<ii> val;
	iii mv;
	node2(int _s, int _e) : S(_s), E(_e), pos(0), pv(0) {
		mv = mt(1e18, -1, -1);
		if (S == E) return;
		int M = (S + E) >> 1;
		left = new node2(S, M);
		right = new node2(M + 1, E);
	}
	void prop() {
		if (S == E || !pv) return;
		g0(left->mv) += pv;
		left->pv += pv;
		g0(right->mv) += pv;
		right->pv += pv;
		pv = 0;
	}
	void upd(int p, int a, int b) {
		if (S == E) {
			val.eb(a, b);
			return;
		}
		int M = (S + E) >> 1;
		prop();
		if (p <= M) left->upd(p, a, b);
		else right->upd(p, a, b);
	}
	void add(int l, int r, int v) {
		if (l > E || r < S) return;
		if (l <= S && E <= r) {
			g0(mv) += v;
			pv += v;
			return;
		}
		prop();
		left->add(l, r, v);
		right->add(l, r, v);
		mv = min(left->mv, right->mv);
	}
	void sortall() {
		if (S == E) {
			sort(val.begin(), val.end());
			if (!val.empty()) mv = mt(val[0].first, S, val[0].second);
			return;
		}
		prop();
		left->sortall();
		right->sortall();
		mv = min(left->mv, right->mv);
	}
	void del(int p) {
		if (S == E) {
			assert(pos < val.size());
			pos++;
			if (pos < val.size()) mv = mt(val[pos].first + pv, S, val[pos].second);
			else mv = mt(1e18, -1, -1);
			return;
		}
		int M = (S + E) >> 1;
		prop();
		if (p <= M) left->del(p);
		else right->del(p);
		mv = min(left->mv, right->mv);
	}
} *root2;

main() {
	read(N);
	read(M);
	read(Q);
	root = new node(1, N);
	root2 = new node2(1, N);
	for (int i = 1; i <= Q; i++) {
		read(T);
		if (T == 1) {
			read(L);
			read(R);
			read(C);
			read(K);
			q1++;
			vq1[q1] = mt(L, R, C, K);
			root->add(L, R, K);
			upd(L, R, K);
		} else if (T == 2) {
			read(L);
			read(R);
			read(K);
			root->add(L, R, -K);
			root->val = max(0ll, root->val);
			root->add_prop(1, 0);
		} else {
			read(A);
			read(B);
			curq++;
			int sz = root->qry(A), tmp = qry(A);
			assert(sz <= tmp);
			if (sz >= B) root2->upd(A, tmp - (sz - B), curq);
		}
	}
	root2->sortall();
	for (int i = 1; i <= q1; i++) {
		tie(L, R, C, K) = vq1[i];
		root2->add(L, R, -K);
		while (g0(root2->mv) <= 0) {
			out[g2(root2->mv)] = C;
			root2->del(g1(root2->mv));
		}
	}
	for (int i = 1; i <= curq; i++) printf("%lld\n", out[i]);
}

Compilation message

In file included from /usr/include/c++/10/ext/pb_ds/detail/pat_trie_/pat_trie_.hpp:45,
                 from /usr/include/c++/10/ext/pb_ds/detail/container_base_dispatch.hpp:90,
                 from /usr/include/c++/10/ext/pb_ds/assoc_container.hpp:48,
                 from foodcourt.cpp:2:
foodcourt.cpp: In member function 'void node2::del(long long int)':
foodcourt.cpp:162:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  162 |    assert(pos < val.size());
      |           ~~~~^~~~~~~~~~~~
foodcourt.cpp:164:12: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  164 |    if (pos < val.size()) mv = mt(val[pos].first + pv, S, val[pos].second);
      |        ~~~~^~~~~~~~~~~~
foodcourt.cpp: At global scope:
foodcourt.cpp:176:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  176 | main() {
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 844 KB Output is correct
2 Correct 3 ms 1064 KB Output is correct
3 Correct 3 ms 972 KB Output is correct
4 Correct 3 ms 1100 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 3 ms 1100 KB Output is correct
8 Correct 3 ms 1120 KB Output is correct
9 Correct 3 ms 1100 KB Output is correct
10 Correct 4 ms 1100 KB Output is correct
11 Correct 4 ms 1100 KB Output is correct
12 Correct 3 ms 1100 KB Output is correct
13 Correct 2 ms 972 KB Output is correct
14 Correct 2 ms 1100 KB Output is correct
15 Correct 2 ms 1080 KB Output is correct
16 Correct 3 ms 1100 KB Output is correct
17 Correct 3 ms 844 KB Output is correct
18 Correct 3 ms 1100 KB Output is correct
19 Correct 3 ms 956 KB Output is correct
20 Correct 3 ms 1128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 844 KB Output is correct
2 Correct 3 ms 1064 KB Output is correct
3 Correct 3 ms 972 KB Output is correct
4 Correct 3 ms 1100 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 3 ms 1100 KB Output is correct
8 Correct 3 ms 1120 KB Output is correct
9 Correct 3 ms 1100 KB Output is correct
10 Correct 4 ms 1100 KB Output is correct
11 Correct 4 ms 1100 KB Output is correct
12 Correct 3 ms 1100 KB Output is correct
13 Correct 2 ms 972 KB Output is correct
14 Correct 2 ms 1100 KB Output is correct
15 Correct 2 ms 1080 KB Output is correct
16 Correct 3 ms 1100 KB Output is correct
17 Correct 3 ms 844 KB Output is correct
18 Correct 3 ms 1100 KB Output is correct
19 Correct 3 ms 956 KB Output is correct
20 Correct 3 ms 1128 KB Output is correct
21 Correct 3 ms 1084 KB Output is correct
22 Correct 3 ms 1100 KB Output is correct
23 Correct 3 ms 844 KB Output is correct
24 Correct 3 ms 1172 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 4 ms 1088 KB Output is correct
28 Correct 3 ms 1100 KB Output is correct
29 Correct 4 ms 1100 KB Output is correct
30 Correct 3 ms 1168 KB Output is correct
31 Correct 4 ms 1100 KB Output is correct
32 Correct 4 ms 1084 KB Output is correct
33 Correct 2 ms 972 KB Output is correct
34 Correct 2 ms 1100 KB Output is correct
35 Correct 3 ms 948 KB Output is correct
36 Correct 3 ms 1048 KB Output is correct
37 Correct 2 ms 972 KB Output is correct
38 Correct 3 ms 1100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 117 ms 26644 KB Output is correct
2 Correct 112 ms 26872 KB Output is correct
3 Correct 126 ms 26544 KB Output is correct
4 Correct 104 ms 26564 KB Output is correct
5 Correct 121 ms 27056 KB Output is correct
6 Correct 124 ms 27040 KB Output is correct
7 Correct 8 ms 1904 KB Output is correct
8 Correct 10 ms 1812 KB Output is correct
9 Correct 123 ms 26840 KB Output is correct
10 Correct 108 ms 26744 KB Output is correct
11 Correct 107 ms 26808 KB Output is correct
12 Correct 115 ms 26732 KB Output is correct
13 Correct 112 ms 19028 KB Output is correct
14 Correct 114 ms 27228 KB Output is correct
15 Correct 96 ms 19748 KB Output is correct
16 Correct 123 ms 27776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 773 ms 91768 KB Output is correct
2 Correct 574 ms 79400 KB Output is correct
3 Correct 828 ms 102060 KB Output is correct
4 Correct 658 ms 100508 KB Output is correct
5 Correct 620 ms 77428 KB Output is correct
6 Correct 847 ms 102960 KB Output is correct
7 Correct 42 ms 5740 KB Output is correct
8 Correct 42 ms 5700 KB Output is correct
9 Runtime error 706 ms 210020 KB Execution killed with signal 11
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 844 KB Output is correct
2 Correct 3 ms 1064 KB Output is correct
3 Correct 3 ms 972 KB Output is correct
4 Correct 3 ms 1100 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 3 ms 1100 KB Output is correct
8 Correct 3 ms 1120 KB Output is correct
9 Correct 3 ms 1100 KB Output is correct
10 Correct 4 ms 1100 KB Output is correct
11 Correct 4 ms 1100 KB Output is correct
12 Correct 3 ms 1100 KB Output is correct
13 Correct 2 ms 972 KB Output is correct
14 Correct 2 ms 1100 KB Output is correct
15 Correct 2 ms 1080 KB Output is correct
16 Correct 3 ms 1100 KB Output is correct
17 Correct 3 ms 844 KB Output is correct
18 Correct 3 ms 1100 KB Output is correct
19 Correct 3 ms 956 KB Output is correct
20 Correct 3 ms 1128 KB Output is correct
21 Correct 117 ms 26644 KB Output is correct
22 Correct 112 ms 26872 KB Output is correct
23 Correct 126 ms 26544 KB Output is correct
24 Correct 104 ms 26564 KB Output is correct
25 Correct 121 ms 27056 KB Output is correct
26 Correct 124 ms 27040 KB Output is correct
27 Correct 8 ms 1904 KB Output is correct
28 Correct 10 ms 1812 KB Output is correct
29 Correct 123 ms 26840 KB Output is correct
30 Correct 108 ms 26744 KB Output is correct
31 Correct 107 ms 26808 KB Output is correct
32 Correct 115 ms 26732 KB Output is correct
33 Correct 112 ms 19028 KB Output is correct
34 Correct 114 ms 27228 KB Output is correct
35 Correct 96 ms 19748 KB Output is correct
36 Correct 123 ms 27776 KB Output is correct
37 Correct 154 ms 24628 KB Output is correct
38 Correct 145 ms 24548 KB Output is correct
39 Correct 6 ms 1864 KB Output is correct
40 Correct 11 ms 1996 KB Output is correct
41 Correct 165 ms 27192 KB Output is correct
42 Correct 160 ms 27204 KB Output is correct
43 Correct 159 ms 27100 KB Output is correct
44 Correct 158 ms 27148 KB Output is correct
45 Correct 166 ms 27148 KB Output is correct
46 Correct 161 ms 27144 KB Output is correct
47 Correct 75 ms 26668 KB Output is correct
48 Correct 147 ms 26688 KB Output is correct
49 Correct 118 ms 18884 KB Output is correct
50 Correct 148 ms 26416 KB Output is correct
51 Correct 160 ms 27172 KB Output is correct
52 Correct 160 ms 27116 KB Output is correct
53 Correct 110 ms 24036 KB Output is correct
54 Correct 140 ms 27936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 155 ms 26968 KB Output is correct
2 Correct 165 ms 24088 KB Output is correct
3 Correct 176 ms 28296 KB Output is correct
4 Correct 128 ms 26040 KB Output is correct
5 Correct 167 ms 27176 KB Output is correct
6 Correct 170 ms 28304 KB Output is correct
7 Correct 14 ms 2756 KB Output is correct
8 Correct 15 ms 2632 KB Output is correct
9 Correct 88 ms 27860 KB Output is correct
10 Correct 122 ms 23972 KB Output is correct
11 Correct 126 ms 27844 KB Output is correct
12 Correct 131 ms 27828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 844 KB Output is correct
2 Correct 3 ms 1064 KB Output is correct
3 Correct 3 ms 972 KB Output is correct
4 Correct 3 ms 1100 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 3 ms 1100 KB Output is correct
8 Correct 3 ms 1120 KB Output is correct
9 Correct 3 ms 1100 KB Output is correct
10 Correct 4 ms 1100 KB Output is correct
11 Correct 4 ms 1100 KB Output is correct
12 Correct 3 ms 1100 KB Output is correct
13 Correct 2 ms 972 KB Output is correct
14 Correct 2 ms 1100 KB Output is correct
15 Correct 2 ms 1080 KB Output is correct
16 Correct 3 ms 1100 KB Output is correct
17 Correct 3 ms 844 KB Output is correct
18 Correct 3 ms 1100 KB Output is correct
19 Correct 3 ms 956 KB Output is correct
20 Correct 3 ms 1128 KB Output is correct
21 Correct 3 ms 1084 KB Output is correct
22 Correct 3 ms 1100 KB Output is correct
23 Correct 3 ms 844 KB Output is correct
24 Correct 3 ms 1172 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 4 ms 1088 KB Output is correct
28 Correct 3 ms 1100 KB Output is correct
29 Correct 4 ms 1100 KB Output is correct
30 Correct 3 ms 1168 KB Output is correct
31 Correct 4 ms 1100 KB Output is correct
32 Correct 4 ms 1084 KB Output is correct
33 Correct 2 ms 972 KB Output is correct
34 Correct 2 ms 1100 KB Output is correct
35 Correct 3 ms 948 KB Output is correct
36 Correct 3 ms 1048 KB Output is correct
37 Correct 2 ms 972 KB Output is correct
38 Correct 3 ms 1100 KB Output is correct
39 Correct 117 ms 26644 KB Output is correct
40 Correct 112 ms 26872 KB Output is correct
41 Correct 126 ms 26544 KB Output is correct
42 Correct 104 ms 26564 KB Output is correct
43 Correct 121 ms 27056 KB Output is correct
44 Correct 124 ms 27040 KB Output is correct
45 Correct 8 ms 1904 KB Output is correct
46 Correct 10 ms 1812 KB Output is correct
47 Correct 123 ms 26840 KB Output is correct
48 Correct 108 ms 26744 KB Output is correct
49 Correct 107 ms 26808 KB Output is correct
50 Correct 115 ms 26732 KB Output is correct
51 Correct 112 ms 19028 KB Output is correct
52 Correct 114 ms 27228 KB Output is correct
53 Correct 96 ms 19748 KB Output is correct
54 Correct 123 ms 27776 KB Output is correct
55 Correct 154 ms 24628 KB Output is correct
56 Correct 145 ms 24548 KB Output is correct
57 Correct 6 ms 1864 KB Output is correct
58 Correct 11 ms 1996 KB Output is correct
59 Correct 165 ms 27192 KB Output is correct
60 Correct 160 ms 27204 KB Output is correct
61 Correct 159 ms 27100 KB Output is correct
62 Correct 158 ms 27148 KB Output is correct
63 Correct 166 ms 27148 KB Output is correct
64 Correct 161 ms 27144 KB Output is correct
65 Correct 75 ms 26668 KB Output is correct
66 Correct 147 ms 26688 KB Output is correct
67 Correct 118 ms 18884 KB Output is correct
68 Correct 148 ms 26416 KB Output is correct
69 Correct 160 ms 27172 KB Output is correct
70 Correct 160 ms 27116 KB Output is correct
71 Correct 110 ms 24036 KB Output is correct
72 Correct 140 ms 27936 KB Output is correct
73 Correct 155 ms 26968 KB Output is correct
74 Correct 165 ms 24088 KB Output is correct
75 Correct 176 ms 28296 KB Output is correct
76 Correct 128 ms 26040 KB Output is correct
77 Correct 167 ms 27176 KB Output is correct
78 Correct 170 ms 28304 KB Output is correct
79 Correct 14 ms 2756 KB Output is correct
80 Correct 15 ms 2632 KB Output is correct
81 Correct 88 ms 27860 KB Output is correct
82 Correct 122 ms 23972 KB Output is correct
83 Correct 126 ms 27844 KB Output is correct
84 Correct 131 ms 27828 KB Output is correct
85 Correct 138 ms 21956 KB Output is correct
86 Correct 156 ms 27616 KB Output is correct
87 Correct 147 ms 25876 KB Output is correct
88 Correct 187 ms 27728 KB Output is correct
89 Correct 110 ms 21480 KB Output is correct
90 Correct 157 ms 27572 KB Output is correct
91 Correct 138 ms 18860 KB Output is correct
92 Correct 107 ms 19048 KB Output is correct
93 Correct 156 ms 27532 KB Output is correct
94 Correct 169 ms 27456 KB Output is correct
95 Correct 148 ms 25220 KB Output is correct
96 Correct 172 ms 27528 KB Output is correct
97 Correct 170 ms 27460 KB Output is correct
98 Correct 135 ms 19988 KB Output is correct
99 Correct 75 ms 27116 KB Output is correct
100 Correct 97 ms 23128 KB Output is correct
101 Correct 128 ms 27128 KB Output is correct
102 Correct 100 ms 27964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 844 KB Output is correct
2 Correct 3 ms 1064 KB Output is correct
3 Correct 3 ms 972 KB Output is correct
4 Correct 3 ms 1100 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 3 ms 1100 KB Output is correct
8 Correct 3 ms 1120 KB Output is correct
9 Correct 3 ms 1100 KB Output is correct
10 Correct 4 ms 1100 KB Output is correct
11 Correct 4 ms 1100 KB Output is correct
12 Correct 3 ms 1100 KB Output is correct
13 Correct 2 ms 972 KB Output is correct
14 Correct 2 ms 1100 KB Output is correct
15 Correct 2 ms 1080 KB Output is correct
16 Correct 3 ms 1100 KB Output is correct
17 Correct 3 ms 844 KB Output is correct
18 Correct 3 ms 1100 KB Output is correct
19 Correct 3 ms 956 KB Output is correct
20 Correct 3 ms 1128 KB Output is correct
21 Correct 3 ms 1084 KB Output is correct
22 Correct 3 ms 1100 KB Output is correct
23 Correct 3 ms 844 KB Output is correct
24 Correct 3 ms 1172 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 4 ms 1088 KB Output is correct
28 Correct 3 ms 1100 KB Output is correct
29 Correct 4 ms 1100 KB Output is correct
30 Correct 3 ms 1168 KB Output is correct
31 Correct 4 ms 1100 KB Output is correct
32 Correct 4 ms 1084 KB Output is correct
33 Correct 2 ms 972 KB Output is correct
34 Correct 2 ms 1100 KB Output is correct
35 Correct 3 ms 948 KB Output is correct
36 Correct 3 ms 1048 KB Output is correct
37 Correct 2 ms 972 KB Output is correct
38 Correct 3 ms 1100 KB Output is correct
39 Correct 117 ms 26644 KB Output is correct
40 Correct 112 ms 26872 KB Output is correct
41 Correct 126 ms 26544 KB Output is correct
42 Correct 104 ms 26564 KB Output is correct
43 Correct 121 ms 27056 KB Output is correct
44 Correct 124 ms 27040 KB Output is correct
45 Correct 8 ms 1904 KB Output is correct
46 Correct 10 ms 1812 KB Output is correct
47 Correct 123 ms 26840 KB Output is correct
48 Correct 108 ms 26744 KB Output is correct
49 Correct 107 ms 26808 KB Output is correct
50 Correct 115 ms 26732 KB Output is correct
51 Correct 112 ms 19028 KB Output is correct
52 Correct 114 ms 27228 KB Output is correct
53 Correct 96 ms 19748 KB Output is correct
54 Correct 123 ms 27776 KB Output is correct
55 Correct 773 ms 91768 KB Output is correct
56 Correct 574 ms 79400 KB Output is correct
57 Correct 828 ms 102060 KB Output is correct
58 Correct 658 ms 100508 KB Output is correct
59 Correct 620 ms 77428 KB Output is correct
60 Correct 847 ms 102960 KB Output is correct
61 Correct 42 ms 5740 KB Output is correct
62 Correct 42 ms 5700 KB Output is correct
63 Runtime error 706 ms 210020 KB Execution killed with signal 11
64 Halted 0 ms 0 KB -