답안 #1104957

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1104957 2024-10-25T00:43:59 Z penguinhacker 푸드 코트 (JOI21_foodcourt) C++17
68 / 100
1000 ms 41548 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ar array

const int mxN=250000;
int n, m, q, qs[mxN], ans[mxN];
ar<ll, 3> st[1<<19]; // sum, suf, sum of negs
vector<ar<int, 2>> changes[mxN];
vector<ar<ll, 2>> qq[mxN];

ar<ll, 3> cmb(ar<ll, 3> a, ar<ll, 3> b) {
	return {a[0]+b[0], max(a[1]+b[0], b[1]), a[2]+b[2]};
}

void upd(int i, int x, int u=1, int l=0, int r=q-1) {
	if (l==r) {
		st[u][0]+=x;
		st[u][1]=max(st[u][0], 0ll);
		st[u][2]=min(st[u][0], 0ll);
		return;
	}
	int mid=(l+r)/2;
	if (i<=mid)
		upd(i, x, 2*u, l, mid);
	else
		upd(i, x, 2*u+1, mid+1, r);
	st[u]=cmb(st[2*u], st[2*u+1]);
}

ar<ll, 3> qry1(int ql, int qr, int u=1, int l=0, int r=q-1) {
	if (l>qr||r<ql)
		return {};
	if (ql<=l&&r<=qr)
		return st[u];
	int mid=(l+r)/2;
	return cmb(qry1(ql, qr, 2*u, l, mid), qry1(ql, qr, 2*u+1, mid+1, r));
}

