답안 #802402

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
802402 2023-08-02T12:08:05 Z Divane 푸드 코트 (JOI21_foodcourt) C++17
24 / 100
318 ms 51824 KB
/* In the name of GOD */

#include <bits/stdc++.h>

using namespace std;

#define F first
#define S second 
#define mk make_pair
typedef long long ll;
typedef long double ld;
typedef pair <long long, long long> pii;
const int N = 250012, SegN = (1 << 19);
const long long INF = 1e18 + 31;
pii lz[SegN];
ll slz[SegN];
int t[N], l[N], r[N], c[N], ans[N];
ll k[N], x[N];
vector <pair <ll, int>> v[N];
vector <pair <int, int>> s[N], e[N];
ll LZ[SegN];
ll MX[SegN];

void SHIFT (int v) {
	if (!LZ[v])
		return;
	LZ[v << 1] += LZ[v];
	LZ[v << 1 | 1] += LZ[v];
	MX[v << 1] += LZ[v];
	MX[v << 1 | 1] += LZ[v];
	LZ[v] = 0;
}

void ADD (int l, int r, int x, int v = 1, int tl = 0, int tr = N - 1) {
	if (tl > r || l > tr) 
		return;
	if (l <= tl && tr <= r) {
		LZ[v] += x;
		MX[v] += x;
	} else {
		SHIFT(v);
		int mid = (tl + tr) >> 1;
		ADD (l, r, x, v << 1, tl, mid);
		ADD (l, r, x, v << 1 | 1, mid + 1, tr);
		MX[v] = max(MX[v << 1], MX[v << 1 | 1]);
	}
}

int GET (int x, int v = 1, int tl = 0, int tr = N - 1) {
	if (x == -1)
		return 0;
	if (tl == tr) {
		return c[tl];
	}
	SHIFT(v);
	int mid = (tl + tr) >> 1;
	if (MX[v << 1] >= x) {
		return GET (x, v << 1, tl, mid);
	} else {
		return GET (x, v << 1 | 1, mid + 1, tr);
	}
}

void shift (int v) {
	ll x = lz[v].F, y = lz[v].S;
	lz[v << 1].F += x;
	lz[v << 1].S += x;
	lz[v << 1 | 1].F += x;
	lz[v << 1 | 1].S += x;
	lz[v << 1].S = max(lz[v << 1].S, y);
	lz[v << 1 | 1].S = max(lz[v << 1 | 1].S, y);
	slz[v << 1] += slz[v];
	slz[v << 1 | 1] += slz[v];
	lz[v] = mk(0, 0);
	slz[v] = 0;
}

void add (int l, int r, int x, int v = 1, int tl = 0, int tr = N - 1) {
//	cout << l << ' ' << r << ' ' << x << ' ' << v << ' ' << tl << ' ' << tr << '\n';
	if (tl > r || l > tr) 
		return;
	if (l <= tl && tr <= r) {
		//cout << "wef\n";
		slz[v] += max(0, x);
		lz[v].S += x;
		lz[v].F += x;
		//cout << lz[v].F << ' ' << lz[v].S << '\n';
	} else {
		shift(v);
		int mid = (tl + tr) >> 1;
		add (l, r, x, v << 1, tl, mid);
		add (l, r, x, v << 1 | 1, mid + 1, tr);
	}
}

pii get (int i, int v = 1, int tl = 0, int tr = N - 1) {
	if (tl == tr) 
		return mk(slz[v], max(lz[v].F, lz[v].S));
	shift(v);
	int mid = (tl + tr) >> 1;
	if (i <= mid)
		return get (i, v << 1, tl, mid);
	return get (i, v << 1 | 1, mid + 1, tr);
}

