답안 #684587

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
684587 2023-01-21T21:58:31 Z NK_ 푸드 코트 (JOI21_foodcourt) C++17
24 / 100
74 ms 42892 KB
// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>

using namespace std;

#define nl '\n'

using ll = long long;

using T = array<ll, 2>;

struct Seg {
	vector<ll> suf, pos, all; int N;

	void init(int n) {
		N = 1; while(N < n) N *= 2; 
		suf.assign(2*N, 0); pos.assign(2*N, 0); all.assign(2*N, 0);
	}

	void pull(int p) {
		pos[p] = pos[2*p] + pos[2*p+1];
		all[p] = all[2*p] + all[2*p+1];
		suf[p] = max(suf[2*p] + all[2*p+1], suf[2*p+1]);
	}

	void upd(int p, ll v, int x, int L, int R) {
		if (p < L || R < p) return;
		if (L == R) {
			suf[x] = all[x] = v;
			pos[x] = max(v, 0LL);
			return;
		}

		int M = (L+R)/2;
		upd(p, v, 2*x, L, M); upd(p, v, 2*x+1, M+1, R);
		pull(x);
	}


	T max_suf(int l, int r, int x, int L, int R) {
		if (r < L || R < l) return T{0, 0};
		if (l <= L && R <= r) return T{suf[x], all[x]};

		int M = (L+R)/2;
		T a = max_suf(l, r, 2*x, L, M), b = max_suf(l, r, 2*x+1, M+1, R);

		return {max(a[0] + b[1], b[0]), a[1] + b[1]};
	};

	ll sum_pos(int l, int r, int x, int L, int R) {
		if (r < L || R < l) return 0;
		if (l <= L && R <= r) return pos[x];
		int M = (L+R)/2;
		return sum_pos(l, r, 2*x, L, M) + sum_pos(l, r, 2*x+1, M+1, R);
	}

	int walk(int l, int r, ll v, ll V, int x, int L, int R) {
		// cout << x << " " << L << " " << R << " " << V << endl;
		// cout << l << " " << r << " " << v << endl;
		if (r < L || R < l || v > V) return -1;
		if (L == R) return L;

		int M = (L+R)/2;

		int res = walk(l, r, v, V - pos[2*x+1], 2*x, L, M);
		if (res == -1) return walk(l, r, v, V, 2*x+1, M+1, R);
		return res;
	}

	void upd(int p, int x) { upd(p, x, 1, 0, N-1); }
	T max_suf(int l, int r) { return max_suf(l, r, 1, 0, N-1); }
	ll sum_pos(int l, int r) { return sum_pos(l, r, 1, 0, N-1); }
	ll walk(int l, int r, ll v) { return walk(l, r, v, pos[1], 1, 0, N-1); }
};