ar<ll, 2> qry2(int ql, ll k, int u=1, int l=0, int r=q-1) {
	if (r<ql)
		return {-1, 0};
	if (ql<=l&&st[u][2]<k)
		return {-1, st[u][0]};
	if (l==r)
		return {l, 0};
	int mid=(l+r)/2;
	ar<ll, 2> x=qry2(k, 2*u, l, mid);
	if (x[0]!=-1)
		return x;
	return qry2(k-x[1], 2*u+1, mid+1, r);
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> m >> q;
	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;
			qs[i]=c;
			changes[l].push_back({i, k});
			if (r+1<n)
				changes[r+1].push_back({i, -k});
		} else if (t==2) {
			int l, r, k;
			cin >> l >> r >> k, --l, --r;
			changes[l].push_back({i, -k});
			if (r+1<n)
				changes[r+1].push_back({i, k});
		} else {
			int a;
			ll b;
			cin >> a >> b, --a;
			qq[a].push_back({i, b});
		}
		ans[i]=-1;
	}
	for (int i=0; i<n; ++i) {
		for (auto [t, k] : changes[i])
			upd(t, k);
		for (auto [ind, k] : qq[i]) {
			ar<ll, 3> x=qry1(0, ind);
			if (x[1]<k) {
				ans[ind]=0;
				continue;
			}
			int lb=0, rb=ind;
			while(lb<rb) {
				int mid=(lb+rb+1)/2;
				if (qry1(mid, ind)[1]==x[1])
					lb=mid;
				else
					rb=mid-1;
			}
			ll neg=qry1(lb, ind)[2];
			int s=lb;
			rb=ind;
			while(lb<rb) {
				int mid=(lb+rb)/2;
				ar<ll, 3> y=qry1(s, mid);
				if (y[0]-y[2]+neg>=k)
					rb=mid;
				else
					lb=mid+1;
			}
			ans[ind]=qs[lb];
		}
	}
	for (int i=0; i<q; ++i)
		if (~ans[i])
			cout << ans[i] << "\n";
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 14928 KB Output is correct
2 Correct 6 ms 15032 KB Output is correct
3 Correct 4 ms 15096 KB Output is correct
4 Correct 5 ms 15124 KB Output is correct
5 Correct 4 ms 15032 KB Output is correct
6 Correct 4 ms 14928 KB Output is correct
7 Correct 5 ms 14928 KB Output is correct
8 Correct 5 ms 15024 KB Output is correct
9 Correct 5 ms 14928 KB Output is correct
10 Correct 5 ms 14928 KB Output is correct
11 Correct 5 ms 14928 KB Output is correct
12 Correct 5 ms 14928 KB Output is correct
13 Correct 4 ms 14928 KB Output is correct
14 Correct 5 ms 15088 KB Output is correct
15 Correct 4 ms 15016 KB Output is correct
16 Correct 5 ms 14968 KB Output is correct
17 Correct 5 ms 14928 KB Output is correct
18 Correct 5 ms 14928 KB Output is correct
19 Correct 4 ms 15016 KB Output is correct
20 Correct 4 ms 14928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 14928 KB Output is correct
2 Correct 6 ms 15032 KB Output is correct
3 Correct 4 ms 15096 KB Output is correct
4 Correct 5 ms 15124 KB Output is correct
5 Correct 4 ms 15032 KB Output is correct
6 Correct 4 ms 14928 KB Output is correct
7 Correct 5 ms 14928 KB Output is correct
8 Correct 5 ms 15024 KB Output is correct
9 Correct 5 ms 14928 KB Output is correct
10 Correct 5 ms 14928 KB Output is correct
11 Correct 5 ms 14928 KB Output is correct
12 Correct 5 ms 14928 KB Output is correct
13 Correct 4 ms 14928 KB Output is correct
14 Correct 5 ms 15088 KB Output is correct
15 Correct 4 ms 15016 KB Output is correct
16 Correct 5 ms 14968 KB Output is correct
17 Correct 5 ms 14928 KB Output is correct
18 Correct 5 ms 14928 KB Output is correct
19 Correct 4 ms 15016 KB Output is correct
20 Correct 4 ms 14928 KB Output is correct
21 Correct 5 ms 14928 KB Output is correct
22 Correct 5 ms 15136 KB Output is correct
23 Correct 5 ms 14928 KB Output is correct
24 Correct 5 ms 14928 KB Output is correct
25 Correct 4 ms 15040 KB Output is correct
26 Correct 4 ms 14928 KB Output is correct
27 Correct 5 ms 14928 KB Output is correct
28 Correct 5 ms 14928 KB Output is correct
29 Correct 5 ms 14928 KB Output is correct
30 Correct 5 ms 15012 KB Output is correct
31 Correct 5 ms 14928 KB Output is correct
32 Correct 5 ms 14928 KB Output is correct
33 Correct 4 ms 15068 KB Output is correct
34 Correct 5 ms 14928 KB Output is correct
35 Correct 5 ms 14928 KB Output is correct
36 Correct 5 ms 15012 KB Output is correct
37 Correct 3 ms 15016 KB Output is correct
38 Correct 4 ms 14928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 21132 KB Output is correct
2 Correct 48 ms 21056 KB Output is correct
3 Correct 46 ms 21072 KB Output is correct
4 Correct 45 ms 21072 KB Output is correct
5 Correct 45 ms 21128 KB Output is correct
6 Correct 49 ms 21064 KB Output is correct
7 Correct 46 ms 19024 KB Output is correct
8 Correct 54 ms 19268 KB Output is correct
9 Correct 52 ms 20880 KB Output is correct
10 Correct 55 ms 21060 KB Output is correct
11 Correct 49 ms 21064 KB Output is correct
12 Correct 49 ms 21072 KB Output is correct
13 Correct 68 ms 20528 KB Output is correct
14 Correct 69 ms 20816 KB Output is correct
15 Correct 49 ms 20808 KB Output is correct
16 Correct 48 ms 21072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 849 ms 39832 KB Output is correct
2 Correct 616 ms 36864 KB Output is correct
3 Correct 872 ms 41384 KB Output is correct
4 Correct 552 ms 37192 KB Output is correct
5 Correct 542 ms 36992 KB Output is correct
6 Correct 739 ms 41548 KB Output is correct
7 Correct 688 ms 34748 KB Output is correct
8 Correct 645 ms 33572 KB Output is correct
9 Execution timed out 1066 ms 41288 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 14928 KB Output is correct
2 Correct 6 ms 15032 KB Output is correct
3 Correct 4 ms 15096 KB Output is correct
4 Correct 5 ms 15124 KB Output is correct
5 Correct 4 ms 15032 KB Output is correct
6 Correct 4 ms 14928 KB Output is correct
7 Correct 5 ms 14928 KB Output is correct
8 Correct 5 ms 15024 KB Output is correct
9 Correct 5 ms 14928 KB Output is correct
10 Correct 5 ms 14928 KB Output is correct
11 Correct 5 ms 14928 KB Output is correct
12 Correct 5 ms 14928 KB Output is correct
13 Correct 4 ms 14928 KB Output is correct
14 Correct 5 ms 15088 KB Output is correct
15 Correct 4 ms 15016 KB Output is correct
16 Correct 5 ms 14968 KB Output is correct
17 Correct 5 ms 14928 KB Output is correct
18 Correct 5 ms 14928 KB Output is correct
19 Correct 4 ms 15016 KB Output is correct
20 Correct 4 ms 14928 KB Output is correct
21 Correct 42 ms 21132 KB Output is correct
22 Correct 48 ms 21056 KB Output is correct
23 Correct 46 ms 21072 KB Output is correct
24 Correct 45 ms 21072 KB Output is correct
25 Correct 45 ms 21128 KB Output is correct
26 Correct 49 ms 21064 KB Output is correct
27 Correct 46 ms 19024 KB Output is correct
28 Correct 54 ms 19268 KB Output is correct
29 Correct 52 ms 20880 KB Output is correct
30 Correct 55 ms 21060 KB Output is correct
31 Correct 49 ms 21064 KB Output is correct
32 Correct 49 ms 21072 KB Output is correct
33 Correct 68 ms 20528 KB Output is correct
34 Correct 69 ms 20816 KB Output is correct
35 Correct 49 ms 20808 KB Output is correct
36 Correct 48 ms 21072 KB Output is correct
37 Correct 140 ms 20464 KB Output is correct
38 Correct 107 ms 20144 KB Output is correct
39 Correct 80 ms 18880 KB Output is correct
40 Correct 102 ms 18812 KB Output is correct
41 Correct 129 ms 20828 KB Output is correct
42 Correct 129 ms 20908 KB Output is correct
43 Correct 120 ms 20816 KB Output is correct
44 Correct 127 ms 20816 KB Output is correct
45 Correct 133 ms 20816 KB Output is correct
46 Correct 123 ms 20808 KB Output is correct
47 Correct 165 ms 19400 KB Output is correct
48 Correct 165 ms 20304 KB Output is correct
49 Correct 73 ms 19876 KB Output is correct
50 Correct 85 ms 20304 KB Output is correct
51 Correct 98 ms 20828 KB Output is correct
52 Correct 113 ms 20808 KB Output is correct
53 Correct 43 ms 20304 KB Output is correct
54 Correct 57 ms 20940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 213 ms 21088 KB Output is correct
2 Correct 265 ms 21384 KB Output is correct
3 Correct 240 ms 21520 KB Output is correct
4 Correct 183 ms 20296 KB Output is correct
5 Correct 220 ms 21076 KB Output is correct
6 Correct 252 ms 21576 KB Output is correct
7 Correct 147 ms 19644 KB Output is correct
8 Correct 167 ms 19416 KB Output is correct
9 Correct 194 ms 20340 KB Output is correct
10 Correct 124 ms 19792 KB Output is correct
11 Correct 204 ms 20824 KB Output is correct
12 Correct 196 ms 20816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 14928 KB Output is correct
2 Correct 6 ms 15032 KB Output is correct
3 Correct 4 ms 15096 KB Output is correct
4 Correct 5 ms 15124 KB Output is correct
5 Correct 4 ms 15032 KB Output is correct
6 Correct 4 ms 14928 KB Output is correct
7 Correct 5 ms 14928 KB Output is correct
8 Correct 5 ms 15024 KB Output is correct
9 Correct 5 ms 14928 KB Output is correct
10 Correct 5 ms 14928 KB Output is correct
11 Correct 5 ms 14928 KB Output is correct
12 Correct 5 ms 14928 KB Output is correct
13 Correct 4 ms 14928 KB Output is correct
14 Correct 5 ms 15088 KB Output is correct
15 Correct 4 ms 15016 KB Output is correct
16 Correct 5 ms 14968 KB Output is correct
17 Correct 5 ms 14928 KB Output is correct
18 Correct 5 ms 14928 KB Output is correct
19 Correct 4 ms 15016 KB Output is correct
20 Correct 4 ms 14928 KB Output is correct
21 Correct 5 ms 14928 KB Output is correct
22 Correct 5 ms 15136 KB Output is correct
23 Correct 5 ms 14928 KB Output is correct
24 Correct 5 ms 14928 KB Output is correct
25 Correct 4 ms 15040 KB Output is correct
26 Correct 4 ms 14928 KB Output is correct
27 Correct 5 ms 14928 KB Output is correct
28 Correct 5 ms 14928 KB Output is correct
29 Correct 5 ms 14928 KB Output is correct
30 Correct 5 ms 15012 KB Output is correct
31 Correct 5 ms 14928 KB Output is correct
32 Correct 5 ms 14928 KB Output is correct
33 Correct 4 ms 15068 KB Output is correct
34 Correct 5 ms 14928 KB Output is correct
35 Correct 5 ms 14928 KB Output is correct
36 Correct 5 ms 15012 KB Output is correct
37 Correct 3 ms 15016 KB Output is correct
38 Correct 4 ms 14928 KB Output is correct
39 Correct 42 ms 21132 KB Output is correct
40 Correct 48 ms 21056 KB Output is correct
41 Correct 46 ms 21072 KB Output is correct
42 Correct 45 ms 21072 KB Output is correct
43 Correct 45 ms 21128 KB Output is correct
44 Correct 49 ms 21064 KB Output is correct
45 Correct 46 ms 19024 KB Output is correct
46 Correct 54 ms 19268 KB Output is correct
47 Correct 52 ms 20880 KB Output is correct
48 Correct 55 ms 21060 KB Output is correct
49 Correct 49 ms 21064 KB Output is correct
50 Correct 49 ms 21072 KB Output is correct
51 Correct 68 ms 20528 KB Output is correct
52 Correct 69 ms 20816 KB Output is correct
53 Correct 49 ms 20808 KB Output is correct
54 Correct 48 ms 21072 KB Output is correct
55 Correct 140 ms 20464 KB Output is correct
56 Correct 107 ms 20144 KB Output is correct
57 Correct 80 ms 18880 KB Output is correct
58 Correct 102 ms 18812 KB Output is correct
59 Correct 129 ms 20828 KB Output is correct
60 Correct 129 ms 20908 KB Output is correct
61 Correct 120 ms 20816 KB Output is correct
62 Correct 127 ms 20816 KB Output is correct
63 Correct 133 ms 20816 KB Output is correct
64 Correct 123 ms 20808 KB Output is correct
65 Correct 165 ms 19400 KB Output is correct
66 Correct 165 ms 20304 KB Output is correct
67 Correct 73 ms 19876 KB Output is correct
68 Correct 85 ms 20304 KB Output is correct
69 Correct 98 ms 20828 KB Output is correct
70 Correct 113 ms 20808 KB Output is correct
71 Correct 43 ms 20304 KB Output is correct
72 Correct 57 ms 20940 KB Output is correct
73 Correct 213 ms 21088 KB Output is correct
74 Correct 265 ms 21384 KB Output is correct
75 Correct 240 ms 21520 KB Output is correct
76 Correct 183 ms 20296 KB Output is correct
77 Correct 220 ms 21076 KB Output is correct
78 Correct 252 ms 21576 KB Output is correct
79 Correct 147 ms 19644 KB Output is correct
80 Correct 167 ms 19416 KB Output is correct
81 Correct 194 ms 20340 KB Output is correct
82 Correct 124 ms 19792 KB Output is correct
83 Correct 204 ms 20824 KB Output is correct
84 Correct 196 ms 20816 KB Output is correct
85 Correct 158 ms 21064 KB Output is correct
86 Correct 180 ms 21320 KB Output is correct
87 Correct 131 ms 21064 KB Output is correct
88 Correct 148 ms 21576 KB Output is correct
89 Correct 91 ms 20048 KB Output is correct
90 Correct 145 ms 21548 KB Output is correct
91 Correct 119 ms 20560 KB Output is correct
92 Correct 103 ms 20304 KB Output is correct
93 Correct 159 ms 21320 KB Output is correct
94 Correct 139 ms 21396 KB Output is correct
95 Correct 142 ms 21364 KB Output is correct
96 Correct 138 ms 21416 KB Output is correct
97 Correct 127 ms 21328 KB Output is correct
98 Correct 108 ms 20748 KB Output is correct
99 Correct 152 ms 20012 KB Output is correct
100 Correct 138 ms 20048 KB Output is correct
101 Correct 159 ms 20808 KB Output is correct
102 Correct 102 ms 21320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 14928 KB Output is correct
2 Correct 6 ms 15032 KB Output is correct
3 Correct 4 ms 15096 KB Output is correct
4 Correct 5 ms 15124 KB Output is correct
5 Correct 4 ms 15032 KB Output is correct
6 Correct 4 ms 14928 KB Output is correct
7 Correct 5 ms 14928 KB Output is correct
8 Correct 5 ms 15024 KB Output is correct
9 Correct 5 ms 14928 KB Output is correct
10 Correct 5 ms 14928 KB Output is correct
11 Correct 5 ms 14928 KB Output is correct
12 Correct 5 ms 14928 KB Output is correct
13 Correct 4 ms 14928 KB Output is correct
14 Correct 5 ms 15088 KB Output is correct
15 Correct 4 ms 15016 KB Output is correct
16 Correct 5 ms 14968 KB Output is correct
17 Correct 5 ms 14928 KB Output is correct
18 Correct 5 ms 14928 KB Output is correct
19 Correct 4 ms 15016 KB Output is correct
20 Correct 4 ms 14928 KB Output is correct
21 Correct 5 ms 14928 KB Output is correct
22 Correct 5 ms 15136 KB Output is correct
23 Correct 5 ms 14928 KB Output is correct
24 Correct 5 ms 14928 KB Output is correct
25 Correct 4 ms 15040 KB Output is correct
26 Correct 4 ms 14928 KB Output is correct
27 Correct 5 ms 14928 KB Output is correct
28 Correct 5 ms 14928 KB Output is correct
29 Correct 5 ms 14928 KB Output is correct
30 Correct 5 ms 15012 KB Output is correct
31 Correct 5 ms 14928 KB Output is correct
32 Correct 5 ms 14928 KB Output is correct
33 Correct 4 ms 15068 KB Output is correct
34 Correct 5 ms 14928 KB Output is correct
35 Correct 5 ms 14928 KB Output is correct
36 Correct 5 ms 15012 KB Output is correct
37 Correct 3 ms 15016 KB Output is correct
38 Correct 4 ms 14928 KB Output is correct
39 Correct 42 ms 21132 KB Output is correct
40 Correct 48 ms 21056 KB Output is correct
41 Correct 46 ms 21072 KB Output is correct
42 Correct 45 ms 21072 KB Output is correct
43 Correct 45 ms 21128 KB Output is correct
44 Correct 49 ms 21064 KB Output is correct
45 Correct 46 ms 19024 KB Output is correct
46 Correct 54 ms 19268 KB Output is correct
47 Correct 52 ms 20880 KB Output is correct
48 Correct 55 ms 21060 KB Output is correct
49 Correct 49 ms 21064 KB Output is correct
50 Correct 49 ms 21072 KB Output is correct
51 Correct 68 ms 20528 KB Output is correct
52 Correct 69 ms 20816 KB Output is correct
53 Correct 49 ms 20808 KB Output is correct
54 Correct 48 ms 21072 KB Output is correct
55 Correct 849 ms 39832 KB Output is correct
56 Correct 616 ms 36864 KB Output is correct
57 Correct 872 ms 41384 KB Output is correct
58 Correct 552 ms 37192 KB Output is correct
59 Correct 542 ms 36992 KB Output is correct
60 Correct 739 ms 41548 KB Output is correct
61 Correct 688 ms 34748 KB Output is correct
62 Correct 645 ms 33572 KB Output is correct
63 Execution timed out 1066 ms 41288 KB Time limit exceeded
64 Halted 0 ms 0 KB -