답안 #567469

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
567469 2022-05-23T14:42:10 Z Drew_ 푸드 코트 (JOI21_foodcourt) C++17
68 / 100
784 ms 44604 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define ii pair<int, int>
#define pl pair<ll, ll>
#define f1 first
#define s2 second

const int MAX = 250069;
const ll inf = 1e18 + 69;

struct Segtree1
{
	int n;
	ll st[1 << 19], lz1[1 << 19], lz2[1 << 19];

	Segtree1(int _n) : n(_n) {}
	inline void propagate(int node, int l, int r)
	{
		st[node] = max(st[node] + lz1[node], lz2[node]);
		if (l < r)
		{
			lz1[node << 1] += lz1[node];
			lz2[node << 1] += lz1[node];
			lz2[node << 1] = max(lz2[node << 1], lz2[node]);

			lz1[node << 1 | 1] += lz1[node];
			lz2[node << 1 | 1] += lz1[node];
			lz2[node << 1 | 1] = max(lz2[node << 1 | 1], lz2[node]);
		}
		lz1[node] = lz2[node] = 0;
	}

	inline void add(int p, int q, ll val)
	{
		const auto add_ = [&](const auto &self, int node, int l, int r) -> void
		{
			propagate(node, l, r);
			if (l > q || r < p)
				return;
			if (p <= l && r <= q)
			{
				lz1[node] += val; lz2[node] += val;
				propagate(node, l, r);
				return;
			}
			int mid = (l + r) >> 1;
			self(self, node << 1, l, mid);
			self(self, node << 1 | 1, mid+1, r);
			st[node] = max(st[node << 1], st[node << 1 | 1]);
		};
		add_(add_, 1, 1, n);
	}

	// Ai = max(Ai, val) for i in [p <= i <= q]
	inline void update(int p, int q, ll val)
	{
		const auto update_ = [&](const auto &self, int node, int l, int r) -> void
		{
			propagate(node, l, r);
			if (l > q || r < p)
				return;
			if (p <= l && r <= q)
			{
				lz2[node] = max(lz2[node], (ll)val);
				propagate(node, l, r);
				return;
			}
			int mid = (l + r) >> 1;
			self(self, node << 1, l, mid);
			self(self, node << 1 | 1, mid+1, r);
			st[node] = max(st[node << 1], st[node << 1 | 1]);
		};
		update_(update_, 1, 1, n);
	}

	inline ll query(ll p)
	{
		const auto query_ = [&](const auto &self, int node, int l, int r) -> ll
		{
			propagate(node, l, r);
			if (l > p || r < p)
				return -1;
			if (p <= l && r <= p)
				return st[node];
			int mid = (l + r) >> 1;
			return max(self(self, node << 1, l, mid), self(self, node << 1 | 1, mid+1, r));		
		};	
		return query_(query_, 1, 1, n);
	}
};

struct Segtree2
{
	int n;
	ll st[1 << 19], lz[1 << 19];

	Segtree2 (int _n) : n(_n) {}
	inline void propagate(int node, int l, int r)
	{
		st[node] += lz[node];
		if (l < r)
		{
			lz[node << 1] += lz[node];
			lz[node << 1 | 1] += lz[node];
		}
		lz[node] = 0;
	}

	inline void add(int p, int q, ll val)
	{
		const auto add_ = [&](const auto &self, int node, int l, int r) -> void
		{
			propagate(node, l, r);
			if (l > q || r < p)
				return;
			if (p <= l && r <= q)
			{
				lz[node] += val;
				propagate(node, l, r);
				return;
			}
			int mid = (l + r) >> 1;
			self(self, node << 1, l, mid);
			self(self, node << 1 | 1, mid+1, r);
			st[node] = min(st[node << 1], st[node << 1 | 1]);
		};
		add_(add_, 1, 0, n-1);
	}