int32_t main () {
	ios::sync_with_stdio(false);
	cin.tie();
	for (int v = 0; v < SegN; v++)
		lz[v] = mk(0, 0);
	int n, m, q;
	cin >> n >> m >> q;
	for (int i = 0; i < q; i++) {
		ans[i] = -1;
		cin >> t[i];
		if (t[i] == 1) {
			cin >> l[i] >> r[i] >> c[i] >> k[i];
			s[l[i]].push_back(mk(i, k[i]));
			e[r[i]].push_back(mk(i, k[i]));
			add (l[i], r[i], k[i]);
		} else if (t[i] == 2) {
			cin >> l[i] >> r[i] >> k[i]; 
			add (l[i], r[i], -k[i]);
		} else {
			cin >> l[i] >> k[i];
			pii p = get (l[i]);
			if (k[i] > p.S) {
				x[i] = -1;
			} else {
				x[i] = p.F - p.S + k[i];
			}
			v[l[i]].push_back(mk(x[i], i));
		}
	}
	// FFFFFFFFFFFFFFFINALY
	for (int i = 1; i <= n; i++) {
		for (auto [tt, kk] : s[i]) {
			ADD (tt, N - 1, kk);
		}
		for (auto [j, ii] : v[i]) 
			ans[ii] = GET (j);
		for (auto [tt, kk] : e[i]) {
			ADD (tt, N - 1, -kk);
		}
	}
	for (int i = 0; i < q; i++) {
		if (ans[i] >= 0)
			cout << ans[i] << '\n';
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 26452 KB Output is correct
2 Correct 15 ms 26440 KB Output is correct
3 Correct 14 ms 26504 KB Output is correct
4 Correct 15 ms 26452 KB Output is correct
5 Correct 15 ms 26452 KB Output is correct
6 Correct 14 ms 26416 KB Output is correct
7 Correct 15 ms 26404 KB Output is correct
8 Correct 15 ms 26552 KB Output is correct
9 Correct 14 ms 26456 KB Output is correct
10 Correct 15 ms 26452 KB Output is correct
11 Correct 15 ms 26452 KB Output is correct
12 Correct 15 ms 26452 KB Output is correct
13 Correct 18 ms 26516 KB Output is correct
14 Correct 15 ms 26452 KB Output is correct
15 Correct 14 ms 26452 KB Output is correct
16 Correct 15 ms 26452 KB Output is correct
17 Correct 15 ms 26376 KB Output is correct
18 Correct 14 ms 26492 KB Output is correct
19 Correct 17 ms 26452 KB Output is correct
20 Correct 15 ms 26580 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 26452 KB Output is correct
2 Correct 15 ms 26440 KB Output is correct
3 Correct 14 ms 26504 KB Output is correct
4 Correct 15 ms 26452 KB Output is correct
5 Correct 15 ms 26452 KB Output is correct
6 Correct 14 ms 26416 KB Output is correct
7 Correct 15 ms 26404 KB Output is correct
8 Correct 15 ms 26552 KB Output is correct
9 Correct 14 ms 26456 KB Output is correct
10 Correct 15 ms 26452 KB Output is correct
11 Correct 15 ms 26452 KB Output is correct
12 Correct 15 ms 26452 KB Output is correct
13 Correct 18 ms 26516 KB Output is correct
14 Correct 15 ms 26452 KB Output is correct
15 Correct 14 ms 26452 KB Output is correct
16 Correct 15 ms 26452 KB Output is correct
17 Correct 15 ms 26376 KB Output is correct
18 Correct 14 ms 26492 KB Output is correct
19 Correct 17 ms 26452 KB Output is correct
20 Correct 15 ms 26580 KB Output is correct
21 Incorrect 15 ms 26452 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 75 ms 33572 KB Output is correct
2 Correct 76 ms 33864 KB Output is correct
3 Correct 71 ms 33612 KB Output is correct
4 Correct 71 ms 33568 KB Output is correct
5 Correct 82 ms 33920 KB Output is correct
6 Correct 78 ms 33872 KB Output is correct
7 Correct 48 ms 31376 KB Output is correct
8 Correct 48 ms 31348 KB Output is correct
9 Correct 83 ms 32724 KB Output is correct
10 Correct 75 ms 33540 KB Output is correct
11 Correct 70 ms 33268 KB Output is correct
12 Correct 73 ms 33540 KB Output is correct
13 Correct 67 ms 32960 KB Output is correct
14 Correct 77 ms 34004 KB Output is correct
15 Correct 92 ms 33776 KB Output is correct
16 Correct 98 ms 34408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 318 ms 51824 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 26452 KB Output is correct
2 Correct 15 ms 26440 KB Output is correct
3 Correct 14 ms 26504 KB Output is correct
4 Correct 15 ms 26452 KB Output is correct
5 Correct 15 ms 26452 KB Output is correct
6 Correct 14 ms 26416 KB Output is correct
7 Correct 15 ms 26404 KB Output is correct
8 Correct 15 ms 26552 KB Output is correct
9 Correct 14 ms 26456 KB Output is correct
10 Correct 15 ms 26452 KB Output is correct
11 Correct 15 ms 26452 KB Output is correct
12 Correct 15 ms 26452 KB Output is correct
13 Correct 18 ms 26516 KB Output is correct
14 Correct 15 ms 26452 KB Output is correct
15 Correct 14 ms 26452 KB Output is correct
16 Correct 15 ms 26452 KB Output is correct
17 Correct 15 ms 26376 KB Output is correct
18 Correct 14 ms 26492 KB Output is correct
19 Correct 17 ms 26452 KB Output is correct
20 Correct 15 ms 26580 KB Output is correct
21 Correct 75 ms 33572 KB Output is correct
22 Correct 76 ms 33864 KB Output is correct
23 Correct 71 ms 33612 KB Output is correct
24 Correct 71 ms 33568 KB Output is correct
25 Correct 82 ms 33920 KB Output is correct
26 Correct 78 ms 33872 KB Output is correct
27 Correct 48 ms 31376 KB Output is correct
28 Correct 48 ms 31348 KB Output is correct
29 Correct 83 ms 32724 KB Output is correct
30 Correct 75 ms 33540 KB Output is correct
31 Correct 70 ms 33268 KB Output is correct
32 Correct 73 ms 33540 KB Output is correct
33 Correct 67 ms 32960 KB Output is correct
34 Correct 77 ms 34004 KB Output is correct
35 Correct 92 ms 33776 KB Output is correct
36 Correct 98 ms 34408 KB Output is correct
37 Correct 68 ms 32844 KB Output is correct
38 Correct 77 ms 32472 KB Output is correct
39 Correct 43 ms 30548 KB Output is correct
40 Correct 48 ms 31200 KB Output is correct
41 Correct 80 ms 32220 KB Output is correct
42 Correct 80 ms 33392 KB Output is correct
43 Correct 75 ms 33412 KB Output is correct
44 Correct 78 ms 32908 KB Output is correct
45 Correct 77 ms 33488 KB Output is correct
46 Correct 78 ms 33452 KB Output is correct
47 Correct 65 ms 32844 KB Output is correct
48 Correct 65 ms 32968 KB Output is correct
49 Correct 57 ms 31360 KB Output is correct
50 Correct 71 ms 32624 KB Output is correct
51 Correct 76 ms 33436 KB Output is correct
52 Correct 84 ms 33488 KB Output is correct
53 Correct 74 ms 32804 KB Output is correct
54 Correct 89 ms 34316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 79 ms 33608 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 26452 KB Output is correct
2 Correct 15 ms 26440 KB Output is correct
3 Correct 14 ms 26504 KB Output is correct
4 Correct 15 ms 26452 KB Output is correct
5 Correct 15 ms 26452 KB Output is correct
6 Correct 14 ms 26416 KB Output is correct
7 Correct 15 ms 26404 KB Output is correct
8 Correct 15 ms 26552 KB Output is correct
9 Correct 14 ms 26456 KB Output is correct
10 Correct 15 ms 26452 KB Output is correct
11 Correct 15 ms 26452 KB Output is correct
12 Correct 15 ms 26452 KB Output is correct
13 Correct 18 ms 26516 KB Output is correct
14 Correct 15 ms 26452 KB Output is correct
15 Correct 14 ms 26452 KB Output is correct
16 Correct 15 ms 26452 KB Output is correct
17 Correct 15 ms 26376 KB Output is correct
18 Correct 14 ms 26492 KB Output is correct
19 Correct 17 ms 26452 KB Output is correct
20 Correct 15 ms 26580 KB Output is correct
21 Incorrect 15 ms 26452 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 26452 KB Output is correct
2 Correct 15 ms 26440 KB Output is correct
3 Correct 14 ms 26504 KB Output is correct
4 Correct 15 ms 26452 KB Output is correct
5 Correct 15 ms 26452 KB Output is correct
6 Correct 14 ms 26416 KB Output is correct
7 Correct 15 ms 26404 KB Output is correct
8 Correct 15 ms 26552 KB Output is correct
9 Correct 14 ms 26456 KB Output is correct
10 Correct 15 ms 26452 KB Output is correct
11 Correct 15 ms 26452 KB Output is correct
12 Correct 15 ms 26452 KB Output is correct
13 Correct 18 ms 26516 KB Output is correct
14 Correct 15 ms 26452 KB Output is correct
15 Correct 14 ms 26452 KB Output is correct
16 Correct 15 ms 26452 KB Output is correct
17 Correct 15 ms 26376 KB Output is correct
18 Correct 14 ms 26492 KB Output is correct
19 Correct 17 ms 26452 KB Output is correct
20 Correct 15 ms 26580 KB Output is correct
21 Incorrect 15 ms 26452 KB Output isn't correct
22 Halted 0 ms 0 KB -