답안 #645397

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
645397 2022-09-27T04:46:20 Z GusterGoose27 푸드 코트 (JOI21_foodcourt) C++11
68 / 100
1000 ms 305540 KB
#pragma GCC optimize("Ofast")
#pragma GCC target("sse4")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pii;

class ptree {
public:
	int lp, rp;
	ptree *l = nullptr;
	ptree *r = nullptr;
	ll s = 0;
	ptree(int lv, int rv) {
		lp = lv;
		rp = rv;
		if (lp != rp) {
			int mid = (lp+rp)/2;
			l = new ptree(lp, mid);
			r = new ptree(mid+1, rp);
		}
	}
	ptree(ptree *t, int lupd = 0) {
		lp = t->lp;
		rp = t->rp;
		l = t->l;
		r = t->r;
		s = t->s+lupd;
	}
	ptree(ptree *lt, ptree *rt, ll curs) {
		l = lt;
		r = rt;
		lp = l->lp;
		rp = r->rp;
		s = curs;
	}
	ptree *upd(int lv, int rv, int v) {
		if (lp > rv || rp < lv) return this;
		if (lp >= lv && rp <= rv) {
			return new ptree(this, v);
		}
		return new ptree(l->upd(lv, rv, v), r->upd(lv, rv, v), s);
	}
	ll query(int p) {
		if (lp == rp) return s;
		if (p > (lp+rp)/2) return s+r->query(p);
		return s+l->query(p);
	}
};

const int MAX_ALLOC = 524288;
int sz;

class stree {
public:
	pii lz[MAX_ALLOC];
	stree() {
		fill(lz, lz+(int)pow(2, ceil(log2(sz))), pii(0, 0));
	}
	void merge(int cur, pii p) {
		lz[cur].first += p.first;
		lz[cur].second += p.first;
		lz[cur].second = max(lz[cur].second, p.second);
	}
	void prop(int cur) {
		merge(2*cur, lz[cur]);
		merge(2*cur+1, lz[cur]);
		lz[cur] = pii(0, 0);
	}
	void upd(int lv, int rv, int v, int cur = 1, int lp = 0, int rp = sz-1) {
		if (lp > rv || rp < lv) return;
		if (lp >= lv && rp <= rv) {
			merge(cur, pii(v, 0));
			return;
		}
		prop(cur);
		int mid = (lp+rp)/2;
		upd(lv, rv, v, 2*cur, lp, mid);
		upd(lv, rv, v, 2*cur+1, mid+1, rp);
	}
	ll getv(int p, int cur = 1, int lp = 0, int rp = sz-1) {
		if (lp == rp) return max(lz[cur].first, lz[cur].second);
		prop(cur);
		int mid = (lp+rp)/2;
		if (p <= mid) return getv(p, 2*cur, lp, mid);
		else return getv(p, 2*cur+1, mid+1, rp);
	}
};

