답안 #579602

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
579602 2022-06-19T13:07:33 Z cheissmart 푸드 코트 (JOI21_foodcourt) C++14
68 / 100
1000 ms 39760 KB
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(v) int((v).size())
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

string _reset = "\u001b[0m", _yellow = "\u001b[33m", _bold = "\u001b[1m";
void DBG() { cerr << "]" << _reset << endl; }
template<class H, class...T> void DBG(H h, T ...t) {
	cerr << to_string(h);
	if(sizeof ...(t)) cerr << ", ";
	DBG(t...);
}
#ifdef CHEISSMART
#define debug(...) cerr << _yellow << _bold << "Line(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define debug(...)
#endif

const int INF = 1e9 + 7, N = 250005;

int n;

namespace seg {
	struct node {
		ll tot_lz, len_add, len_mx;
		node() {
			tot_lz = len_add = len_mx = 0;
		}
	} t[N * 4];
	void apply_add_tot(int v, ll x) {
		t[v].tot_lz += x;
	}
	void apply_upd_len(int v, ll add, ll mx) {
		t[v].len_add += add;
		t[v].len_mx += add;
		t[v].len_mx = max(t[v].len_mx, mx);
	}
	void push(int v) {
		apply_add_tot(v * 2, t[v].tot_lz);
		apply_add_tot(v * 2 + 1, t[v].tot_lz);
		t[v].tot_lz = 0;

		apply_upd_len(v * 2, t[v].len_add, t[v].len_mx);
		apply_upd_len(v * 2 + 1, t[v].len_add, t[v].len_mx);
		t[v].len_add = t[v].len_mx = 0;
	}
	void add_tot(int l, int r, ll x, int v = 1, int tl = 0, int tr = n) {
		if(l <= tl && tr <= r) {
			apply_add_tot(v, x);
			return;
		}
		push(v);
		int tm = (tl + tr) / 2;
		if(l < tm) add_tot(l, r, x, v * 2, tl, tm);
		if(r > tm) add_tot(l, r, x, v * 2 + 1, tm, tr);
	}
	void upd_len(int l, int r, ll add, ll mx, int v = 1, int tl = 0, int tr = n) {
		if(l <= tl && tr <= r) {
			apply_upd_len(v, add, mx);
			return;
		}
		push(v);
		int tm = (tl + tr) / 2;
		if(l < tm) upd_len(l, r, add, mx, v * 2, tl, tm);
		if(r > tm) upd_len(l, r, add, mx, v * 2 + 1, tm, tr);
	}
	ll qry_tot(int pos, int v = 1, int tl = 0, int tr = n) {
		if(tr - tl == 1)
			return t[v].tot_lz;
		push(v);
		int tm = (tl + tr) / 2;
		if(pos < tm) return qry_tot(pos, v * 2, tl, tm);
		else return qry_tot(pos, v * 2 + 1, tm, tr);
	}
	ll qry_len(int pos, int v = 1, int tl = 0, int tr = n) {
		if(tr - tl == 1)
			return max(t[v].len_add, t[v].len_mx);
		push(v);
		int tm = (tl + tr) / 2;
		if(pos < tm) return qry_len(pos, v * 2, tl, tm);
		else return qry_len(pos, v * 2 + 1, tm, tr);
	}
}

namespace seg2 {
	ll t[N * 4];
	void apply(int v, ll x) {
		t[v] += x;
	}
	void push(int v) {
		apply(v * 2, t[v]);
		apply(v * 2 + 1, t[v]);
		t[v] = 0;
	}
	void add(int l, int r, ll x, int v = 1, int tl = 0, int tr = n) {
		if(l <= tl && tr <= r) {
			apply(v, x);
			return;
		}
		push(v);
		int tm = (tl + tr) / 2;
		if(l < tm) add(l, r, x, v * 2, tl, tm);
		if(r > tm) add(l, r, x, v * 2 + 1, tm, tr);
	}
	ll qry(int pos, int v = 1, int tl = 0, int tr = n) {
		if(tr - tl == 1)
			return t[v];
		push(v);
		int tm = (tl + tr) / 2;
		if(pos < tm) return qry(pos, v * 2, tl, tm);
		else return qry(pos, v * 2 + 1, tm, tr);
	}
}