int main() {
	cin.tie(0)->sync_with_stdio(0);
	
	int N, M, Q; cin >> N >> M >> Q;

	vector<vector<int>> QL(N), QR(N), QQ(N);

	vector<int> C(Q), K(Q);

	for(int q = 0; q < Q; q++) {
		int t; cin >> t;
		if (t == 1) {
			int l, r; cin >> l >> r >> C[q] >> K[q]; --l, --r;
			QL[l].push_back(q);
			QR[r].push_back(q);
		}

		if (t == 2) {
			int l, r; cin >> l >> r >> K[q]; --l, --r;
			K[q] = -K[q], C[q] = -1;
			QL[l].push_back(q);
			QR[r].push_back(q);
		}

		if (t == 3) {
			int i; cin >> i >> K[q]; --i;
			QQ[i].push_back(q);
		}
	}

	Seg st; st.init(Q);

	vector<ll> ans(Q, -1);

	for(int i = 0; i < N; i++) {
		for(auto q : QL[i]) { st.upd(q, K[q]);/* cout << "ON: " << q << endl;*/ }

		for(auto q : QQ[i]) {
			ll pos = st.sum_pos(0, q), suf = st.max_suf(0, q)[0];

			ll I = pos - suf + K[q];
			// cout << "INFO: " << q << " " << pos << " " << suf << " " << I << endl;

			int res = st.walk(0, q, I);
			assert(res == -1 || res <= q);
			ans[q] = (res == -1 ? 0 : C[res]);
			// cout << "DONE: " << res << endl;
		}

		for(auto q : QR[i]) { st.upd(q, 0); /*cout << "OFF: " << q << endl;*/ }
	}

	for(int q = 0; q < Q; q++) if (ans[q] != -1) cout << ans[q] << nl;

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 2 ms 596 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 2 ms 596 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 2 ms 596 KB Output is correct
8 Correct 2 ms 596 KB Output is correct
9 Correct 2 ms 596 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
11 Correct 2 ms 596 KB Output is correct
12 Correct 2 ms 596 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 1 ms 576 KB Output is correct
16 Correct 1 ms 596 KB Output is correct
17 Correct 2 ms 596 KB Output is correct
18 Correct 2 ms 596 KB Output is correct
19 Correct 2 ms 596 KB Output is correct
20 Correct 2 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 2 ms 596 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 2 ms 596 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 2 ms 596 KB Output is correct
8 Correct 2 ms 596 KB Output is correct
9 Correct 2 ms 596 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
11 Correct 2 ms 596 KB Output is correct
12 Correct 2 ms 596 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 1 ms 576 KB Output is correct
16 Correct 1 ms 596 KB Output is correct
17 Correct 2 ms 596 KB Output is correct
18 Correct 2 ms 596 KB Output is correct
19 Correct 2 ms 596 KB Output is correct
20 Correct 2 ms 596 KB Output is correct
21 Runtime error 1 ms 724 KB Execution killed with signal 11
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 68 ms 12360 KB Output is correct
2 Correct 71 ms 11992 KB Output is correct
3 Correct 67 ms 12356 KB Output is correct
4 Correct 74 ms 12420 KB Output is correct
5 Correct 69 ms 11592 KB Output is correct
6 Correct 74 ms 12480 KB Output is correct
7 Correct 34 ms 5024 KB Output is correct
8 Correct 37 ms 5836 KB Output is correct
9 Correct 71 ms 12300 KB Output is correct
10 Correct 64 ms 12392 KB Output is correct
11 Correct 66 ms 12388 KB Output is correct
12 Correct 67 ms 12364 KB Output is correct
13 Correct 56 ms 10400 KB Output is correct
14 Correct 72 ms 12376 KB Output is correct
15 Correct 62 ms 10596 KB Output is correct
16 Correct 74 ms 12524 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 30 ms 42892 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 2 ms 596 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 2 ms 596 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 2 ms 596 KB Output is correct
8 Correct 2 ms 596 KB Output is correct
9 Correct 2 ms 596 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
11 Correct 2 ms 596 KB Output is correct
12 Correct 2 ms 596 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 1 ms 576 KB Output is correct
16 Correct 1 ms 596 KB Output is correct
17 Correct 2 ms 596 KB Output is correct
18 Correct 2 ms 596 KB Output is correct
19 Correct 2 ms 596 KB Output is correct
20 Correct 2 ms 596 KB Output is correct
21 Correct 68 ms 12360 KB Output is correct
22 Correct 71 ms 11992 KB Output is correct
23 Correct 67 ms 12356 KB Output is correct
24 Correct 74 ms 12420 KB Output is correct
25 Correct 69 ms 11592 KB Output is correct
26 Correct 74 ms 12480 KB Output is correct
27 Correct 34 ms 5024 KB Output is correct
28 Correct 37 ms 5836 KB Output is correct
29 Correct 71 ms 12300 KB Output is correct
30 Correct 64 ms 12392 KB Output is correct
31 Correct 66 ms 12388 KB Output is correct
32 Correct 67 ms 12364 KB Output is correct
33 Correct 56 ms 10400 KB Output is correct
34 Correct 72 ms 12376 KB Output is correct
35 Correct 62 ms 10596 KB Output is correct
36 Correct 74 ms 12524 KB Output is correct
37 Correct 56 ms 11532 KB Output is correct
38 Correct 53 ms 11204 KB Output is correct
39 Correct 35 ms 5320 KB Output is correct
40 Correct 36 ms 5624 KB Output is correct
41 Correct 66 ms 12128 KB Output is correct
42 Correct 65 ms 12124 KB Output is correct
43 Correct 73 ms 12184 KB Output is correct
44 Correct 68 ms 12136 KB Output is correct
45 Correct 74 ms 12320 KB Output is correct
46 Correct 67 ms 12124 KB Output is correct
47 Correct 50 ms 10816 KB Output is correct
48 Correct 54 ms 11092 KB Output is correct
49 Correct 45 ms 9704 KB Output is correct
50 Correct 56 ms 11800 KB Output is correct
51 Correct 71 ms 12224 KB Output is correct
52 Correct 66 ms 12216 KB Output is correct
53 Correct 52 ms 11136 KB Output is correct
54 Correct 68 ms 12348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 9 ms 12532 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 2 ms 596 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 2 ms 596 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 2 ms 596 KB Output is correct
8 Correct 2 ms 596 KB Output is correct
9 Correct 2 ms 596 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
11 Correct 2 ms 596 KB Output is correct
12 Correct 2 ms 596 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 1 ms 576 KB Output is correct
16 Correct 1 ms 596 KB Output is correct
17 Correct 2 ms 596 KB Output is correct
18 Correct 2 ms 596 KB Output is correct
19 Correct 2 ms 596 KB Output is correct
20 Correct 2 ms 596 KB Output is correct
21 Runtime error 1 ms 724 KB Execution killed with signal 11
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 2 ms 596 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 2 ms 596 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 2 ms 596 KB Output is correct
8 Correct 2 ms 596 KB Output is correct
9 Correct 2 ms 596 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
11 Correct 2 ms 596 KB Output is correct
12 Correct 2 ms 596 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 1 ms 576 KB Output is correct
16 Correct 1 ms 596 KB Output is correct
17 Correct 2 ms 596 KB Output is correct
18 Correct 2 ms 596 KB Output is correct
19 Correct 2 ms 596 KB Output is correct
20 Correct 2 ms 596 KB Output is correct
21 Runtime error 1 ms 724 KB Execution killed with signal 11
22 Halted 0 ms 0 KB -