	inline void modify(int p, ll val)
	{
		const auto modify_ = [&](const auto &self, int node, int l, int r) -> void
		{
			propagate(node, l, r);
			if (l > p || r < p)
				return;
			if (p <= l && r <= p)
			{
				st[node] = val;
				return;
			}

			int mid = (l + r) >> 1;
			self(self, node << 1, l, mid);
			self(self, node << 1 | 1, mid+1, r);
			st[node] = min(st[node << 1], st[node << 1 | 1]);
		};
		modify_(modify_, 1, 0, n-1);
	}

	inline int query()
	{
		const auto query_ = [&](const auto &self, int node, int l, int r) -> int
		{
			propagate(node, l, r);
			if (l == r)
				return l;

			int mid = (l + r) >> 1;
			propagate(node << 1, l, mid);
			if (st[node << 1] <= 0)
				return self(self, node << 1, l, mid);
			return self(self, node << 1 | 1, mid+1, r);
		};
		return query_(query_, 1, 0, n-1);
	}
};

int main()
{
	ios :: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int N, M, Q;
	cin >> N >> M >> Q;

	int ty[MAX], L[MAX], R[MAX];
	ll A[MAX], B[MAX];
	for (int i = 0; i < Q; ++i)
	{
		cin >> ty[i];
		if (ty[i] == 1) cin >> L[i] >> R[i] >> B[i] >> A[i];
		else if (ty[i] == 2) cin >> L[i] >> R[i] >> A[i];
		else cin >> A[i] >> B[i];
	}

	int askQ = 0;
	ll ans[MAX];
	vector<pair<pl, int>> query;

	Segtree1 st1(N), All(N);
	for (int i = 0; i < Q; ++i)
	{
		if (ty[i] == 1)
		{
			st1.add(L[i], R[i], A[i]);
			All.add(L[i], R[i], A[i]);
		}
		else if (ty[i] == 2)
		{
			st1.add(L[i], R[i], -A[i]);
			st1.update(L[i], R[i], 0);
		}
		else
		{
			ll cur = st1.query(A[i]);
			ll tot = All.query(A[i]);

			if (cur >= B[i]) query.pb({{A[i], tot - cur + B[i]}, askQ++});
			else ans[askQ++] = 0;
		}
	}

	sort(query.begin(), query.end());

	Segtree2 st2((int)query.size());
	for (int i = 0; i < (int)query.size(); ++i)
		st2.modify(i, query[i].f1.s2);

	for (int i = 0; i < Q; ++i)
	{
		if (ty[i] == 1)
		{
			int l = (int)(lower_bound(query.begin(), query.end(), mp(mp((ll)L[i], 0ll), 0)) - query.begin());
			int r = -1 + (int)(upper_bound(query.begin(), query.end(), mp(mp((ll)R[i], inf), 0)) - query.begin());
			
			if (l <= r)
				st2.add(l, r, -A[i]);
			
			while (st2.st[1] <= 0)
			{
				int id = st2.query();
				ans[query[id].s2] = B[i];
				st2.modify(id, inf);
			}
		}
	}

	for (int i = 0; i < askQ; ++i)
		cout << ans[i] << '\n';

	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 41940 KB Output is correct
2 Correct 21 ms 41992 KB Output is correct
3 Correct 21 ms 41940 KB Output is correct
4 Correct 20 ms 41996 KB Output is correct
5 Correct 18 ms 41880 KB Output is correct
6 Correct 18 ms 41940 KB Output is correct
7 Correct 27 ms 41940 KB Output is correct
8 Correct 20 ms 41932 KB Output is correct
9 Correct 20 ms 41916 KB Output is correct
10 Correct 21 ms 41972 KB Output is correct
11 Correct 20 ms 41896 KB Output is correct
12 Correct 20 ms 41996 KB Output is correct
13 Correct 21 ms 41912 KB Output is correct
14 Correct 18 ms 41992 KB Output is correct
15 Correct 19 ms 41940 KB Output is correct
16 Correct 20 ms 42044 KB Output is correct
17 Correct 20 ms 41988 KB Output is correct
18 Correct 23 ms 41928 KB Output is correct
19 Correct 21 ms 41940 KB Output is correct
20 Correct 19 ms 41968 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 41940 KB Output is correct
2 Correct 21 ms 41992 KB Output is correct
3 Correct 21 ms 41940 KB Output is correct
4 Correct 20 ms 41996 KB Output is correct
5 Correct 18 ms 41880 KB Output is correct
6 Correct 18 ms 41940 KB Output is correct
7 Correct 27 ms 41940 KB Output is correct
8 Correct 20 ms 41932 KB Output is correct
9 Correct 20 ms 41916 KB Output is correct
10 Correct 21 ms 41972 KB Output is correct
11 Correct 20 ms 41896 KB Output is correct
12 Correct 20 ms 41996 KB Output is correct
13 Correct 21 ms 41912 KB Output is correct
14 Correct 18 ms 41992 KB Output is correct
15 Correct 19 ms 41940 KB Output is correct
16 Correct 20 ms 42044 KB Output is correct
17 Correct 20 ms 41988 KB Output is correct
18 Correct 23 ms 41928 KB Output is correct
19 Correct 21 ms 41940 KB Output is correct
20 Correct 19 ms 41968 KB Output is correct
21 Correct 22 ms 41996 KB Output is correct
22 Correct 22 ms 41932 KB Output is correct
23 Correct 22 ms 41940 KB Output is correct
24 Correct 24 ms 41992 KB Output is correct
25 Correct 19 ms 41940 KB Output is correct
26 Correct 20 ms 41964 KB Output is correct
27 Correct 24 ms 41956 KB Output is correct
28 Correct 21 ms 41952 KB Output is correct
29 Correct 22 ms 42000 KB Output is correct
30 Correct 22 ms 41936 KB Output is correct
31 Correct 21 ms 41940 KB Output is correct
32 Correct 20 ms 41940 KB Output is correct
33 Correct 18 ms 42000 KB Output is correct
34 Correct 20 ms 41980 KB Output is correct
35 Correct 19 ms 41940 KB Output is correct
36 Correct 22 ms 41904 KB Output is correct
37 Correct 20 ms 41952 KB Output is correct
38 Correct 22 ms 41932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 123 ms 41940 KB Output is correct
2 Correct 128 ms 43296 KB Output is correct
3 Correct 177 ms 43096 KB Output is correct
4 Correct 128 ms 43096 KB Output is correct
5 Correct 126 ms 43212 KB Output is correct
6 Correct 125 ms 43172 KB Output is correct
7 Correct 39 ms 42980 KB Output is correct
8 Correct 40 ms 43020 KB Output is correct
9 Correct 166 ms 43312 KB Output is correct
10 Correct 132 ms 43192 KB Output is correct
11 Correct 128 ms 43220 KB Output is correct
12 Correct 122 ms 43184 KB Output is correct
13 Correct 137 ms 43244 KB Output is correct
14 Correct 127 ms 43284 KB Output is correct
15 Correct 112 ms 43332 KB Output is correct
16 Correct 143 ms 43212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 784 ms 43640 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 41940 KB Output is correct
2 Correct 21 ms 41992 KB Output is correct
3 Correct 21 ms 41940 KB Output is correct
4 Correct 20 ms 41996 KB Output is correct
5 Correct 18 ms 41880 KB Output is correct
6 Correct 18 ms 41940 KB Output is correct
7 Correct 27 ms 41940 KB Output is correct
8 Correct 20 ms 41932 KB Output is correct
9 Correct 20 ms 41916 KB Output is correct
10 Correct 21 ms 41972 KB Output is correct
11 Correct 20 ms 41896 KB Output is correct
12 Correct 20 ms 41996 KB Output is correct
13 Correct 21 ms 41912 KB Output is correct
14 Correct 18 ms 41992 KB Output is correct
15 Correct 19 ms 41940 KB Output is correct
16 Correct 20 ms 42044 KB Output is correct
17 Correct 20 ms 41988 KB Output is correct
18 Correct 23 ms 41928 KB Output is correct
19 Correct 21 ms 41940 KB Output is correct
20 Correct 19 ms 41968 KB Output is correct
21 Correct 123 ms 41940 KB Output is correct
22 Correct 128 ms 43296 KB Output is correct
23 Correct 177 ms 43096 KB Output is correct
24 Correct 128 ms 43096 KB Output is correct
25 Correct 126 ms 43212 KB Output is correct
26 Correct 125 ms 43172 KB Output is correct
27 Correct 39 ms 42980 KB Output is correct
28 Correct 40 ms 43020 KB Output is correct
29 Correct 166 ms 43312 KB Output is correct
30 Correct 132 ms 43192 KB Output is correct
31 Correct 128 ms 43220 KB Output is correct
32 Correct 122 ms 43184 KB Output is correct
33 Correct 137 ms 43244 KB Output is correct
34 Correct 127 ms 43284 KB Output is correct
35 Correct 112 ms 43332 KB Output is correct
36 Correct 143 ms 43212 KB Output is correct
37 Correct 179 ms 43344 KB Output is correct
38 Correct 149 ms 43384 KB Output is correct
39 Correct 38 ms 42892 KB Output is correct
40 Correct 45 ms 42996 KB Output is correct
41 Correct 212 ms 43500 KB Output is correct
42 Correct 169 ms 43528 KB Output is correct
43 Correct 186 ms 43520 KB Output is correct
44 Correct 182 ms 43504 KB Output is correct
45 Correct 173 ms 43516 KB Output is correct
46 Correct 180 ms 43488 KB Output is correct
47 Correct 82 ms 43356 KB Output is correct
48 Correct 165 ms 43480 KB Output is correct
49 Correct 139 ms 42988 KB Output is correct
50 Correct 154 ms 43168 KB Output is correct
51 Correct 187 ms 43608 KB Output is correct
52 Correct 192 ms 43572 KB Output is correct
53 Correct 104 ms 42888 KB Output is correct
54 Correct 151 ms 43228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 202 ms 42860 KB Output is correct
2 Correct 177 ms 44360 KB Output is correct
3 Correct 186 ms 44604 KB Output is correct
4 Correct 141 ms 43676 KB Output is correct
5 Correct 178 ms 44340 KB Output is correct
6 Correct 224 ms 44492 KB Output is correct
7 Correct 55 ms 43940 KB Output is correct
8 Correct 57 ms 43832 KB Output is correct
9 Correct 89 ms 44364 KB Output is correct
10 Correct 126 ms 43632 KB Output is correct
11 Correct 180 ms 44492 KB Output is correct
12 Correct 200 ms 44392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 41940 KB Output is correct
2 Correct 21 ms 41992 KB Output is correct
3 Correct 21 ms 41940 KB Output is correct
4 Correct 20 ms 41996 KB Output is correct
5 Correct 18 ms 41880 KB Output is correct
6 Correct 18 ms 41940 KB Output is correct
7 Correct 27 ms 41940 KB Output is correct
8 Correct 20 ms 41932 KB Output is correct
9 Correct 20 ms 41916 KB Output is correct
10 Correct 21 ms 41972 KB Output is correct
11 Correct 20 ms 41896 KB Output is correct
12 Correct 20 ms 41996 KB Output is correct
13 Correct 21 ms 41912 KB Output is correct
14 Correct 18 ms 41992 KB Output is correct
15 Correct 19 ms 41940 KB Output is correct
16 Correct 20 ms 42044 KB Output is correct
17 Correct 20 ms 41988 KB Output is correct
18 Correct 23 ms 41928 KB Output is correct
19 Correct 21 ms 41940 KB Output is correct
20 Correct 19 ms 41968 KB Output is correct
21 Correct 22 ms 41996 KB Output is correct
22 Correct 22 ms 41932 KB Output is correct
23 Correct 22 ms 41940 KB Output is correct
24 Correct 24 ms 41992 KB Output is correct
25 Correct 19 ms 41940 KB Output is correct
26 Correct 20 ms 41964 KB Output is correct
27 Correct 24 ms 41956 KB Output is correct
28 Correct 21 ms 41952 KB Output is correct
29 Correct 22 ms 42000 KB Output is correct
30 Correct 22 ms 41936 KB Output is correct
31 Correct 21 ms 41940 KB Output is correct
32 Correct 20 ms 41940 KB Output is correct
33 Correct 18 ms 42000 KB Output is correct
34 Correct 20 ms 41980 KB Output is correct
35 Correct 19 ms 41940 KB Output is correct
36 Correct 22 ms 41904 KB Output is correct
37 Correct 20 ms 41952 KB Output is correct
38 Correct 22 ms 41932 KB Output is correct
39 Correct 123 ms 41940 KB Output is correct
40 Correct 128 ms 43296 KB Output is correct
41 Correct 177 ms 43096 KB Output is correct
42 Correct 128 ms 43096 KB Output is correct
43 Correct 126 ms 43212 KB Output is correct
44 Correct 125 ms 43172 KB Output is correct
45 Correct 39 ms 42980 KB Output is correct
46 Correct 40 ms 43020 KB Output is correct
47 Correct 166 ms 43312 KB Output is correct
48 Correct 132 ms 43192 KB Output is correct
49 Correct 128 ms 43220 KB Output is correct
50 Correct 122 ms 43184 KB Output is correct
51 Correct 137 ms 43244 KB Output is correct
52 Correct 127 ms 43284 KB Output is correct
53 Correct 112 ms 43332 KB Output is correct
54 Correct 143 ms 43212 KB Output is correct
55 Correct 179 ms 43344 KB Output is correct
56 Correct 149 ms 43384 KB Output is correct
57 Correct 38 ms 42892 KB Output is correct
58 Correct 45 ms 42996 KB Output is correct
59 Correct 212 ms 43500 KB Output is correct
60 Correct 169 ms 43528 KB Output is correct
61 Correct 186 ms 43520 KB Output is correct
62 Correct 182 ms 43504 KB Output is correct
63 Correct 173 ms 43516 KB Output is correct
64 Correct 180 ms 43488 KB Output is correct
65 Correct 82 ms 43356 KB Output is correct
66 Correct 165 ms 43480 KB Output is correct
67 Correct 139 ms 42988 KB Output is correct
68 Correct 154 ms 43168 KB Output is correct
69 Correct 187 ms 43608 KB Output is correct
70 Correct 192 ms 43572 KB Output is correct
71 Correct 104 ms 42888 KB Output is correct
72 Correct 151 ms 43228 KB Output is correct
73 Correct 202 ms 42860 KB Output is correct
74 Correct 177 ms 44360 KB Output is correct
75 Correct 186 ms 44604 KB Output is correct
76 Correct 141 ms 43676 KB Output is correct
77 Correct 178 ms 44340 KB Output is correct
78 Correct 224 ms 44492 KB Output is correct
79 Correct 55 ms 43940 KB Output is correct
80 Correct 57 ms 43832 KB Output is correct
81 Correct 89 ms 44364 KB Output is correct
82 Correct 126 ms 43632 KB Output is correct
83 Correct 180 ms 44492 KB Output is correct
84 Correct 200 ms 44392 KB Output is correct
85 Correct 220 ms 43844 KB Output is correct
86 Correct 178 ms 44024 KB Output is correct
87 Correct 196 ms 43812 KB Output is correct
88 Correct 192 ms 44020 KB Output is correct
89 Correct 119 ms 43384 KB Output is correct
90 Correct 191 ms 44044 KB Output is correct
91 Correct 158 ms 43668 KB Output is correct
92 Correct 132 ms 43648 KB Output is correct
93 Correct 172 ms 44004 KB Output is correct
94 Correct 216 ms 44136 KB Output is correct
95 Correct 171 ms 43960 KB Output is correct
96 Correct 173 ms 44028 KB Output is correct
97 Correct 175 ms 43928 KB Output is correct
98 Correct 172 ms 43780 KB Output is correct
99 Correct 70 ms 43844 KB Output is correct
100 Correct 134 ms 43652 KB Output is correct
101 Correct 153 ms 43940 KB Output is correct
102 Correct 134 ms 43912 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 41940 KB Output is correct
2 Correct 21 ms 41992 KB Output is correct
3 Correct 21 ms 41940 KB Output is correct
4 Correct 20 ms 41996 KB Output is correct
5 Correct 18 ms 41880 KB Output is correct
6 Correct 18 ms 41940 KB Output is correct
7 Correct 27 ms 41940 KB Output is correct
8 Correct 20 ms 41932 KB Output is correct
9 Correct 20 ms 41916 KB Output is correct
10 Correct 21 ms 41972 KB Output is correct
11 Correct 20 ms 41896 KB Output is correct
12 Correct 20 ms 41996 KB Output is correct
13 Correct 21 ms 41912 KB Output is correct
14 Correct 18 ms 41992 KB Output is correct
15 Correct 19 ms 41940 KB Output is correct
16 Correct 20 ms 42044 KB Output is correct
17 Correct 20 ms 41988 KB Output is correct
18 Correct 23 ms 41928 KB Output is correct
19 Correct 21 ms 41940 KB Output is correct
20 Correct 19 ms 41968 KB Output is correct
21 Correct 22 ms 41996 KB Output is correct
22 Correct 22 ms 41932 KB Output is correct
23 Correct 22 ms 41940 KB Output is correct
24 Correct 24 ms 41992 KB Output is correct
25 Correct 19 ms 41940 KB Output is correct
26 Correct 20 ms 41964 KB Output is correct
27 Correct 24 ms 41956 KB Output is correct
28 Correct 21 ms 41952 KB Output is correct
29 Correct 22 ms 42000 KB Output is correct
30 Correct 22 ms 41936 KB Output is correct
31 Correct 21 ms 41940 KB Output is correct
32 Correct 20 ms 41940 KB Output is correct
33 Correct 18 ms 42000 KB Output is correct
34 Correct 20 ms 41980 KB Output is correct
35 Correct 19 ms 41940 KB Output is correct
36 Correct 22 ms 41904 KB Output is correct
37 Correct 20 ms 41952 KB Output is correct
38 Correct 22 ms 41932 KB Output is correct
39 Correct 123 ms 41940 KB Output is correct
40 Correct 128 ms 43296 KB Output is correct
41 Correct 177 ms 43096 KB Output is correct
42 Correct 128 ms 43096 KB Output is correct
43 Correct 126 ms 43212 KB Output is correct
44 Correct 125 ms 43172 KB Output is correct
45 Correct 39 ms 42980 KB Output is correct
46 Correct 40 ms 43020 KB Output is correct
47 Correct 166 ms 43312 KB Output is correct
48 Correct 132 ms 43192 KB Output is correct
49 Correct 128 ms 43220 KB Output is correct
50 Correct 122 ms 43184 KB Output is correct
51 Correct 137 ms 43244 KB Output is correct
52 Correct 127 ms 43284 KB Output is correct
53 Correct 112 ms 43332 KB Output is correct
54 Correct 143 ms 43212 KB Output is correct
55 Incorrect 784 ms 43640 KB Output isn't correct
56 Halted 0 ms 0 KB -