답안 #579603

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
579603 2022-06-19T13:12:00 Z cheissmart 푸드 코트 (JOI21_foodcourt) C++14
68 / 100
1000 ms 33856 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_tot(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;
	}
	void push_len(int v) {
		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_tot(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_len(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_tot(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_len(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 11 ms 23764 KB Output is correct
2 Correct 12 ms 23808 KB Output is correct
3 Correct 12 ms 23836 KB Output is correct
4 Correct 14 ms 23892 KB Output is correct
5 Correct 10 ms 23764 KB Output is correct
6 Correct 10 ms 23764 KB Output is correct
7 Correct 13 ms 23848 KB Output is correct
8 Correct 13 ms 23820 KB Output is correct
9 Correct 13 ms 23888 KB Output is correct
10 Correct 15 ms 23828 KB Output is correct
11 Correct 13 ms 23892 KB Output is correct
12 Correct 13 ms 23892 KB Output is correct
13 Correct 14 ms 23812 KB Output is correct
14 Correct 14 ms 23896 KB Output is correct
15 Correct 14 ms 23764 KB Output is correct
16 Correct 15 ms 23892 KB Output is correct
17 Correct 13 ms 23764 KB Output is correct
18 Correct 13 ms 23892 KB Output is correct
19 Correct 12 ms 23808 KB Output is correct
20 Correct 13 ms 23892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 23764 KB Output is correct
2 Correct 12 ms 23808 KB Output is correct
3 Correct 12 ms 23836 KB Output is correct
4 Correct 14 ms 23892 KB Output is correct
5 Correct 10 ms 23764 KB Output is correct
6 Correct 10 ms 23764 KB Output is correct
7 Correct 13 ms 23848 KB Output is correct
8 Correct 13 ms 23820 KB Output is correct
9 Correct 13 ms 23888 KB Output is correct
10 Correct 15 ms 23828 KB Output is correct
11 Correct 13 ms 23892 KB Output is correct
12 Correct 13 ms 23892 KB Output is correct
13 Correct 14 ms 23812 KB Output is correct
14 Correct 14 ms 23896 KB Output is correct
15 Correct 14 ms 23764 KB Output is correct
16 Correct 15 ms 23892 KB Output is correct
17 Correct 13 ms 23764 KB Output is correct
18 Correct 13 ms 23892 KB Output is correct
19 Correct 12 ms 23808 KB Output is correct
20 Correct 13 ms 23892 KB Output is correct
21 Correct 12 ms 23892 KB Output is correct
22 Correct 13 ms 23788 KB Output is correct
23 Correct 12 ms 23812 KB Output is correct
24 Correct 13 ms 23776 KB Output is correct
25 Correct 11 ms 23764 KB Output is correct
26 Correct 11 ms 23764 KB Output is correct
27 Correct 13 ms 23796 KB Output is correct
28 Correct 13 ms 23764 KB Output is correct
29 Correct 16 ms 23892 KB Output is correct
30 Correct 16 ms 23764 KB Output is correct
31 Correct 17 ms 23764 KB Output is correct
32 Correct 18 ms 23904 KB Output is correct
33 Correct 12 ms 23892 KB Output is correct
34 Correct 12 ms 23856 KB Output is correct
35 Correct 13 ms 23892 KB Output is correct
36 Correct 12 ms 23892 KB Output is correct
37 Correct 12 ms 23788 KB Output is correct
38 Correct 13 ms 23892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 25672 KB Output is correct
2 Correct 71 ms 25824 KB Output is correct
3 Correct 96 ms 25720 KB Output is correct
4 Correct 74 ms 25580 KB Output is correct
5 Correct 81 ms 25668 KB Output is correct
6 Correct 85 ms 25924 KB Output is correct
7 Correct 28 ms 24668 KB Output is correct
8 Correct 42 ms 24656 KB Output is correct
9 Correct 89 ms 25600 KB Output is correct
10 Correct 66 ms 25604 KB Output is correct
11 Correct 76 ms 25668 KB Output is correct
12 Correct 63 ms 25608 KB Output is correct
13 Correct 104 ms 25876 KB Output is correct
14 Correct 117 ms 25992 KB Output is correct
15 Correct 127 ms 26092 KB Output is correct
16 Correct 104 ms 26096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 618 ms 31492 KB Output is correct
2 Correct 548 ms 30752 KB Output is correct
3 Correct 743 ms 31656 KB Output is correct
4 Correct 566 ms 30760 KB Output is correct
5 Correct 614 ms 31160 KB Output is correct
6 Correct 886 ms 31928 KB Output is correct
7 Correct 111 ms 27680 KB Output is correct
8 Correct 129 ms 27652 KB Output is correct
9 Execution timed out 1052 ms 33856 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 23764 KB Output is correct
2 Correct 12 ms 23808 KB Output is correct
3 Correct 12 ms 23836 KB Output is correct
4 Correct 14 ms 23892 KB Output is correct
5 Correct 10 ms 23764 KB Output is correct
6 Correct 10 ms 23764 KB Output is correct
7 Correct 13 ms 23848 KB Output is correct
8 Correct 13 ms 23820 KB Output is correct
9 Correct 13 ms 23888 KB Output is correct
10 Correct 15 ms 23828 KB Output is correct
11 Correct 13 ms 23892 KB Output is correct
12 Correct 13 ms 23892 KB Output is correct
13 Correct 14 ms 23812 KB Output is correct
14 Correct 14 ms 23896 KB Output is correct
15 Correct 14 ms 23764 KB Output is correct
16 Correct 15 ms 23892 KB Output is correct
17 Correct 13 ms 23764 KB Output is correct
18 Correct 13 ms 23892 KB Output is correct
19 Correct 12 ms 23808 KB Output is correct
20 Correct 13 ms 23892 KB Output is correct
21 Correct 67 ms 25672 KB Output is correct
22 Correct 71 ms 25824 KB Output is correct
23 Correct 96 ms 25720 KB Output is correct
24 Correct 74 ms 25580 KB Output is correct
25 Correct 81 ms 25668 KB Output is correct
26 Correct 85 ms 25924 KB Output is correct
27 Correct 28 ms 24668 KB Output is correct
28 Correct 42 ms 24656 KB Output is correct
29 Correct 89 ms 25600 KB Output is correct
30 Correct 66 ms 25604 KB Output is correct
31 Correct 76 ms 25668 KB Output is correct
32 Correct 63 ms 25608 KB Output is correct
33 Correct 104 ms 25876 KB Output is correct
34 Correct 117 ms 25992 KB Output is correct
35 Correct 127 ms 26092 KB Output is correct
36 Correct 104 ms 26096 KB Output is correct
37 Correct 130 ms 25792 KB Output is correct
38 Correct 151 ms 25720 KB Output is correct
39 Correct 30 ms 24648 KB Output is correct
40 Correct 32 ms 24656 KB Output is correct
41 Correct 148 ms 25812 KB Output is correct
42 Correct 154 ms 25716 KB Output is correct
43 Correct 160 ms 25796 KB Output is correct
44 Correct 151 ms 25724 KB Output is correct
45 Correct 147 ms 25828 KB Output is correct
46 Correct 168 ms 25792 KB Output is correct
47 Correct 75 ms 25844 KB Output is correct
48 Correct 140 ms 25908 KB Output is correct
49 Correct 106 ms 25412 KB Output is correct
50 Correct 147 ms 25608 KB Output is correct
51 Correct 167 ms 25688 KB Output is correct
52 Correct 143 ms 25696 KB Output is correct
53 Correct 86 ms 25688 KB Output is correct
54 Correct 119 ms 26012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 184 ms 26368 KB Output is correct
2 Correct 194 ms 26520 KB Output is correct
3 Correct 193 ms 26540 KB Output is correct
4 Correct 161 ms 26012 KB Output is correct
5 Correct 211 ms 26340 KB Output is correct
6 Correct 191 ms 26560 KB Output is correct
7 Correct 37 ms 25360 KB Output is correct
8 Correct 42 ms 25184 KB Output is correct
9 Correct 98 ms 26544 KB Output is correct
10 Correct 159 ms 25992 KB Output is correct
11 Correct 203 ms 26532 KB Output is correct
12 Correct 195 ms 26548 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 23764 KB Output is correct
2 Correct 12 ms 23808 KB Output is correct
3 Correct 12 ms 23836 KB Output is correct
4 Correct 14 ms 23892 KB Output is correct
5 Correct 10 ms 23764 KB Output is correct
6 Correct 10 ms 23764 KB Output is correct
7 Correct 13 ms 23848 KB Output is correct
8 Correct 13 ms 23820 KB Output is correct
9 Correct 13 ms 23888 KB Output is correct
10 Correct 15 ms 23828 KB Output is correct
11 Correct 13 ms 23892 KB Output is correct
12 Correct 13 ms 23892 KB Output is correct
13 Correct 14 ms 23812 KB Output is correct
14 Correct 14 ms 23896 KB Output is correct
15 Correct 14 ms 23764 KB Output is correct
16 Correct 15 ms 23892 KB Output is correct
17 Correct 13 ms 23764 KB Output is correct
18 Correct 13 ms 23892 KB Output is correct
19 Correct 12 ms 23808 KB Output is correct
20 Correct 13 ms 23892 KB Output is correct
21 Correct 12 ms 23892 KB Output is correct
22 Correct 13 ms 23788 KB Output is correct
23 Correct 12 ms 23812 KB Output is correct
24 Correct 13 ms 23776 KB Output is correct
25 Correct 11 ms 23764 KB Output is correct
26 Correct 11 ms 23764 KB Output is correct
27 Correct 13 ms 23796 KB Output is correct
28 Correct 13 ms 23764 KB Output is correct
29 Correct 16 ms 23892 KB Output is correct
30 Correct 16 ms 23764 KB Output is correct
31 Correct 17 ms 23764 KB Output is correct
32 Correct 18 ms 23904 KB Output is correct
33 Correct 12 ms 23892 KB Output is correct
34 Correct 12 ms 23856 KB Output is correct
35 Correct 13 ms 23892 KB Output is correct
36 Correct 12 ms 23892 KB Output is correct
37 Correct 12 ms 23788 KB Output is correct
38 Correct 13 ms 23892 KB Output is correct
39 Correct 67 ms 25672 KB Output is correct
40 Correct 71 ms 25824 KB Output is correct
41 Correct 96 ms 25720 KB Output is correct
42 Correct 74 ms 25580 KB Output is correct
43 Correct 81 ms 25668 KB Output is correct
44 Correct 85 ms 25924 KB Output is correct
45 Correct 28 ms 24668 KB Output is correct
46 Correct 42 ms 24656 KB Output is correct
47 Correct 89 ms 25600 KB Output is correct
48 Correct 66 ms 25604 KB Output is correct
49 Correct 76 ms 25668 KB Output is correct
50 Correct 63 ms 25608 KB Output is correct
51 Correct 104 ms 25876 KB Output is correct
52 Correct 117 ms 25992 KB Output is correct
53 Correct 127 ms 26092 KB Output is correct
54 Correct 104 ms 26096 KB Output is correct
55 Correct 130 ms 25792 KB Output is correct
56 Correct 151 ms 25720 KB Output is correct
57 Correct 30 ms 24648 KB Output is correct
58 Correct 32 ms 24656 KB Output is correct
59 Correct 148 ms 25812 KB Output is correct
60 Correct 154 ms 25716 KB Output is correct
61 Correct 160 ms 25796 KB Output is correct
62 Correct 151 ms 25724 KB Output is correct
63 Correct 147 ms 25828 KB Output is correct
64 Correct 168 ms 25792 KB Output is correct
65 Correct 75 ms 25844 KB Output is correct
66 Correct 140 ms 25908 KB Output is correct
67 Correct 106 ms 25412 KB Output is correct
68 Correct 147 ms 25608 KB Output is correct
69 Correct 167 ms 25688 KB Output is correct
70 Correct 143 ms 25696 KB Output is correct
71 Correct 86 ms 25688 KB Output is correct
72 Correct 119 ms 26012 KB Output is correct
73 Correct 184 ms 26368 KB Output is correct
74 Correct 194 ms 26520 KB Output is correct
75 Correct 193 ms 26540 KB Output is correct
76 Correct 161 ms 26012 KB Output is correct
77 Correct 211 ms 26340 KB Output is correct
78 Correct 191 ms 26560 KB Output is correct
79 Correct 37 ms 25360 KB Output is correct
80 Correct 42 ms 25184 KB Output is correct
81 Correct 98 ms 26544 KB Output is correct
82 Correct 159 ms 25992 KB Output is correct
83 Correct 203 ms 26532 KB Output is correct
84 Correct 195 ms 26548 KB Output is correct
85 Correct 167 ms 25768 KB Output is correct
86 Correct 193 ms 25828 KB Output is correct
87 Correct 156 ms 25744 KB Output is correct
88 Correct 176 ms 25860 KB Output is correct
89 Correct 110 ms 25456 KB Output is correct
90 Correct 170 ms 25744 KB Output is correct
91 Correct 121 ms 25604 KB Output is correct
92 Correct 128 ms 25576 KB Output is correct
93 Correct 158 ms 25736 KB Output is correct
94 Correct 155 ms 26000 KB Output is correct
95 Correct 172 ms 25732 KB Output is correct
96 Correct 162 ms 25848 KB Output is correct
97 Correct 146 ms 25788 KB Output is correct
98 Correct 142 ms 25616 KB Output is correct
99 Correct 77 ms 25824 KB Output is correct
100 Correct 130 ms 25752 KB Output is correct
101 Correct 155 ms 25916 KB Output is correct
102 Correct 131 ms 25896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 23764 KB Output is correct
2 Correct 12 ms 23808 KB Output is correct
3 Correct 12 ms 23836 KB Output is correct
4 Correct 14 ms 23892 KB Output is correct
5 Correct 10 ms 23764 KB Output is correct
6 Correct 10 ms 23764 KB Output is correct
7 Correct 13 ms 23848 KB Output is correct
8 Correct 13 ms 23820 KB Output is correct
9 Correct 13 ms 23888 KB Output is correct
10 Correct 15 ms 23828 KB Output is correct
11 Correct 13 ms 23892 KB Output is correct
12 Correct 13 ms 23892 KB Output is correct
13 Correct 14 ms 23812 KB Output is correct
14 Correct 14 ms 23896 KB Output is correct
15 Correct 14 ms 23764 KB Output is correct
16 Correct 15 ms 23892 KB Output is correct
17 Correct 13 ms 23764 KB Output is correct
18 Correct 13 ms 23892 KB Output is correct
19 Correct 12 ms 23808 KB Output is correct
20 Correct 13 ms 23892 KB Output is correct
21 Correct 12 ms 23892 KB Output is correct
22 Correct 13 ms 23788 KB Output is correct
23 Correct 12 ms 23812 KB Output is correct
24 Correct 13 ms 23776 KB Output is correct
25 Correct 11 ms 23764 KB Output is correct
26 Correct 11 ms 23764 KB Output is correct
27 Correct 13 ms 23796 KB Output is correct
28 Correct 13 ms 23764 KB Output is correct
29 Correct 16 ms 23892 KB Output is correct
30 Correct 16 ms 23764 KB Output is correct
31 Correct 17 ms 23764 KB Output is correct
32 Correct 18 ms 23904 KB Output is correct
33 Correct 12 ms 23892 KB Output is correct
34 Correct 12 ms 23856 KB Output is correct
35 Correct 13 ms 23892 KB Output is correct
36 Correct 12 ms 23892 KB Output is correct
37 Correct 12 ms 23788 KB Output is correct
38 Correct 13 ms 23892 KB Output is correct
39 Correct 67 ms 25672 KB Output is correct
40 Correct 71 ms 25824 KB Output is correct
41 Correct 96 ms 25720 KB Output is correct
42 Correct 74 ms 25580 KB Output is correct
43 Correct 81 ms 25668 KB Output is correct
44 Correct 85 ms 25924 KB Output is correct
45 Correct 28 ms 24668 KB Output is correct
46 Correct 42 ms 24656 KB Output is correct
47 Correct 89 ms 25600 KB Output is correct
48 Correct 66 ms 25604 KB Output is correct
49 Correct 76 ms 25668 KB Output is correct
50 Correct 63 ms 25608 KB Output is correct
51 Correct 104 ms 25876 KB Output is correct
52 Correct 117 ms 25992 KB Output is correct
53 Correct 127 ms 26092 KB Output is correct
54 Correct 104 ms 26096 KB Output is correct
55 Correct 618 ms 31492 KB Output is correct
56 Correct 548 ms 30752 KB Output is correct
57 Correct 743 ms 31656 KB Output is correct
58 Correct 566 ms 30760 KB Output is correct
59 Correct 614 ms 31160 KB Output is correct
60 Correct 886 ms 31928 KB Output is correct
61 Correct 111 ms 27680 KB Output is correct
62 Correct 129 ms 27652 KB Output is correct
63 Execution timed out 1052 ms 33856 KB Time limit exceeded
64 Halted 0 ms 0 KB -