답안 #567471

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
567471 2022-05-23T14:46:12 Z Drew_ 푸드 코트 (JOI21_foodcourt) C++17
68 / 100
884 ms 43592 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)
	{
		assert(node < (1 << 19));

		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)
	{
		assert(node < (1 << 19));

		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());

	// cerr << "query: \n";
	// for (int i = 0; i < (int)query.size(); ++i)
	// 	cerr << query[i].f1.f1 << " " << query[i].f1.s2 << " " << query[i].s2 << '\n';
	// cerr << '\n';

	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 23 ms 41912 KB Output is correct
2 Correct 27 ms 41860 KB Output is correct
3 Correct 20 ms 41940 KB Output is correct
4 Correct 24 ms 41856 KB Output is correct
5 Correct 18 ms 41924 KB Output is correct
6 Correct 17 ms 41976 KB Output is correct
7 Correct 22 ms 41940 KB Output is correct
8 Correct 20 ms 41940 KB Output is correct
9 Correct 21 ms 41940 KB Output is correct
10 Correct 20 ms 41940 KB Output is correct
11 Correct 19 ms 41892 KB Output is correct
12 Correct 23 ms 41912 KB Output is correct
13 Correct 20 ms 41940 KB Output is correct
14 Correct 18 ms 41896 KB Output is correct
15 Correct 18 ms 41964 KB Output is correct
16 Correct 25 ms 41940 KB Output is correct
17 Correct 20 ms 41852 KB Output is correct
18 Correct 23 ms 41860 KB Output is correct
19 Correct 19 ms 41940 KB Output is correct
20 Correct 28 ms 41932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 41912 KB Output is correct
2 Correct 27 ms 41860 KB Output is correct
3 Correct 20 ms 41940 KB Output is correct
4 Correct 24 ms 41856 KB Output is correct
5 Correct 18 ms 41924 KB Output is correct
6 Correct 17 ms 41976 KB Output is correct
7 Correct 22 ms 41940 KB Output is correct
8 Correct 20 ms 41940 KB Output is correct
9 Correct 21 ms 41940 KB Output is correct
10 Correct 20 ms 41940 KB Output is correct
11 Correct 19 ms 41892 KB Output is correct
12 Correct 23 ms 41912 KB Output is correct
13 Correct 20 ms 41940 KB Output is correct
14 Correct 18 ms 41896 KB Output is correct
15 Correct 18 ms 41964 KB Output is correct
16 Correct 25 ms 41940 KB Output is correct
17 Correct 20 ms 41852 KB Output is correct
18 Correct 23 ms 41860 KB Output is correct
19 Correct 19 ms 41940 KB Output is correct
20 Correct 28 ms 41932 KB Output is correct
21 Correct 20 ms 41940 KB Output is correct
22 Correct 21 ms 41948 KB Output is correct
23 Correct 19 ms 41972 KB Output is correct
24 Correct 21 ms 41884 KB Output is correct
25 Correct 18 ms 41940 KB Output is correct
26 Correct 19 ms 41940 KB Output is correct
27 Correct 27 ms 41936 KB Output is correct
28 Correct 24 ms 41984 KB Output is correct
29 Correct 21 ms 41940 KB Output is correct
30 Correct 23 ms 41868 KB Output is correct
31 Correct 26 ms 41940 KB Output is correct
32 Correct 22 ms 41860 KB Output is correct
33 Correct 25 ms 41952 KB Output is correct
34 Correct 19 ms 41852 KB Output is correct
35 Correct 25 ms 41940 KB Output is correct
36 Correct 23 ms 41924 KB Output is correct
37 Correct 26 ms 41960 KB Output is correct
38 Correct 21 ms 41940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 137 ms 41952 KB Output is correct
2 Correct 150 ms 41940 KB Output is correct
3 Correct 155 ms 41952 KB Output is correct
4 Correct 129 ms 41940 KB Output is correct
5 Correct 141 ms 41940 KB Output is correct
6 Correct 196 ms 41940 KB Output is correct
7 Correct 52 ms 42224 KB Output is correct
8 Correct 45 ms 42320 KB Output is correct
9 Correct 147 ms 41964 KB Output is correct
10 Correct 176 ms 41940 KB Output is correct
11 Correct 153 ms 41936 KB Output is correct
12 Correct 150 ms 41936 KB Output is correct
13 Correct 137 ms 42180 KB Output is correct
14 Correct 133 ms 42220 KB Output is correct
15 Correct 131 ms 41948 KB Output is correct
16 Correct 123 ms 41940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 884 ms 43592 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 41912 KB Output is correct
2 Correct 27 ms 41860 KB Output is correct
3 Correct 20 ms 41940 KB Output is correct
4 Correct 24 ms 41856 KB Output is correct
5 Correct 18 ms 41924 KB Output is correct
6 Correct 17 ms 41976 KB Output is correct
7 Correct 22 ms 41940 KB Output is correct
8 Correct 20 ms 41940 KB Output is correct
9 Correct 21 ms 41940 KB Output is correct
10 Correct 20 ms 41940 KB Output is correct
11 Correct 19 ms 41892 KB Output is correct
12 Correct 23 ms 41912 KB Output is correct
13 Correct 20 ms 41940 KB Output is correct
14 Correct 18 ms 41896 KB Output is correct
15 Correct 18 ms 41964 KB Output is correct
16 Correct 25 ms 41940 KB Output is correct
17 Correct 20 ms 41852 KB Output is correct
18 Correct 23 ms 41860 KB Output is correct
19 Correct 19 ms 41940 KB Output is correct
20 Correct 28 ms 41932 KB Output is correct
21 Correct 137 ms 41952 KB Output is correct
22 Correct 150 ms 41940 KB Output is correct
23 Correct 155 ms 41952 KB Output is correct
24 Correct 129 ms 41940 KB Output is correct
25 Correct 141 ms 41940 KB Output is correct
26 Correct 196 ms 41940 KB Output is correct
27 Correct 52 ms 42224 KB Output is correct
28 Correct 45 ms 42320 KB Output is correct
29 Correct 147 ms 41964 KB Output is correct
30 Correct 176 ms 41940 KB Output is correct
31 Correct 153 ms 41936 KB Output is correct
32 Correct 150 ms 41936 KB Output is correct
33 Correct 137 ms 42180 KB Output is correct
34 Correct 133 ms 42220 KB Output is correct
35 Correct 131 ms 41948 KB Output is correct
36 Correct 123 ms 41940 KB Output is correct
37 Correct 170 ms 42408 KB Output is correct
38 Correct 163 ms 42384 KB Output is correct
39 Correct 40 ms 42388 KB Output is correct
40 Correct 58 ms 42384 KB Output is correct
41 Correct 182 ms 42400 KB Output is correct
42 Correct 193 ms 42436 KB Output is correct
43 Correct 239 ms 42400 KB Output is correct
44 Correct 188 ms 42408 KB Output is correct
45 Correct 205 ms 42388 KB Output is correct
46 Correct 221 ms 42396 KB Output is correct
47 Correct 73 ms 42440 KB Output is correct
48 Correct 179 ms 42504 KB Output is correct
49 Correct 137 ms 42188 KB Output is correct
50 Correct 172 ms 42368 KB Output is correct
51 Correct 220 ms 42392 KB Output is correct
52 Correct 193 ms 42460 KB Output is correct
53 Correct 132 ms 41956 KB Output is correct
54 Correct 180 ms 41952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 206 ms 42864 KB Output is correct
2 Correct 220 ms 42792 KB Output is correct
3 Correct 220 ms 42804 KB Output is correct
4 Correct 155 ms 42532 KB Output is correct
5 Correct 187 ms 42808 KB Output is correct
6 Correct 186 ms 42776 KB Output is correct
7 Correct 52 ms 42824 KB Output is correct
8 Correct 56 ms 42828 KB Output is correct
9 Correct 94 ms 42728 KB Output is correct
10 Correct 145 ms 42440 KB Output is correct
11 Correct 166 ms 42880 KB Output is correct
12 Correct 185 ms 42788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 41912 KB Output is correct
2 Correct 27 ms 41860 KB Output is correct
3 Correct 20 ms 41940 KB Output is correct
4 Correct 24 ms 41856 KB Output is correct
5 Correct 18 ms 41924 KB Output is correct
6 Correct 17 ms 41976 KB Output is correct
7 Correct 22 ms 41940 KB Output is correct
8 Correct 20 ms 41940 KB Output is correct
9 Correct 21 ms 41940 KB Output is correct
10 Correct 20 ms 41940 KB Output is correct
11 Correct 19 ms 41892 KB Output is correct
12 Correct 23 ms 41912 KB Output is correct
13 Correct 20 ms 41940 KB Output is correct
14 Correct 18 ms 41896 KB Output is correct
15 Correct 18 ms 41964 KB Output is correct
16 Correct 25 ms 41940 KB Output is correct
17 Correct 20 ms 41852 KB Output is correct
18 Correct 23 ms 41860 KB Output is correct
19 Correct 19 ms 41940 KB Output is correct
20 Correct 28 ms 41932 KB Output is correct
21 Correct 20 ms 41940 KB Output is correct
22 Correct 21 ms 41948 KB Output is correct
23 Correct 19 ms 41972 KB Output is correct
24 Correct 21 ms 41884 KB Output is correct
25 Correct 18 ms 41940 KB Output is correct
26 Correct 19 ms 41940 KB Output is correct
27 Correct 27 ms 41936 KB Output is correct
28 Correct 24 ms 41984 KB Output is correct
29 Correct 21 ms 41940 KB Output is correct
30 Correct 23 ms 41868 KB Output is correct
31 Correct 26 ms 41940 KB Output is correct
32 Correct 22 ms 41860 KB Output is correct
33 Correct 25 ms 41952 KB Output is correct
34 Correct 19 ms 41852 KB Output is correct
35 Correct 25 ms 41940 KB Output is correct
36 Correct 23 ms 41924 KB Output is correct
37 Correct 26 ms 41960 KB Output is correct
38 Correct 21 ms 41940 KB Output is correct
39 Correct 137 ms 41952 KB Output is correct
40 Correct 150 ms 41940 KB Output is correct
41 Correct 155 ms 41952 KB Output is correct
42 Correct 129 ms 41940 KB Output is correct
43 Correct 141 ms 41940 KB Output is correct
44 Correct 196 ms 41940 KB Output is correct
45 Correct 52 ms 42224 KB Output is correct
46 Correct 45 ms 42320 KB Output is correct
47 Correct 147 ms 41964 KB Output is correct
48 Correct 176 ms 41940 KB Output is correct
49 Correct 153 ms 41936 KB Output is correct
50 Correct 150 ms 41936 KB Output is correct
51 Correct 137 ms 42180 KB Output is correct
52 Correct 133 ms 42220 KB Output is correct
53 Correct 131 ms 41948 KB Output is correct
54 Correct 123 ms 41940 KB Output is correct
55 Correct 170 ms 42408 KB Output is correct
56 Correct 163 ms 42384 KB Output is correct
57 Correct 40 ms 42388 KB Output is correct
58 Correct 58 ms 42384 KB Output is correct
59 Correct 182 ms 42400 KB Output is correct
60 Correct 193 ms 42436 KB Output is correct
61 Correct 239 ms 42400 KB Output is correct
62 Correct 188 ms 42408 KB Output is correct
63 Correct 205 ms 42388 KB Output is correct
64 Correct 221 ms 42396 KB Output is correct
65 Correct 73 ms 42440 KB Output is correct
66 Correct 179 ms 42504 KB Output is correct
67 Correct 137 ms 42188 KB Output is correct
68 Correct 172 ms 42368 KB Output is correct
69 Correct 220 ms 42392 KB Output is correct
70 Correct 193 ms 42460 KB Output is correct
71 Correct 132 ms 41956 KB Output is correct
72 Correct 180 ms 41952 KB Output is correct
73 Correct 206 ms 42864 KB Output is correct
74 Correct 220 ms 42792 KB Output is correct
75 Correct 220 ms 42804 KB Output is correct
76 Correct 155 ms 42532 KB Output is correct
77 Correct 187 ms 42808 KB Output is correct
78 Correct 186 ms 42776 KB Output is correct
79 Correct 52 ms 42824 KB Output is correct
80 Correct 56 ms 42828 KB Output is correct
81 Correct 94 ms 42728 KB Output is correct
82 Correct 145 ms 42440 KB Output is correct
83 Correct 166 ms 42880 KB Output is correct
84 Correct 185 ms 42788 KB Output is correct
85 Correct 164 ms 42432 KB Output is correct
86 Correct 198 ms 42448 KB Output is correct
87 Correct 168 ms 42340 KB Output is correct
88 Correct 193 ms 42384 KB Output is correct
89 Correct 133 ms 42252 KB Output is correct
90 Correct 188 ms 42432 KB Output is correct
91 Correct 151 ms 42572 KB Output is correct
92 Correct 149 ms 42344 KB Output is correct
93 Correct 200 ms 42372 KB Output is correct
94 Correct 184 ms 42420 KB Output is correct
95 Correct 179 ms 42408 KB Output is correct
96 Correct 176 ms 42424 KB Output is correct
97 Correct 187 ms 42544 KB Output is correct
98 Correct 161 ms 42404 KB Output is correct
99 Correct 74 ms 42452 KB Output is correct
100 Correct 149 ms 42452 KB Output is correct
101 Correct 169 ms 42456 KB Output is correct
102 Correct 133 ms 42224 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 41912 KB Output is correct
2 Correct 27 ms 41860 KB Output is correct
3 Correct 20 ms 41940 KB Output is correct
4 Correct 24 ms 41856 KB Output is correct
5 Correct 18 ms 41924 KB Output is correct
6 Correct 17 ms 41976 KB Output is correct
7 Correct 22 ms 41940 KB Output is correct
8 Correct 20 ms 41940 KB Output is correct
9 Correct 21 ms 41940 KB Output is correct
10 Correct 20 ms 41940 KB Output is correct
11 Correct 19 ms 41892 KB Output is correct
12 Correct 23 ms 41912 KB Output is correct
13 Correct 20 ms 41940 KB Output is correct
14 Correct 18 ms 41896 KB Output is correct
15 Correct 18 ms 41964 KB Output is correct
16 Correct 25 ms 41940 KB Output is correct
17 Correct 20 ms 41852 KB Output is correct
18 Correct 23 ms 41860 KB Output is correct
19 Correct 19 ms 41940 KB Output is correct
20 Correct 28 ms 41932 KB Output is correct
21 Correct 20 ms 41940 KB Output is correct
22 Correct 21 ms 41948 KB Output is correct
23 Correct 19 ms 41972 KB Output is correct
24 Correct 21 ms 41884 KB Output is correct
25 Correct 18 ms 41940 KB Output is correct
26 Correct 19 ms 41940 KB Output is correct
27 Correct 27 ms 41936 KB Output is correct
28 Correct 24 ms 41984 KB Output is correct
29 Correct 21 ms 41940 KB Output is correct
30 Correct 23 ms 41868 KB Output is correct
31 Correct 26 ms 41940 KB Output is correct
32 Correct 22 ms 41860 KB Output is correct
33 Correct 25 ms 41952 KB Output is correct
34 Correct 19 ms 41852 KB Output is correct
35 Correct 25 ms 41940 KB Output is correct
36 Correct 23 ms 41924 KB Output is correct
37 Correct 26 ms 41960 KB Output is correct
38 Correct 21 ms 41940 KB Output is correct
39 Correct 137 ms 41952 KB Output is correct
40 Correct 150 ms 41940 KB Output is correct
41 Correct 155 ms 41952 KB Output is correct
42 Correct 129 ms 41940 KB Output is correct
43 Correct 141 ms 41940 KB Output is correct
44 Correct 196 ms 41940 KB Output is correct
45 Correct 52 ms 42224 KB Output is correct
46 Correct 45 ms 42320 KB Output is correct
47 Correct 147 ms 41964 KB Output is correct
48 Correct 176 ms 41940 KB Output is correct
49 Correct 153 ms 41936 KB Output is correct
50 Correct 150 ms 41936 KB Output is correct
51 Correct 137 ms 42180 KB Output is correct
52 Correct 133 ms 42220 KB Output is correct
53 Correct 131 ms 41948 KB Output is correct
54 Correct 123 ms 41940 KB Output is correct
55 Incorrect 884 ms 43592 KB Output isn't correct
56 Halted 0 ms 0 KB -