const int MAXN = 250000;
int n, m, q;
int upd_id[MAXN];
ptree *trees[MAXN];
stree *net_tree;
int ev_num = 0;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cin >> n >> m >> q;
	ptree *cur_tree = new ptree(0, n-1);
	sz = n;
	stree *net_tree = new stree();
	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--; r--;
			upd_id[ev_num] = c;
			cur_tree = cur_tree->upd(l, r, k);
			trees[ev_num] = cur_tree;
			net_tree->upd(l, r, k);
			ev_num++;
		}
		if (t == 2) {
			int l, r, k; cin >> l >> r >> k;
			l--; r--;
			net_tree->upd(l, r, -k);
		}
		if (t == 3) {
			int a; ll b; cin >> a >> b; a--;
			ll cur_sz = net_tree->getv(a);
			if (cur_sz < b) {
				cout << "0\n";
				continue;
			}
			ll num_adds = trees[ev_num-1]->query(a);
			ll req_sz = num_adds-cur_sz+b;
			int mn = -1;
			int mx = ev_num-1;
			while (mx > mn+1) {
				int cur = (mn+mx)/2;
				if (trees[cur]->query(a) < req_sz) mn = cur;
				else mx = cur;
			}
			cout << upd_id[mx] << "\n";
		}
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9300 KB Output is correct
2 Correct 6 ms 9556 KB Output is correct
3 Correct 6 ms 9556 KB Output is correct
4 Correct 7 ms 10068 KB Output is correct
5 Correct 4 ms 8532 KB Output is correct
6 Correct 4 ms 8532 KB Output is correct
7 Correct 6 ms 9684 KB Output is correct
8 Correct 6 ms 9684 KB Output is correct
9 Correct 7 ms 9684 KB Output is correct
10 Correct 9 ms 9692 KB Output is correct
11 Correct 6 ms 9684 KB Output is correct
12 Correct 6 ms 9684 KB Output is correct
13 Correct 4 ms 8660 KB Output is correct
14 Correct 5 ms 8788 KB Output is correct
15 Correct 6 ms 9428 KB Output is correct
16 Correct 7 ms 9720 KB Output is correct
17 Correct 8 ms 9428 KB Output is correct
18 Correct 6 ms 9684 KB Output is correct
19 Correct 6 ms 9680 KB Output is correct
20 Correct 6 ms 9940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9300 KB Output is correct
2 Correct 6 ms 9556 KB Output is correct
3 Correct 6 ms 9556 KB Output is correct
4 Correct 7 ms 10068 KB Output is correct
5 Correct 4 ms 8532 KB Output is correct
6 Correct 4 ms 8532 KB Output is correct
7 Correct 6 ms 9684 KB Output is correct
8 Correct 6 ms 9684 KB Output is correct
9 Correct 7 ms 9684 KB Output is correct
10 Correct 9 ms 9692 KB Output is correct
11 Correct 6 ms 9684 KB Output is correct
12 Correct 6 ms 9684 KB Output is correct
13 Correct 4 ms 8660 KB Output is correct
14 Correct 5 ms 8788 KB Output is correct
15 Correct 6 ms 9428 KB Output is correct
16 Correct 7 ms 9720 KB Output is correct
17 Correct 8 ms 9428 KB Output is correct
18 Correct 6 ms 9684 KB Output is correct
19 Correct 6 ms 9680 KB Output is correct
20 Correct 6 ms 9940 KB Output is correct
21 Correct 6 ms 9428 KB Output is correct
22 Correct 6 ms 9556 KB Output is correct
23 Correct 8 ms 9828 KB Output is correct
24 Correct 6 ms 10068 KB Output is correct
25 Correct 6 ms 8576 KB Output is correct
26 Correct 5 ms 8576 KB Output is correct
27 Correct 8 ms 9756 KB Output is correct
28 Correct 7 ms 9760 KB Output is correct
29 Correct 8 ms 9684 KB Output is correct
30 Correct 6 ms 9684 KB Output is correct
31 Correct 6 ms 9684 KB Output is correct
32 Correct 6 ms 9684 KB Output is correct
33 Correct 5 ms 8648 KB Output is correct
34 Correct 4 ms 8748 KB Output is correct
35 Correct 6 ms 9556 KB Output is correct
36 Correct 6 ms 9812 KB Output is correct
37 Correct 6 ms 9556 KB Output is correct
38 Correct 7 ms 9940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 82 ms 35260 KB Output is correct
2 Correct 103 ms 45980 KB Output is correct
3 Correct 91 ms 37328 KB Output is correct
4 Correct 84 ms 37068 KB Output is correct
5 Correct 128 ms 48684 KB Output is correct
6 Correct 108 ms 48736 KB Output is correct
7 Correct 18 ms 9812 KB Output is correct
8 Correct 21 ms 9812 KB Output is correct
9 Correct 88 ms 37796 KB Output is correct
10 Correct 84 ms 37912 KB Output is correct
11 Correct 97 ms 37964 KB Output is correct
12 Correct 85 ms 38052 KB Output is correct
13 Correct 93 ms 42940 KB Output is correct
14 Correct 110 ms 49124 KB Output is correct
15 Correct 123 ms 63840 KB Output is correct
16 Correct 142 ms 67236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 801 ms 201040 KB Output is correct
2 Correct 602 ms 161796 KB Output is correct
3 Correct 845 ms 220852 KB Output is correct
4 Correct 819 ms 242008 KB Output is correct
5 Correct 819 ms 237388 KB Output is correct
6 Execution timed out 1099 ms 305540 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9300 KB Output is correct
2 Correct 6 ms 9556 KB Output is correct
3 Correct 6 ms 9556 KB Output is correct
4 Correct 7 ms 10068 KB Output is correct
5 Correct 4 ms 8532 KB Output is correct
6 Correct 4 ms 8532 KB Output is correct
7 Correct 6 ms 9684 KB Output is correct
8 Correct 6 ms 9684 KB Output is correct
9 Correct 7 ms 9684 KB Output is correct
10 Correct 9 ms 9692 KB Output is correct
11 Correct 6 ms 9684 KB Output is correct
12 Correct 6 ms 9684 KB Output is correct
13 Correct 4 ms 8660 KB Output is correct
14 Correct 5 ms 8788 KB Output is correct
15 Correct 6 ms 9428 KB Output is correct
16 Correct 7 ms 9720 KB Output is correct
17 Correct 8 ms 9428 KB Output is correct
18 Correct 6 ms 9684 KB Output is correct
19 Correct 6 ms 9680 KB Output is correct
20 Correct 6 ms 9940 KB Output is correct
21 Correct 82 ms 35260 KB Output is correct
22 Correct 103 ms 45980 KB Output is correct
23 Correct 91 ms 37328 KB Output is correct
24 Correct 84 ms 37068 KB Output is correct
25 Correct 128 ms 48684 KB Output is correct
26 Correct 108 ms 48736 KB Output is correct
27 Correct 18 ms 9812 KB Output is correct
28 Correct 21 ms 9812 KB Output is correct
29 Correct 88 ms 37796 KB Output is correct
30 Correct 84 ms 37912 KB Output is correct
31 Correct 97 ms 37964 KB Output is correct
32 Correct 85 ms 38052 KB Output is correct
33 Correct 93 ms 42940 KB Output is correct
34 Correct 110 ms 49124 KB Output is correct
35 Correct 123 ms 63840 KB Output is correct
36 Correct 142 ms 67236 KB Output is correct
37 Correct 134 ms 52040 KB Output is correct
38 Correct 183 ms 66900 KB Output is correct
39 Correct 17 ms 9708 KB Output is correct
40 Correct 20 ms 10452 KB Output is correct
41 Correct 198 ms 64596 KB Output is correct
42 Correct 191 ms 64952 KB Output is correct
43 Correct 158 ms 64564 KB Output is correct
44 Correct 177 ms 64608 KB Output is correct
45 Correct 181 ms 64840 KB Output is correct
46 Correct 164 ms 64860 KB Output is correct
47 Correct 49 ms 16020 KB Output is correct
48 Correct 123 ms 65636 KB Output is correct
49 Correct 103 ms 48484 KB Output is correct
50 Correct 135 ms 58580 KB Output is correct
51 Correct 170 ms 66960 KB Output is correct
52 Correct 157 ms 66520 KB Output is correct
53 Correct 121 ms 54836 KB Output is correct
54 Correct 130 ms 67312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 267 ms 71712 KB Output is correct
2 Correct 289 ms 76516 KB Output is correct
3 Correct 298 ms 79428 KB Output is correct
4 Correct 195 ms 61340 KB Output is correct
5 Correct 246 ms 71808 KB Output is correct
6 Correct 305 ms 81568 KB Output is correct
7 Correct 31 ms 10332 KB Output is correct
8 Correct 30 ms 10888 KB Output is correct
9 Correct 66 ms 16640 KB Output is correct
10 Correct 141 ms 66432 KB Output is correct
11 Correct 218 ms 91668 KB Output is correct
12 Correct 206 ms 91208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9300 KB Output is correct
2 Correct 6 ms 9556 KB Output is correct
3 Correct 6 ms 9556 KB Output is correct
4 Correct 7 ms 10068 KB Output is correct
5 Correct 4 ms 8532 KB Output is correct
6 Correct 4 ms 8532 KB Output is correct
7 Correct 6 ms 9684 KB Output is correct
8 Correct 6 ms 9684 KB Output is correct
9 Correct 7 ms 9684 KB Output is correct
10 Correct 9 ms 9692 KB Output is correct
11 Correct 6 ms 9684 KB Output is correct
12 Correct 6 ms 9684 KB Output is correct
13 Correct 4 ms 8660 KB Output is correct
14 Correct 5 ms 8788 KB Output is correct
15 Correct 6 ms 9428 KB Output is correct
16 Correct 7 ms 9720 KB Output is correct
17 Correct 8 ms 9428 KB Output is correct
18 Correct 6 ms 9684 KB Output is correct
19 Correct 6 ms 9680 KB Output is correct
20 Correct 6 ms 9940 KB Output is correct
21 Correct 6 ms 9428 KB Output is correct
22 Correct 6 ms 9556 KB Output is correct
23 Correct 8 ms 9828 KB Output is correct
24 Correct 6 ms 10068 KB Output is correct
25 Correct 6 ms 8576 KB Output is correct
26 Correct 5 ms 8576 KB Output is correct
27 Correct 8 ms 9756 KB Output is correct
28 Correct 7 ms 9760 KB Output is correct
29 Correct 8 ms 9684 KB Output is correct
30 Correct 6 ms 9684 KB Output is correct
31 Correct 6 ms 9684 KB Output is correct
32 Correct 6 ms 9684 KB Output is correct
33 Correct 5 ms 8648 KB Output is correct
34 Correct 4 ms 8748 KB Output is correct
35 Correct 6 ms 9556 KB Output is correct
36 Correct 6 ms 9812 KB Output is correct
37 Correct 6 ms 9556 KB Output is correct
38 Correct 7 ms 9940 KB Output is correct
39 Correct 82 ms 35260 KB Output is correct
40 Correct 103 ms 45980 KB Output is correct
41 Correct 91 ms 37328 KB Output is correct
42 Correct 84 ms 37068 KB Output is correct
43 Correct 128 ms 48684 KB Output is correct
44 Correct 108 ms 48736 KB Output is correct
45 Correct 18 ms 9812 KB Output is correct
46 Correct 21 ms 9812 KB Output is correct
47 Correct 88 ms 37796 KB Output is correct
48 Correct 84 ms 37912 KB Output is correct
49 Correct 97 ms 37964 KB Output is correct
50 Correct 85 ms 38052 KB Output is correct
51 Correct 93 ms 42940 KB Output is correct
52 Correct 110 ms 49124 KB Output is correct
53 Correct 123 ms 63840 KB Output is correct
54 Correct 142 ms 67236 KB Output is correct
55 Correct 134 ms 52040 KB Output is correct
56 Correct 183 ms 66900 KB Output is correct
57 Correct 17 ms 9708 KB Output is correct
58 Correct 20 ms 10452 KB Output is correct
59 Correct 198 ms 64596 KB Output is correct
60 Correct 191 ms 64952 KB Output is correct
61 Correct 158 ms 64564 KB Output is correct
62 Correct 177 ms 64608 KB Output is correct
63 Correct 181 ms 64840 KB Output is correct
64 Correct 164 ms 64860 KB Output is correct
65 Correct 49 ms 16020 KB Output is correct
66 Correct 123 ms 65636 KB Output is correct
67 Correct 103 ms 48484 KB Output is correct
68 Correct 135 ms 58580 KB Output is correct
69 Correct 170 ms 66960 KB Output is correct
70 Correct 157 ms 66520 KB Output is correct
71 Correct 121 ms 54836 KB Output is correct
72 Correct 130 ms 67312 KB Output is correct
73 Correct 267 ms 71712 KB Output is correct
74 Correct 289 ms 76516 KB Output is correct
75 Correct 298 ms 79428 KB Output is correct
76 Correct 195 ms 61340 KB Output is correct
77 Correct 246 ms 71808 KB Output is correct
78 Correct 305 ms 81568 KB Output is correct
79 Correct 31 ms 10332 KB Output is correct
80 Correct 30 ms 10888 KB Output is correct
81 Correct 66 ms 16640 KB Output is correct
82 Correct 141 ms 66432 KB Output is correct
83 Correct 218 ms 91668 KB Output is correct
84 Correct 206 ms 91208 KB Output is correct
85 Correct 141 ms 51716 KB Output is correct
86 Correct 177 ms 57904 KB Output is correct
87 Correct 194 ms 72472 KB Output is correct
88 Correct 227 ms 81388 KB Output is correct
89 Correct 123 ms 46156 KB Output is correct
90 Correct 195 ms 65004 KB Output is correct
91 Correct 124 ms 52648 KB Output is correct
92 Correct 118 ms 50404 KB Output is correct
93 Correct 167 ms 64624 KB Output is correct
94 Correct 182 ms 64824 KB Output is correct
95 Correct 185 ms 63060 KB Output is correct
96 Correct 162 ms 65228 KB Output is correct
97 Correct 166 ms 65092 KB Output is correct
98 Correct 131 ms 54600 KB Output is correct
99 Correct 50 ms 15936 KB Output is correct
100 Correct 104 ms 56496 KB Output is correct
101 Correct 125 ms 65332 KB Output is correct
102 Correct 159 ms 64700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9300 KB Output is correct
2 Correct 6 ms 9556 KB Output is correct
3 Correct 6 ms 9556 KB Output is correct
4 Correct 7 ms 10068 KB Output is correct
5 Correct 4 ms 8532 KB Output is correct
6 Correct 4 ms 8532 KB Output is correct
7 Correct 6 ms 9684 KB Output is correct
8 Correct 6 ms 9684 KB Output is correct
9 Correct 7 ms 9684 KB Output is correct
10 Correct 9 ms 9692 KB Output is correct
11 Correct 6 ms 9684 KB Output is correct
12 Correct 6 ms 9684 KB Output is correct
13 Correct 4 ms 8660 KB Output is correct
14 Correct 5 ms 8788 KB Output is correct
15 Correct 6 ms 9428 KB Output is correct
16 Correct 7 ms 9720 KB Output is correct
17 Correct 8 ms 9428 KB Output is correct
18 Correct 6 ms 9684 KB Output is correct
19 Correct 6 ms 9680 KB Output is correct
20 Correct 6 ms 9940 KB Output is correct
21 Correct 6 ms 9428 KB Output is correct
22 Correct 6 ms 9556 KB Output is correct
23 Correct 8 ms 9828 KB Output is correct
24 Correct 6 ms 10068 KB Output is correct
25 Correct 6 ms 8576 KB Output is correct
26 Correct 5 ms 8576 KB Output is correct
27 Correct 8 ms 9756 KB Output is correct
28 Correct 7 ms 9760 KB Output is correct
29 Correct 8 ms 9684 KB Output is correct
30 Correct 6 ms 9684 KB Output is correct
31 Correct 6 ms 9684 KB Output is correct
32 Correct 6 ms 9684 KB Output is correct
33 Correct 5 ms 8648 KB Output is correct
34 Correct 4 ms 8748 KB Output is correct
35 Correct 6 ms 9556 KB Output is correct
36 Correct 6 ms 9812 KB Output is correct
37 Correct 6 ms 9556 KB Output is correct
38 Correct 7 ms 9940 KB Output is correct
39 Correct 82 ms 35260 KB Output is correct
40 Correct 103 ms 45980 KB Output is correct
41 Correct 91 ms 37328 KB Output is correct
42 Correct 84 ms 37068 KB Output is correct
43 Correct 128 ms 48684 KB Output is correct
44 Correct 108 ms 48736 KB Output is correct
45 Correct 18 ms 9812 KB Output is correct
46 Correct 21 ms 9812 KB Output is correct
47 Correct 88 ms 37796 KB Output is correct
48 Correct 84 ms 37912 KB Output is correct
49 Correct 97 ms 37964 KB Output is correct
50 Correct 85 ms 38052 KB Output is correct
51 Correct 93 ms 42940 KB Output is correct
52 Correct 110 ms 49124 KB Output is correct
53 Correct 123 ms 63840 KB Output is correct
54 Correct 142 ms 67236 KB Output is correct
55 Correct 801 ms 201040 KB Output is correct
56 Correct 602 ms 161796 KB Output is correct
57 Correct 845 ms 220852 KB Output is correct
58 Correct 819 ms 242008 KB Output is correct
59 Correct 819 ms 237388 KB Output is correct
60 Execution timed out 1099 ms 305540 KB Time limit exceeded
61 Halted 0 ms 0 KB -