Submission #909878

# Submission time Handle Problem Language Result Execution time Memory
909878 2024-01-17T14:07:46 Z Trisanu_Das Food Court (JOI21_foodcourt) C++17
68 / 100
1000 ms 71712 KB
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define MAX 251010
#define MAXS 20
#define INF 1000000000000000001
#define bb ' '
#define ln '\n'
#define Ln '\n'
struct node {
	ll a, b;
	node() :a(0), b(0) {}
	node(ll a) :a(min(a, 0ll)), b(a) {}
	node(ll a, ll b) :a(a), b(b) {}
};
node operator+(node& n1, node& n2) {
	node ret;
	ret.a = min(n1.a, n1.b + n2.a);
	ret.b = n1.b + n2.b;
	return ret;
}
void operator+= (node& n1, node& n2) { n1 = n1 + n2; }
void operator+=(node& n1, ll x) {
	n1.b += x;
	n1.a = min(n1.a, n1.b);
}
void operator+=(ll& x, node n1) {
	x += n1.a;
	ll ub = n1.b - n1.a;
	x = max(x, 0ll);
	x += ub;
}
typedef pair<int, ll> T;
struct segtree {
	vector<vector<T>> tree;
	vector<node> lazy;
	vector<int> l, r;
	vector<ll> rcnt;
	int s;
	int qcnt = 0;
	void init(int x = 1) {
		if (x >= s) {
			l[x] = r[x] = x - s + 1;
			return;
		}
		init(x * 2);
		init(x * 2 + 1);
		l[x] = l[x * 2];
		r[x] = r[x * 2 + 1];
	}
	segtree(int N = 0) {
		s = 1 << (int)ceil(log2(N));
		tree = vector<vector<T>>(2 * s + 1, vector<T>(1, T(0, 0ll)));
		lazy.resize(2 * s + 1);
		l.resize(2 * s + 1);
		r.resize(2 * s + 1);
		rcnt.resize(2 * s + 1);
		init();
	}
	void add(int low, int high, int t, int num, int loc = 1) {
		if (low == l[loc] && high == r[loc]) {
			tree[loc].emplace_back(t, num + tree[loc].back().second);
			return;
		}
		if (high <= r[loc * 2]) add(low, high, t, num, loc * 2);
		else if (low >= l[loc * 2 + 1]) add(low, high, t, num, loc * 2 + 1);
		else add(low, r[loc * 2], t, num, loc * 2), add(l[loc * 2 + 1], high, t, num, loc * 2 + 1);
	}
	void prop(int loc) {
		if (loc >= s) return;
		for (auto c : { loc * 2, loc * 2 + 1 }) {
			rcnt[c] += lazy[loc];
			lazy[c] += lazy[loc];
		}
		lazy[loc] = node();
	}
	void updnt(int low, int high, node num, int loc = 1) {
		prop(loc);
		if (low == l[loc] && high == r[loc]) {
			rcnt[loc] += num;
			lazy[loc] += num;
			return;
		}
		if (high <= r[loc * 2]) updnt(low, high, num, loc * 2);
		else if (low >= l[loc * 2 + 1]) updnt(low, high, num, loc * 2 + 1);
		else updnt(low, r[loc * 2], num, loc * 2), updnt(l[loc * 2 + 1], high, num, loc * 2 + 1);
		rcnt[loc] = min(rcnt[loc * 2], rcnt[loc * 2 + 1]);
	}
	ll getrcnt(int x, int loc = 1) {
		prop(loc);
		if (l[loc] == r[loc]) return rcnt[loc];
		if (x <= r[loc * 2]) return getrcnt(x, loc * 2);
		else return getrcnt(x, loc * 2 + 1);
	}
	ll gettcnt(int x, int t, int loc = 1) {
		int ind = upper_bound(tree[loc].begin(), tree[loc].end(), T(t + 1, -1)) - tree[loc].begin();
		ind--;
		ll ans;
		if (ind < 0) ans = 0;
		else ans = tree[loc][ind].second;
		if (l[loc] == r[loc]) return ans;
		if (x <= r[loc * 2]) return ans + gettcnt(x, t, loc * 2);
		else return ans + gettcnt(x, t, loc * 2 + 1);
	}
	void update(int l, int r, int t, int n) {
		add(l, r, t, n);
		updnt(l, r, node(n));
		qcnt++;
	}
	void remove(int l, int r, int n) { qcnt++; updnt(l, r, node(-n)); }
	int query(int A, ll B) {
		qcnt++;
		ll nb = B + (gettcnt(A, qcnt) - getrcnt(A));
		int l, r;
		if (gettcnt(A, qcnt) < nb) return -1;
		l = 0, r = qcnt;
		while (r - l > 1) {
			int mid = (l + r + 1) / 2;
			if (gettcnt(A, mid) < nb) l = mid;
			else r = mid;
		}
		return r;
	}
};
int cn[MAX];
signed main() {
	ios::sync_with_stdio(false), cin.tie(0);
	int N, Q;
	cin >> N >> Q >> Q;
	segtree seg(N);
	int i;
	int t, l, r, c, k, a;
	ll b;
	for (i = 1; i <= Q; i++) {
		cin >> t;
		if (t == 1) cin >> l >> r >> c >> k, seg.update(l, r, i, k), cn[i] = c;
		if (t == 2) cin >> l >> r >> k, seg.remove(l, r, k);
		if (t == 3) {
			cin >> a >> b;
			int res = seg.query(a, b);
			if (!~res) cout << 0 << ln;
			else cout << cn[res] << ln;
		}
	}
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 856 KB Output is correct
2 Correct 3 ms 860 KB Output is correct
3 Correct 2 ms 860 KB Output is correct
4 Correct 3 ms 860 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 3 ms 860 KB Output is correct
8 Correct 4 ms 1028 KB Output is correct
9 Correct 3 ms 1112 KB Output is correct
10 Correct 3 ms 860 KB Output is correct
11 Correct 4 ms 860 KB Output is correct
12 Correct 3 ms 856 KB Output is correct
13 Correct 2 ms 856 KB Output is correct
14 Correct 2 ms 856 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 3 ms 860 KB Output is correct
18 Correct 3 ms 860 KB Output is correct
19 Correct 2 ms 860 KB Output is correct
20 Correct 3 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 856 KB Output is correct
2 Correct 3 ms 860 KB Output is correct
3 Correct 2 ms 860 KB Output is correct
4 Correct 3 ms 860 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 3 ms 860 KB Output is correct
8 Correct 4 ms 1028 KB Output is correct
9 Correct 3 ms 1112 KB Output is correct
10 Correct 3 ms 860 KB Output is correct
11 Correct 4 ms 860 KB Output is correct
12 Correct 3 ms 856 KB Output is correct
13 Correct 2 ms 856 KB Output is correct
14 Correct 2 ms 856 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 3 ms 860 KB Output is correct
18 Correct 3 ms 860 KB Output is correct
19 Correct 2 ms 860 KB Output is correct
20 Correct 3 ms 860 KB Output is correct
21 Correct 3 ms 860 KB Output is correct
22 Correct 3 ms 860 KB Output is correct
23 Correct 3 ms 1000 KB Output is correct
24 Correct 3 ms 856 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 2 ms 348 KB Output is correct
27 Correct 4 ms 860 KB Output is correct
28 Correct 3 ms 860 KB Output is correct
29 Correct 3 ms 860 KB Output is correct
30 Correct 3 ms 860 KB Output is correct
31 Correct 3 ms 856 KB Output is correct
32 Correct 3 ms 860 KB Output is correct
33 Correct 2 ms 860 KB Output is correct
34 Correct 2 ms 860 KB Output is correct
35 Correct 3 ms 964 KB Output is correct
36 Correct 3 ms 860 KB Output is correct
37 Correct 2 ms 876 KB Output is correct
38 Correct 3 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 118 ms 13996 KB Output is correct
2 Correct 95 ms 14420 KB Output is correct
3 Correct 90 ms 14160 KB Output is correct
4 Correct 90 ms 14120 KB Output is correct
5 Correct 131 ms 15272 KB Output is correct
6 Correct 101 ms 15188 KB Output is correct
7 Correct 20 ms 1244 KB Output is correct
8 Correct 23 ms 1256 KB Output is correct
9 Correct 110 ms 13740 KB Output is correct
10 Correct 138 ms 13908 KB Output is correct
11 Correct 85 ms 13904 KB Output is correct
12 Correct 86 ms 13908 KB Output is correct
13 Correct 73 ms 14416 KB Output is correct
14 Correct 110 ms 15148 KB Output is correct
15 Correct 92 ms 15732 KB Output is correct
16 Correct 101 ms 15960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1046 ms 71712 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 856 KB Output is correct
2 Correct 3 ms 860 KB Output is correct
3 Correct 2 ms 860 KB Output is correct
4 Correct 3 ms 860 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 3 ms 860 KB Output is correct
8 Correct 4 ms 1028 KB Output is correct
9 Correct 3 ms 1112 KB Output is correct
10 Correct 3 ms 860 KB Output is correct
11 Correct 4 ms 860 KB Output is correct
12 Correct 3 ms 856 KB Output is correct
13 Correct 2 ms 856 KB Output is correct
14 Correct 2 ms 856 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 3 ms 860 KB Output is correct
18 Correct 3 ms 860 KB Output is correct
19 Correct 2 ms 860 KB Output is correct
20 Correct 3 ms 860 KB Output is correct
21 Correct 118 ms 13996 KB Output is correct
22 Correct 95 ms 14420 KB Output is correct
23 Correct 90 ms 14160 KB Output is correct
24 Correct 90 ms 14120 KB Output is correct
25 Correct 131 ms 15272 KB Output is correct
26 Correct 101 ms 15188 KB Output is correct
27 Correct 20 ms 1244 KB Output is correct
28 Correct 23 ms 1256 KB Output is correct
29 Correct 110 ms 13740 KB Output is correct
30 Correct 138 ms 13908 KB Output is correct
31 Correct 85 ms 13904 KB Output is correct
32 Correct 86 ms 13908 KB Output is correct
33 Correct 73 ms 14416 KB Output is correct
34 Correct 110 ms 15148 KB Output is correct
35 Correct 92 ms 15732 KB Output is correct
36 Correct 101 ms 15960 KB Output is correct
37 Correct 183 ms 18484 KB Output is correct
38 Correct 218 ms 21600 KB Output is correct
39 Correct 20 ms 1756 KB Output is correct
40 Correct 30 ms 1884 KB Output is correct
41 Correct 205 ms 21352 KB Output is correct
42 Correct 198 ms 21516 KB Output is correct
43 Correct 251 ms 21488 KB Output is correct
44 Correct 250 ms 21588 KB Output is correct
45 Correct 234 ms 21568 KB Output is correct
46 Correct 195 ms 21620 KB Output is correct
47 Correct 94 ms 17136 KB Output is correct
48 Correct 156 ms 21692 KB Output is correct
49 Correct 118 ms 18996 KB Output is correct
50 Correct 171 ms 20728 KB Output is correct
51 Correct 180 ms 21672 KB Output is correct
52 Correct 179 ms 21644 KB Output is correct
53 Correct 81 ms 15956 KB Output is correct
54 Correct 117 ms 17140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 274 ms 21272 KB Output is correct
2 Correct 336 ms 23608 KB Output is correct
3 Correct 307 ms 24240 KB Output is correct
4 Correct 238 ms 20984 KB Output is correct
5 Correct 287 ms 22984 KB Output is correct
6 Correct 312 ms 24640 KB Output is correct
7 Correct 38 ms 2512 KB Output is correct
8 Correct 52 ms 2252 KB Output is correct
9 Correct 144 ms 19516 KB Output is correct
10 Correct 131 ms 21976 KB Output is correct
11 Correct 184 ms 25352 KB Output is correct
12 Correct 177 ms 25120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 856 KB Output is correct
2 Correct 3 ms 860 KB Output is correct
3 Correct 2 ms 860 KB Output is correct
4 Correct 3 ms 860 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 3 ms 860 KB Output is correct
8 Correct 4 ms 1028 KB Output is correct
9 Correct 3 ms 1112 KB Output is correct
10 Correct 3 ms 860 KB Output is correct
11 Correct 4 ms 860 KB Output is correct
12 Correct 3 ms 856 KB Output is correct
13 Correct 2 ms 856 KB Output is correct
14 Correct 2 ms 856 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 3 ms 860 KB Output is correct
18 Correct 3 ms 860 KB Output is correct
19 Correct 2 ms 860 KB Output is correct
20 Correct 3 ms 860 KB Output is correct
21 Correct 3 ms 860 KB Output is correct
22 Correct 3 ms 860 KB Output is correct
23 Correct 3 ms 1000 KB Output is correct
24 Correct 3 ms 856 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 2 ms 348 KB Output is correct
27 Correct 4 ms 860 KB Output is correct
28 Correct 3 ms 860 KB Output is correct
29 Correct 3 ms 860 KB Output is correct
30 Correct 3 ms 860 KB Output is correct
31 Correct 3 ms 856 KB Output is correct
32 Correct 3 ms 860 KB Output is correct
33 Correct 2 ms 860 KB Output is correct
34 Correct 2 ms 860 KB Output is correct
35 Correct 3 ms 964 KB Output is correct
36 Correct 3 ms 860 KB Output is correct
37 Correct 2 ms 876 KB Output is correct
38 Correct 3 ms 860 KB Output is correct
39 Correct 118 ms 13996 KB Output is correct
40 Correct 95 ms 14420 KB Output is correct
41 Correct 90 ms 14160 KB Output is correct
42 Correct 90 ms 14120 KB Output is correct
43 Correct 131 ms 15272 KB Output is correct
44 Correct 101 ms 15188 KB Output is correct
45 Correct 20 ms 1244 KB Output is correct
46 Correct 23 ms 1256 KB Output is correct
47 Correct 110 ms 13740 KB Output is correct
48 Correct 138 ms 13908 KB Output is correct
49 Correct 85 ms 13904 KB Output is correct
50 Correct 86 ms 13908 KB Output is correct
51 Correct 73 ms 14416 KB Output is correct
52 Correct 110 ms 15148 KB Output is correct
53 Correct 92 ms 15732 KB Output is correct
54 Correct 101 ms 15960 KB Output is correct
55 Correct 183 ms 18484 KB Output is correct
56 Correct 218 ms 21600 KB Output is correct
57 Correct 20 ms 1756 KB Output is correct
58 Correct 30 ms 1884 KB Output is correct
59 Correct 205 ms 21352 KB Output is correct
60 Correct 198 ms 21516 KB Output is correct
61 Correct 251 ms 21488 KB Output is correct
62 Correct 250 ms 21588 KB Output is correct
63 Correct 234 ms 21568 KB Output is correct
64 Correct 195 ms 21620 KB Output is correct
65 Correct 94 ms 17136 KB Output is correct
66 Correct 156 ms 21692 KB Output is correct
67 Correct 118 ms 18996 KB Output is correct
68 Correct 171 ms 20728 KB Output is correct
69 Correct 180 ms 21672 KB Output is correct
70 Correct 179 ms 21644 KB Output is correct
71 Correct 81 ms 15956 KB Output is correct
72 Correct 117 ms 17140 KB Output is correct
73 Correct 274 ms 21272 KB Output is correct
74 Correct 336 ms 23608 KB Output is correct
75 Correct 307 ms 24240 KB Output is correct
76 Correct 238 ms 20984 KB Output is correct
77 Correct 287 ms 22984 KB Output is correct
78 Correct 312 ms 24640 KB Output is correct
79 Correct 38 ms 2512 KB Output is correct
80 Correct 52 ms 2252 KB Output is correct
81 Correct 144 ms 19516 KB Output is correct
82 Correct 131 ms 21976 KB Output is correct
83 Correct 184 ms 25352 KB Output is correct
84 Correct 177 ms 25120 KB Output is correct
85 Correct 179 ms 19788 KB Output is correct
86 Correct 233 ms 20920 KB Output is correct
87 Correct 226 ms 22908 KB Output is correct
88 Correct 243 ms 24752 KB Output is correct
89 Correct 128 ms 18516 KB Output is correct
90 Correct 230 ms 22020 KB Output is correct
91 Correct 150 ms 19916 KB Output is correct
92 Correct 146 ms 19488 KB Output is correct
93 Correct 204 ms 21996 KB Output is correct
94 Correct 234 ms 22236 KB Output is correct
95 Correct 199 ms 21836 KB Output is correct
96 Correct 199 ms 22084 KB Output is correct
97 Correct 246 ms 22132 KB Output is correct
98 Correct 146 ms 20228 KB Output is correct
99 Correct 105 ms 17532 KB Output is correct
100 Correct 118 ms 19328 KB Output is correct
101 Correct 141 ms 21984 KB Output is correct
102 Correct 125 ms 18772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 856 KB Output is correct
2 Correct 3 ms 860 KB Output is correct
3 Correct 2 ms 860 KB Output is correct
4 Correct 3 ms 860 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 3 ms 860 KB Output is correct
8 Correct 4 ms 1028 KB Output is correct
9 Correct 3 ms 1112 KB Output is correct
10 Correct 3 ms 860 KB Output is correct
11 Correct 4 ms 860 KB Output is correct
12 Correct 3 ms 856 KB Output is correct
13 Correct 2 ms 856 KB Output is correct
14 Correct 2 ms 856 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 3 ms 860 KB Output is correct
18 Correct 3 ms 860 KB Output is correct
19 Correct 2 ms 860 KB Output is correct
20 Correct 3 ms 860 KB Output is correct
21 Correct 3 ms 860 KB Output is correct
22 Correct 3 ms 860 KB Output is correct
23 Correct 3 ms 1000 KB Output is correct
24 Correct 3 ms 856 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 2 ms 348 KB Output is correct
27 Correct 4 ms 860 KB Output is correct
28 Correct 3 ms 860 KB Output is correct
29 Correct 3 ms 860 KB Output is correct
30 Correct 3 ms 860 KB Output is correct
31 Correct 3 ms 856 KB Output is correct
32 Correct 3 ms 860 KB Output is correct
33 Correct 2 ms 860 KB Output is correct
34 Correct 2 ms 860 KB Output is correct
35 Correct 3 ms 964 KB Output is correct
36 Correct 3 ms 860 KB Output is correct
37 Correct 2 ms 876 KB Output is correct
38 Correct 3 ms 860 KB Output is correct
39 Correct 118 ms 13996 KB Output is correct
40 Correct 95 ms 14420 KB Output is correct
41 Correct 90 ms 14160 KB Output is correct
42 Correct 90 ms 14120 KB Output is correct
43 Correct 131 ms 15272 KB Output is correct
44 Correct 101 ms 15188 KB Output is correct
45 Correct 20 ms 1244 KB Output is correct
46 Correct 23 ms 1256 KB Output is correct
47 Correct 110 ms 13740 KB Output is correct
48 Correct 138 ms 13908 KB Output is correct
49 Correct 85 ms 13904 KB Output is correct
50 Correct 86 ms 13908 KB Output is correct
51 Correct 73 ms 14416 KB Output is correct
52 Correct 110 ms 15148 KB Output is correct
53 Correct 92 ms 15732 KB Output is correct
54 Correct 101 ms 15960 KB Output is correct
55 Execution timed out 1046 ms 71712 KB Time limit exceeded
56 Halted 0 ms 0 KB -