signed main()
{
	IO_OP;

	int m, q;
	cin >> n >> m >> q;

	V<array<int, 4>> ev;
	V<pair<int, ll>> qq;

	for(int i = 0; i < q; i++) {
		int t; cin >> t;
		if(t == 1) {
			int l, r, c, k;
			cin >> l >> r >> c >> k, l--;
			ev.PB({l, r, c, k});
			seg::add_tot(l, r, k);
			seg::upd_len(l, r, k, 0);
		} else if(t == 2) {
			int l, r, k;
			cin >> l >> r >> k, l--;
			seg::upd_len(l, r, -k, 0);
		} else {
			int a;
			ll b;
			cin >> a >> b, a--;
			if(b > seg::qry_len(a)) {
				qq.EB(a, -1);
			} else {
				qq.EB(a, seg::qry_tot(a) - seg::qry_len(a) + b);
			}
		}
	}

	vi ans(SZ(qq));

	int now = -1;

	auto gogo = [&] (int m) {
		while(now < m) {
			now++;
			seg2::add(ev[now][0], ev[now][1], ev[now][3]);
		}
		while(now > m) {
			seg2::add(ev[now][0], ev[now][1], -ev[now][3]);
			now--;
		}
	};

	function<void(vi&, int, int)> solve = [&] (vi& todo, int l, int r) {
		if(todo.empty()) return;
		if(l == r) {
			for(int i:todo) ans[i] = ev[l][2];
			return;
		}
		int m = (l + r) / 2;
		vi todo_l, todo_r;

		gogo(m);

		for(int i:todo) {
			if(seg2::qry(qq[i].F) >= qq[i].S) {
				todo_l.PB(i);
			} else {
				todo_r.PB(i);
			}
		}

		solve(todo_l, l, m);
		solve(todo_r, m + 1, r);
	};

	vi todo;
	for(int i = 0; i < SZ(qq); i++)
		if(qq[i].S != -1) {
			todo.PB(i);
		}

	solve(todo, 0, SZ(ev) - 1);

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

}

# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Correct 12 ms 23892 KB Output is correct
3 Correct 14 ms 23764 KB Output is correct
4 Correct 12 ms 23892 KB Output is correct
5 Correct 14 ms 23764 KB Output is correct
6 Correct 11 ms 23764 KB Output is correct
7 Correct 13 ms 23764 KB Output is correct
8 Correct 12 ms 23892 KB Output is correct
9 Correct 17 ms 23764 KB Output is correct
10 Correct 17 ms 23812 KB Output is correct
11 Correct 16 ms 23804 KB Output is correct
12 Correct 14 ms 23844 KB Output is correct
13 Correct 14 ms 23868 KB Output is correct
14 Correct 11 ms 23892 KB Output is correct
15 Correct 12 ms 23764 KB Output is correct
16 Correct 12 ms 23892 KB Output is correct
17 Correct 12 ms 23844 KB Output is correct
18 Correct 12 ms 23876 KB Output is correct
19 Correct 12 ms 23892 KB Output is correct
20 Correct 14 ms 23892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Correct 12 ms 23892 KB Output is correct
3 Correct 14 ms 23764 KB Output is correct
4 Correct 12 ms 23892 KB Output is correct
5 Correct 14 ms 23764 KB Output is correct
6 Correct 11 ms 23764 KB Output is correct
7 Correct 13 ms 23764 KB Output is correct
8 Correct 12 ms 23892 KB Output is correct
9 Correct 17 ms 23764 KB Output is correct
10 Correct 17 ms 23812 KB Output is correct
11 Correct 16 ms 23804 KB Output is correct
12 Correct 14 ms 23844 KB Output is correct
13 Correct 14 ms 23868 KB Output is correct
14 Correct 11 ms 23892 KB Output is correct
15 Correct 12 ms 23764 KB Output is correct
16 Correct 12 ms 23892 KB Output is correct
17 Correct 12 ms 23844 KB Output is correct
18 Correct 12 ms 23876 KB Output is correct
19 Correct 12 ms 23892 KB Output is correct
20 Correct 14 ms 23892 KB Output is correct
21 Correct 12 ms 23892 KB Output is correct
22 Correct 14 ms 23892 KB Output is correct
23 Correct 12 ms 23860 KB Output is correct
24 Correct 14 ms 23816 KB Output is correct
25 Correct 13 ms 23772 KB Output is correct
26 Correct 13 ms 23764 KB Output is correct
27 Correct 14 ms 23892 KB Output is correct
28 Correct 13 ms 23756 KB Output is correct
29 Correct 12 ms 23852 KB Output is correct
30 Correct 15 ms 23852 KB Output is correct
31 Correct 12 ms 23892 KB Output is correct
32 Correct 13 ms 23892 KB Output is correct
33 Correct 12 ms 23892 KB Output is correct
34 Correct 12 ms 23892 KB Output is correct
35 Correct 12 ms 23892 KB Output is correct
36 Correct 13 ms 23844 KB Output is correct
37 Correct 12 ms 23892 KB Output is correct
38 Correct 13 ms 23892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 72 ms 25696 KB Output is correct
2 Correct 76 ms 25800 KB Output is correct
3 Correct 80 ms 25736 KB Output is correct
4 Correct 86 ms 26828 KB Output is correct
5 Correct 84 ms 26956 KB Output is correct
6 Correct 79 ms 27076 KB Output is correct
7 Correct 29 ms 25392 KB Output is correct
8 Correct 31 ms 25360 KB Output is correct
9 Correct 87 ms 26816 KB Output is correct
10 Correct 69 ms 26884 KB Output is correct
11 Correct 91 ms 26956 KB Output is correct
12 Correct 100 ms 26900 KB Output is correct
13 Correct 101 ms 26824 KB Output is correct
14 Correct 109 ms 26996 KB Output is correct
15 Correct 113 ms 27268 KB Output is correct
16 Correct 145 ms 27392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 644 ms 31428 KB Output is correct
2 Correct 564 ms 34968 KB Output is correct
3 Correct 757 ms 37668 KB Output is correct
4 Correct 686 ms 35228 KB Output is correct
5 Correct 646 ms 35640 KB Output is correct
6 Correct 940 ms 38100 KB Output is correct
7 Correct 114 ms 31780 KB Output is correct
8 Correct 127 ms 31708 KB Output is correct
9 Execution timed out 1093 ms 39760 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Correct 12 ms 23892 KB Output is correct
3 Correct 14 ms 23764 KB Output is correct
4 Correct 12 ms 23892 KB Output is correct
5 Correct 14 ms 23764 KB Output is correct
6 Correct 11 ms 23764 KB Output is correct
7 Correct 13 ms 23764 KB Output is correct
8 Correct 12 ms 23892 KB Output is correct
9 Correct 17 ms 23764 KB Output is correct
10 Correct 17 ms 23812 KB Output is correct
11 Correct 16 ms 23804 KB Output is correct
12 Correct 14 ms 23844 KB Output is correct
13 Correct 14 ms 23868 KB Output is correct
14 Correct 11 ms 23892 KB Output is correct
15 Correct 12 ms 23764 KB Output is correct
16 Correct 12 ms 23892 KB Output is correct
17 Correct 12 ms 23844 KB Output is correct
18 Correct 12 ms 23876 KB Output is correct
19 Correct 12 ms 23892 KB Output is correct
20 Correct 14 ms 23892 KB Output is correct
21 Correct 72 ms 25696 KB Output is correct
22 Correct 76 ms 25800 KB Output is correct
23 Correct 80 ms 25736 KB Output is correct
24 Correct 86 ms 26828 KB Output is correct
25 Correct 84 ms 26956 KB Output is correct
26 Correct 79 ms 27076 KB Output is correct
27 Correct 29 ms 25392 KB Output is correct
28 Correct 31 ms 25360 KB Output is correct
29 Correct 87 ms 26816 KB Output is correct
30 Correct 69 ms 26884 KB Output is correct
31 Correct 91 ms 26956 KB Output is correct
32 Correct 100 ms 26900 KB Output is correct
33 Correct 101 ms 26824 KB Output is correct
34 Correct 109 ms 26996 KB Output is correct
35 Correct 113 ms 27268 KB Output is correct
36 Correct 145 ms 27392 KB Output is correct
37 Correct 166 ms 26752 KB Output is correct
38 Correct 171 ms 26636 KB Output is correct
39 Correct 28 ms 25220 KB Output is correct
40 Correct 34 ms 25248 KB Output is correct
41 Correct 156 ms 26996 KB Output is correct
42 Correct 169 ms 27008 KB Output is correct
43 Correct 181 ms 26796 KB Output is correct
44 Correct 182 ms 26800 KB Output is correct
45 Correct 158 ms 26816 KB Output is correct
46 Correct 194 ms 26820 KB Output is correct
47 Correct 89 ms 26680 KB Output is correct
48 Correct 141 ms 26816 KB Output is correct
49 Correct 108 ms 26268 KB Output is correct
50 Correct 128 ms 26500 KB Output is correct
51 Correct 203 ms 26828 KB Output is correct
52 Correct 152 ms 26904 KB Output is correct
53 Correct 96 ms 26884 KB Output is correct
54 Correct 118 ms 27408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 182 ms 26364 KB Output is correct
2 Correct 223 ms 28096 KB Output is correct
3 Correct 219 ms 28192 KB Output is correct
4 Correct 151 ms 27188 KB Output is correct
5 Correct 193 ms 27712 KB Output is correct
6 Correct 227 ms 28252 KB Output is correct
7 Correct 39 ms 26500 KB Output is correct
8 Correct 42 ms 26340 KB Output is correct
9 Correct 99 ms 28016 KB Output is correct
10 Correct 169 ms 27016 KB Output is correct
11 Correct 215 ms 28220 KB Output is correct
12 Correct 197 ms 28140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Correct 12 ms 23892 KB Output is correct
3 Correct 14 ms 23764 KB Output is correct
4 Correct 12 ms 23892 KB Output is correct
5 Correct 14 ms 23764 KB Output is correct
6 Correct 11 ms 23764 KB Output is correct
7 Correct 13 ms 23764 KB Output is correct
8 Correct 12 ms 23892 KB Output is correct
9 Correct 17 ms 23764 KB Output is correct
10 Correct 17 ms 23812 KB Output is correct
11 Correct 16 ms 23804 KB Output is correct
12 Correct 14 ms 23844 KB Output is correct
13 Correct 14 ms 23868 KB Output is correct
14 Correct 11 ms 23892 KB Output is correct
15 Correct 12 ms 23764 KB Output is correct
16 Correct 12 ms 23892 KB Output is correct
17 Correct 12 ms 23844 KB Output is correct
18 Correct 12 ms 23876 KB Output is correct
19 Correct 12 ms 23892 KB Output is correct
20 Correct 14 ms 23892 KB Output is correct
21 Correct 12 ms 23892 KB Output is correct
22 Correct 14 ms 23892 KB Output is correct
23 Correct 12 ms 23860 KB Output is correct
24 Correct 14 ms 23816 KB Output is correct
25 Correct 13 ms 23772 KB Output is correct
26 Correct 13 ms 23764 KB Output is correct
27 Correct 14 ms 23892 KB Output is correct
28 Correct 13 ms 23756 KB Output is correct
29 Correct 12 ms 23852 KB Output is correct
30 Correct 15 ms 23852 KB Output is correct
31 Correct 12 ms 23892 KB Output is correct
32 Correct 13 ms 23892 KB Output is correct
33 Correct 12 ms 23892 KB Output is correct
34 Correct 12 ms 23892 KB Output is correct
35 Correct 12 ms 23892 KB Output is correct
36 Correct 13 ms 23844 KB Output is correct
37 Correct 12 ms 23892 KB Output is correct
38 Correct 13 ms 23892 KB Output is correct
39 Correct 72 ms 25696 KB Output is correct
40 Correct 76 ms 25800 KB Output is correct
41 Correct 80 ms 25736 KB Output is correct
42 Correct 86 ms 26828 KB Output is correct
43 Correct 84 ms 26956 KB Output is correct
44 Correct 79 ms 27076 KB Output is correct
45 Correct 29 ms 25392 KB Output is correct
46 Correct 31 ms 25360 KB Output is correct
47 Correct 87 ms 26816 KB Output is correct
48 Correct 69 ms 26884 KB Output is correct
49 Correct 91 ms 26956 KB Output is correct
50 Correct 100 ms 26900 KB Output is correct
51 Correct 101 ms 26824 KB Output is correct
52 Correct 109 ms 26996 KB Output is correct
53 Correct 113 ms 27268 KB Output is correct
54 Correct 145 ms 27392 KB Output is correct
55 Correct 166 ms 26752 KB Output is correct
56 Correct 171 ms 26636 KB Output is correct
57 Correct 28 ms 25220 KB Output is correct
58 Correct 34 ms 25248 KB Output is correct
59 Correct 156 ms 26996 KB Output is correct
60 Correct 169 ms 27008 KB Output is correct
61 Correct 181 ms 26796 KB Output is correct
62 Correct 182 ms 26800 KB Output is correct
63 Correct 158 ms 26816 KB Output is correct
64 Correct 194 ms 26820 KB Output is correct
65 Correct 89 ms 26680 KB Output is correct
66 Correct 141 ms 26816 KB Output is correct
67 Correct 108 ms 26268 KB Output is correct
68 Correct 128 ms 26500 KB Output is correct
69 Correct 203 ms 26828 KB Output is correct
70 Correct 152 ms 26904 KB Output is correct
71 Correct 96 ms 26884 KB Output is correct
72 Correct 118 ms 27408 KB Output is correct
73 Correct 182 ms 26364 KB Output is correct
74 Correct 223 ms 28096 KB Output is correct
75 Correct 219 ms 28192 KB Output is correct
76 Correct 151 ms 27188 KB Output is correct
77 Correct 193 ms 27712 KB Output is correct
78 Correct 227 ms 28252 KB Output is correct
79 Correct 39 ms 26500 KB Output is correct
80 Correct 42 ms 26340 KB Output is correct
81 Correct 99 ms 28016 KB Output is correct
82 Correct 169 ms 27016 KB Output is correct
83 Correct 215 ms 28220 KB Output is correct
84 Correct 197 ms 28140 KB Output is correct
85 Correct 156 ms 27220 KB Output is correct
86 Correct 174 ms 27440 KB Output is correct
87 Correct 155 ms 27204 KB Output is correct
88 Correct 186 ms 27544 KB Output is correct
89 Correct 122 ms 26576 KB Output is correct
90 Correct 165 ms 27412 KB Output is correct
91 Correct 125 ms 26908 KB Output is correct
92 Correct 126 ms 26764 KB Output is correct
93 Correct 167 ms 27340 KB Output is correct
94 Correct 165 ms 27528 KB Output is correct
95 Correct 167 ms 27288 KB Output is correct
96 Correct 157 ms 27360 KB Output is correct
97 Correct 151 ms 27328 KB Output is correct
98 Correct 137 ms 26984 KB Output is correct
99 Correct 88 ms 27224 KB Output is correct
100 Correct 151 ms 26928 KB Output is correct
101 Correct 146 ms 27268 KB Output is correct
102 Correct 129 ms 27596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Correct 12 ms 23892 KB Output is correct
3 Correct 14 ms 23764 KB Output is correct
4 Correct 12 ms 23892 KB Output is correct
5 Correct 14 ms 23764 KB Output is correct
6 Correct 11 ms 23764 KB Output is correct
7 Correct 13 ms 23764 KB Output is correct
8 Correct 12 ms 23892 KB Output is correct
9 Correct 17 ms 23764 KB Output is correct
10 Correct 17 ms 23812 KB Output is correct
11 Correct 16 ms 23804 KB Output is correct
12 Correct 14 ms 23844 KB Output is correct
13 Correct 14 ms 23868 KB Output is correct
14 Correct 11 ms 23892 KB Output is correct
15 Correct 12 ms 23764 KB Output is correct
16 Correct 12 ms 23892 KB Output is correct
17 Correct 12 ms 23844 KB Output is correct
18 Correct 12 ms 23876 KB Output is correct
19 Correct 12 ms 23892 KB Output is correct
20 Correct 14 ms 23892 KB Output is correct
21 Correct 12 ms 23892 KB Output is correct
22 Correct 14 ms 23892 KB Output is correct
23 Correct 12 ms 23860 KB Output is correct
24 Correct 14 ms 23816 KB Output is correct
25 Correct 13 ms 23772 KB Output is correct
26 Correct 13 ms 23764 KB Output is correct
27 Correct 14 ms 23892 KB Output is correct
28 Correct 13 ms 23756 KB Output is correct
29 Correct 12 ms 23852 KB Output is correct
30 Correct 15 ms 23852 KB Output is correct
31 Correct 12 ms 23892 KB Output is correct
32 Correct 13 ms 23892 KB Output is correct
33 Correct 12 ms 23892 KB Output is correct
34 Correct 12 ms 23892 KB Output is correct
35 Correct 12 ms 23892 KB Output is correct
36 Correct 13 ms 23844 KB Output is correct
37 Correct 12 ms 23892 KB Output is correct
38 Correct 13 ms 23892 KB Output is correct
39 Correct 72 ms 25696 KB Output is correct
40 Correct 76 ms 25800 KB Output is correct
41 Correct 80 ms 25736 KB Output is correct
42 Correct 86 ms 26828 KB Output is correct
43 Correct 84 ms 26956 KB Output is correct
44 Correct 79 ms 27076 KB Output is correct
45 Correct 29 ms 25392 KB Output is correct
46 Correct 31 ms 25360 KB Output is correct
47 Correct 87 ms 26816 KB Output is correct
48 Correct 69 ms 26884 KB Output is correct
49 Correct 91 ms 26956 KB Output is correct
50 Correct 100 ms 26900 KB Output is correct
51 Correct 101 ms 26824 KB Output is correct
52 Correct 109 ms 26996 KB Output is correct
53 Correct 113 ms 27268 KB Output is correct
54 Correct 145 ms 27392 KB Output is correct
55 Correct 644 ms 31428 KB Output is correct
56 Correct 564 ms 34968 KB Output is correct
57 Correct 757 ms 37668 KB Output is correct
58 Correct 686 ms 35228 KB Output is correct
59 Correct 646 ms 35640 KB Output is correct
60 Correct 940 ms 38100 KB Output is correct
61 Correct 114 ms 31780 KB Output is correct
62 Correct 127 ms 31708 KB Output is correct
63 Execution timed out 1093 ms 39760 KB Time limit exceeded
64 Halted 0 ms 0 KB -