Submission #645395

# Submission time Handle Problem Language Result Execution time Memory
645395 2022-09-27T04:41:54 Z GusterGoose27 Food Court (JOI21_foodcourt) C++11
68 / 100
1000 ms 302236 KB
#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";
		}
	}
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9300 KB Output is correct
2 Correct 6 ms 9556 KB Output is correct
3 Correct 6 ms 9560 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 9688 KB Output is correct
8 Correct 6 ms 9692 KB Output is correct
9 Correct 6 ms 9716 KB Output is correct
10 Correct 7 ms 9812 KB Output is correct
11 Correct 6 ms 9812 KB Output is correct
12 Correct 6 ms 9684 KB Output is correct
13 Correct 4 ms 8788 KB Output is correct
14 Correct 5 ms 8788 KB Output is correct
15 Correct 5 ms 9556 KB Output is correct
16 Correct 6 ms 9808 KB Output is correct
17 Correct 6 ms 9428 KB Output is correct
18 Correct 6 ms 9812 KB Output is correct
19 Correct 6 ms 9812 KB Output is correct
20 Correct 6 ms 9940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9300 KB Output is correct
2 Correct 6 ms 9556 KB Output is correct
3 Correct 6 ms 9560 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 9688 KB Output is correct
8 Correct 6 ms 9692 KB Output is correct
9 Correct 6 ms 9716 KB Output is correct
10 Correct 7 ms 9812 KB Output is correct
11 Correct 6 ms 9812 KB Output is correct
12 Correct 6 ms 9684 KB Output is correct
13 Correct 4 ms 8788 KB Output is correct
14 Correct 5 ms 8788 KB Output is correct
15 Correct 5 ms 9556 KB Output is correct
16 Correct 6 ms 9808 KB Output is correct
17 Correct 6 ms 9428 KB Output is correct
18 Correct 6 ms 9812 KB Output is correct
19 Correct 6 ms 9812 KB Output is correct
20 Correct 6 ms 9940 KB Output is correct
21 Correct 5 ms 9556 KB Output is correct
22 Correct 6 ms 9556 KB Output is correct
23 Correct 6 ms 9812 KB Output is correct
24 Correct 7 ms 10068 KB Output is correct
25 Correct 4 ms 8540 KB Output is correct
26 Correct 4 ms 8540 KB Output is correct
27 Correct 8 ms 9804 KB Output is correct
28 Correct 6 ms 9744 KB Output is correct
29 Correct 6 ms 9812 KB Output is correct
30 Correct 6 ms 9812 KB Output is correct
31 Correct 6 ms 9684 KB Output is correct
32 Correct 6 ms 9736 KB Output is correct
33 Correct 5 ms 8792 KB Output is correct
34 Correct 5 ms 8788 KB Output is correct
35 Correct 6 ms 9684 KB Output is correct
36 Correct 6 ms 9764 KB Output is correct
37 Correct 6 ms 9556 KB Output is correct
38 Correct 7 ms 9948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 81 ms 36500 KB Output is correct
2 Correct 109 ms 47228 KB Output is correct
3 Correct 80 ms 38476 KB Output is correct
4 Correct 90 ms 38364 KB Output is correct
5 Correct 113 ms 49928 KB Output is correct
6 Correct 101 ms 49868 KB Output is correct
7 Correct 19 ms 10508 KB Output is correct
8 Correct 21 ms 10576 KB Output is correct
9 Correct 87 ms 39128 KB Output is correct
10 Correct 94 ms 39172 KB Output is correct
11 Correct 84 ms 39264 KB Output is correct
12 Correct 83 ms 39288 KB Output is correct
13 Correct 92 ms 43984 KB Output is correct
14 Correct 115 ms 50152 KB Output is correct
15 Correct 140 ms 65400 KB Output is correct
16 Correct 129 ms 68460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 797 ms 206512 KB Output is correct
2 Correct 604 ms 166132 KB Output is correct
3 Correct 880 ms 226764 KB Output is correct
4 Correct 843 ms 246416 KB Output is correct
5 Correct 854 ms 241876 KB Output is correct
6 Execution timed out 1095 ms 302236 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9300 KB Output is correct
2 Correct 6 ms 9556 KB Output is correct
3 Correct 6 ms 9560 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 9688 KB Output is correct
8 Correct 6 ms 9692 KB Output is correct
9 Correct 6 ms 9716 KB Output is correct
10 Correct 7 ms 9812 KB Output is correct
11 Correct 6 ms 9812 KB Output is correct
12 Correct 6 ms 9684 KB Output is correct
13 Correct 4 ms 8788 KB Output is correct
14 Correct 5 ms 8788 KB Output is correct
15 Correct 5 ms 9556 KB Output is correct
16 Correct 6 ms 9808 KB Output is correct
17 Correct 6 ms 9428 KB Output is correct
18 Correct 6 ms 9812 KB Output is correct
19 Correct 6 ms 9812 KB Output is correct
20 Correct 6 ms 9940 KB Output is correct
21 Correct 81 ms 36500 KB Output is correct
22 Correct 109 ms 47228 KB Output is correct
23 Correct 80 ms 38476 KB Output is correct
24 Correct 90 ms 38364 KB Output is correct
25 Correct 113 ms 49928 KB Output is correct
26 Correct 101 ms 49868 KB Output is correct
27 Correct 19 ms 10508 KB Output is correct
28 Correct 21 ms 10576 KB Output is correct
29 Correct 87 ms 39128 KB Output is correct
30 Correct 94 ms 39172 KB Output is correct
31 Correct 84 ms 39264 KB Output is correct
32 Correct 83 ms 39288 KB Output is correct
33 Correct 92 ms 43984 KB Output is correct
34 Correct 115 ms 50152 KB Output is correct
35 Correct 140 ms 65400 KB Output is correct
36 Correct 129 ms 68460 KB Output is correct
37 Correct 138 ms 52956 KB Output is correct
38 Correct 183 ms 67888 KB Output is correct
39 Correct 17 ms 10312 KB Output is correct
40 Correct 20 ms 11044 KB Output is correct
41 Correct 207 ms 65868 KB Output is correct
42 Correct 193 ms 66068 KB Output is correct
43 Correct 170 ms 65668 KB Output is correct
44 Correct 192 ms 65744 KB Output is correct
45 Correct 180 ms 65868 KB Output is correct
46 Correct 161 ms 65816 KB Output is correct
47 Correct 45 ms 16908 KB Output is correct
48 Correct 127 ms 66624 KB Output is correct
49 Correct 105 ms 49220 KB Output is correct
50 Correct 135 ms 59340 KB Output is correct
51 Correct 169 ms 67716 KB Output is correct
52 Correct 163 ms 67656 KB Output is correct
53 Correct 105 ms 55928 KB Output is correct
54 Correct 132 ms 68564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 268 ms 73164 KB Output is correct
2 Correct 306 ms 78284 KB Output is correct
3 Correct 305 ms 80960 KB Output is correct
4 Correct 201 ms 62472 KB Output is correct
5 Correct 275 ms 73168 KB Output is correct
6 Correct 303 ms 83096 KB Output is correct
7 Correct 26 ms 11504 KB Output is correct
8 Correct 27 ms 11932 KB Output is correct
9 Correct 69 ms 18256 KB Output is correct
10 Correct 140 ms 67444 KB Output is correct
11 Correct 211 ms 93260 KB Output is correct
12 Correct 212 ms 92788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9300 KB Output is correct
2 Correct 6 ms 9556 KB Output is correct
3 Correct 6 ms 9560 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 9688 KB Output is correct
8 Correct 6 ms 9692 KB Output is correct
9 Correct 6 ms 9716 KB Output is correct
10 Correct 7 ms 9812 KB Output is correct
11 Correct 6 ms 9812 KB Output is correct
12 Correct 6 ms 9684 KB Output is correct
13 Correct 4 ms 8788 KB Output is correct
14 Correct 5 ms 8788 KB Output is correct
15 Correct 5 ms 9556 KB Output is correct
16 Correct 6 ms 9808 KB Output is correct
17 Correct 6 ms 9428 KB Output is correct
18 Correct 6 ms 9812 KB Output is correct
19 Correct 6 ms 9812 KB Output is correct
20 Correct 6 ms 9940 KB Output is correct
21 Correct 5 ms 9556 KB Output is correct
22 Correct 6 ms 9556 KB Output is correct
23 Correct 6 ms 9812 KB Output is correct
24 Correct 7 ms 10068 KB Output is correct
25 Correct 4 ms 8540 KB Output is correct
26 Correct 4 ms 8540 KB Output is correct
27 Correct 8 ms 9804 KB Output is correct
28 Correct 6 ms 9744 KB Output is correct
29 Correct 6 ms 9812 KB Output is correct
30 Correct 6 ms 9812 KB Output is correct
31 Correct 6 ms 9684 KB Output is correct
32 Correct 6 ms 9736 KB Output is correct
33 Correct 5 ms 8792 KB Output is correct
34 Correct 5 ms 8788 KB Output is correct
35 Correct 6 ms 9684 KB Output is correct
36 Correct 6 ms 9764 KB Output is correct
37 Correct 6 ms 9556 KB Output is correct
38 Correct 7 ms 9948 KB Output is correct
39 Correct 81 ms 36500 KB Output is correct
40 Correct 109 ms 47228 KB Output is correct
41 Correct 80 ms 38476 KB Output is correct
42 Correct 90 ms 38364 KB Output is correct
43 Correct 113 ms 49928 KB Output is correct
44 Correct 101 ms 49868 KB Output is correct
45 Correct 19 ms 10508 KB Output is correct
46 Correct 21 ms 10576 KB Output is correct
47 Correct 87 ms 39128 KB Output is correct
48 Correct 94 ms 39172 KB Output is correct
49 Correct 84 ms 39264 KB Output is correct
50 Correct 83 ms 39288 KB Output is correct
51 Correct 92 ms 43984 KB Output is correct
52 Correct 115 ms 50152 KB Output is correct
53 Correct 140 ms 65400 KB Output is correct
54 Correct 129 ms 68460 KB Output is correct
55 Correct 138 ms 52956 KB Output is correct
56 Correct 183 ms 67888 KB Output is correct
57 Correct 17 ms 10312 KB Output is correct
58 Correct 20 ms 11044 KB Output is correct
59 Correct 207 ms 65868 KB Output is correct
60 Correct 193 ms 66068 KB Output is correct
61 Correct 170 ms 65668 KB Output is correct
62 Correct 192 ms 65744 KB Output is correct
63 Correct 180 ms 65868 KB Output is correct
64 Correct 161 ms 65816 KB Output is correct
65 Correct 45 ms 16908 KB Output is correct
66 Correct 127 ms 66624 KB Output is correct
67 Correct 105 ms 49220 KB Output is correct
68 Correct 135 ms 59340 KB Output is correct
69 Correct 169 ms 67716 KB Output is correct
70 Correct 163 ms 67656 KB Output is correct
71 Correct 105 ms 55928 KB Output is correct
72 Correct 132 ms 68564 KB Output is correct
73 Correct 268 ms 73164 KB Output is correct
74 Correct 306 ms 78284 KB Output is correct
75 Correct 305 ms 80960 KB Output is correct
76 Correct 201 ms 62472 KB Output is correct
77 Correct 275 ms 73168 KB Output is correct
78 Correct 303 ms 83096 KB Output is correct
79 Correct 26 ms 11504 KB Output is correct
80 Correct 27 ms 11932 KB Output is correct
81 Correct 69 ms 18256 KB Output is correct
82 Correct 140 ms 67444 KB Output is correct
83 Correct 211 ms 93260 KB Output is correct
84 Correct 212 ms 92788 KB Output is correct
85 Correct 145 ms 53124 KB Output is correct
86 Correct 178 ms 59408 KB Output is correct
87 Correct 202 ms 73892 KB Output is correct
88 Correct 230 ms 83000 KB Output is correct
89 Correct 122 ms 47244 KB Output is correct
90 Correct 218 ms 66704 KB Output is correct
91 Correct 132 ms 53964 KB Output is correct
92 Correct 133 ms 51612 KB Output is correct
93 Correct 164 ms 66260 KB Output is correct
94 Correct 186 ms 66636 KB Output is correct
95 Correct 179 ms 64512 KB Output is correct
96 Correct 164 ms 66764 KB Output is correct
97 Correct 173 ms 66656 KB Output is correct
98 Correct 133 ms 55932 KB Output is correct
99 Correct 54 ms 17416 KB Output is correct
100 Correct 110 ms 57832 KB Output is correct
101 Correct 127 ms 66888 KB Output is correct
102 Correct 151 ms 66016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9300 KB Output is correct
2 Correct 6 ms 9556 KB Output is correct
3 Correct 6 ms 9560 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 9688 KB Output is correct
8 Correct 6 ms 9692 KB Output is correct
9 Correct 6 ms 9716 KB Output is correct
10 Correct 7 ms 9812 KB Output is correct
11 Correct 6 ms 9812 KB Output is correct
12 Correct 6 ms 9684 KB Output is correct
13 Correct 4 ms 8788 KB Output is correct
14 Correct 5 ms 8788 KB Output is correct
15 Correct 5 ms 9556 KB Output is correct
16 Correct 6 ms 9808 KB Output is correct
17 Correct 6 ms 9428 KB Output is correct
18 Correct 6 ms 9812 KB Output is correct
19 Correct 6 ms 9812 KB Output is correct
20 Correct 6 ms 9940 KB Output is correct
21 Correct 5 ms 9556 KB Output is correct
22 Correct 6 ms 9556 KB Output is correct
23 Correct 6 ms 9812 KB Output is correct
24 Correct 7 ms 10068 KB Output is correct
25 Correct 4 ms 8540 KB Output is correct
26 Correct 4 ms 8540 KB Output is correct
27 Correct 8 ms 9804 KB Output is correct
28 Correct 6 ms 9744 KB Output is correct
29 Correct 6 ms 9812 KB Output is correct
30 Correct 6 ms 9812 KB Output is correct
31 Correct 6 ms 9684 KB Output is correct
32 Correct 6 ms 9736 KB Output is correct
33 Correct 5 ms 8792 KB Output is correct
34 Correct 5 ms 8788 KB Output is correct
35 Correct 6 ms 9684 KB Output is correct
36 Correct 6 ms 9764 KB Output is correct
37 Correct 6 ms 9556 KB Output is correct
38 Correct 7 ms 9948 KB Output is correct
39 Correct 81 ms 36500 KB Output is correct
40 Correct 109 ms 47228 KB Output is correct
41 Correct 80 ms 38476 KB Output is correct
42 Correct 90 ms 38364 KB Output is correct
43 Correct 113 ms 49928 KB Output is correct
44 Correct 101 ms 49868 KB Output is correct
45 Correct 19 ms 10508 KB Output is correct
46 Correct 21 ms 10576 KB Output is correct
47 Correct 87 ms 39128 KB Output is correct
48 Correct 94 ms 39172 KB Output is correct
49 Correct 84 ms 39264 KB Output is correct
50 Correct 83 ms 39288 KB Output is correct
51 Correct 92 ms 43984 KB Output is correct
52 Correct 115 ms 50152 KB Output is correct
53 Correct 140 ms 65400 KB Output is correct
54 Correct 129 ms 68460 KB Output is correct
55 Correct 797 ms 206512 KB Output is correct
56 Correct 604 ms 166132 KB Output is correct
57 Correct 880 ms 226764 KB Output is correct
58 Correct 843 ms 246416 KB Output is correct
59 Correct 854 ms 241876 KB Output is correct
60 Execution timed out 1095 ms 302236 KB Time limit exceeded
61 Halted 0 ms 0 KB -