Submission #802404

# Submission time Handle Problem Language Result Execution time Memory
802404 2023-08-02T12:09:03 Z Divane Food Court (JOI21_foodcourt) C++17
24 / 100
340 ms 51848 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, -INF);
	slz[v] = 0;
}

void mx (int l, int r, int v = 1, int tl = 0, int tr = N - 1) {
	if (tl > r || l > tr) 
		return;
	if (l <= tl && tr <= r) {
		lz[v].S = max(lz[v].S, 0LL);
	} else {
		shift(v);
		int mid = (tl + tr) >> 1;
		mx (l, r, v << 1, tl, mid);
		mx (l, r, v << 1 | 1, mid + 1, tr);
	}
}

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, -INF);
	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]);
			mx (l[i], r[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';
	}
}
# Verdict Execution time Memory Grader output
1 Correct 15 ms 26452 KB Output is correct
2 Correct 15 ms 26540 KB Output is correct
3 Correct 14 ms 26452 KB Output is correct
4 Correct 15 ms 26460 KB Output is correct
5 Correct 14 ms 26504 KB Output is correct
6 Correct 14 ms 26440 KB Output is correct
7 Correct 15 ms 26508 KB Output is correct
8 Correct 17 ms 26664 KB Output is correct
9 Correct 15 ms 26452 KB Output is correct
10 Correct 15 ms 26452 KB Output is correct
11 Correct 15 ms 26428 KB Output is correct
12 Correct 15 ms 26440 KB Output is correct
13 Correct 15 ms 26508 KB Output is correct
14 Correct 17 ms 26544 KB Output is correct
15 Correct 14 ms 26452 KB Output is correct
16 Correct 16 ms 26436 KB Output is correct
17 Correct 15 ms 26500 KB Output is correct
18 Correct 15 ms 26452 KB Output is correct
19 Correct 15 ms 26452 KB Output is correct
20 Correct 15 ms 26580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 26452 KB Output is correct
2 Correct 15 ms 26540 KB Output is correct
3 Correct 14 ms 26452 KB Output is correct
4 Correct 15 ms 26460 KB Output is correct
5 Correct 14 ms 26504 KB Output is correct
6 Correct 14 ms 26440 KB Output is correct
7 Correct 15 ms 26508 KB Output is correct
8 Correct 17 ms 26664 KB Output is correct
9 Correct 15 ms 26452 KB Output is correct
10 Correct 15 ms 26452 KB Output is correct
11 Correct 15 ms 26428 KB Output is correct
12 Correct 15 ms 26440 KB Output is correct
13 Correct 15 ms 26508 KB Output is correct
14 Correct 17 ms 26544 KB Output is correct
15 Correct 14 ms 26452 KB Output is correct
16 Correct 16 ms 26436 KB Output is correct
17 Correct 15 ms 26500 KB Output is correct
18 Correct 15 ms 26452 KB Output is correct
19 Correct 15 ms 26452 KB Output is correct
20 Correct 15 ms 26580 KB Output is correct
21 Incorrect 15 ms 26504 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 82 ms 33608 KB Output is correct
2 Correct 90 ms 33872 KB Output is correct
3 Correct 78 ms 33580 KB Output is correct
4 Correct 77 ms 33500 KB Output is correct
5 Correct 91 ms 33884 KB Output is correct
6 Correct 108 ms 33888 KB Output is correct
7 Correct 52 ms 31316 KB Output is correct
8 Correct 52 ms 31336 KB Output is correct
9 Correct 79 ms 32712 KB Output is correct
10 Correct 79 ms 33568 KB Output is correct
11 Correct 80 ms 33196 KB Output is correct
12 Correct 96 ms 33592 KB Output is correct
13 Correct 70 ms 33004 KB Output is correct
14 Correct 83 ms 34104 KB Output is correct
15 Correct 87 ms 33840 KB Output is correct
16 Correct 88 ms 34392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 340 ms 51848 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 26452 KB Output is correct
2 Correct 15 ms 26540 KB Output is correct
3 Correct 14 ms 26452 KB Output is correct
4 Correct 15 ms 26460 KB Output is correct
5 Correct 14 ms 26504 KB Output is correct
6 Correct 14 ms 26440 KB Output is correct
7 Correct 15 ms 26508 KB Output is correct
8 Correct 17 ms 26664 KB Output is correct
9 Correct 15 ms 26452 KB Output is correct
10 Correct 15 ms 26452 KB Output is correct
11 Correct 15 ms 26428 KB Output is correct
12 Correct 15 ms 26440 KB Output is correct
13 Correct 15 ms 26508 KB Output is correct
14 Correct 17 ms 26544 KB Output is correct
15 Correct 14 ms 26452 KB Output is correct
16 Correct 16 ms 26436 KB Output is correct
17 Correct 15 ms 26500 KB Output is correct
18 Correct 15 ms 26452 KB Output is correct
19 Correct 15 ms 26452 KB Output is correct
20 Correct 15 ms 26580 KB Output is correct
21 Correct 82 ms 33608 KB Output is correct
22 Correct 90 ms 33872 KB Output is correct
23 Correct 78 ms 33580 KB Output is correct
24 Correct 77 ms 33500 KB Output is correct
25 Correct 91 ms 33884 KB Output is correct
26 Correct 108 ms 33888 KB Output is correct
27 Correct 52 ms 31316 KB Output is correct
28 Correct 52 ms 31336 KB Output is correct
29 Correct 79 ms 32712 KB Output is correct
30 Correct 79 ms 33568 KB Output is correct
31 Correct 80 ms 33196 KB Output is correct
32 Correct 96 ms 33592 KB Output is correct
33 Correct 70 ms 33004 KB Output is correct
34 Correct 83 ms 34104 KB Output is correct
35 Correct 87 ms 33840 KB Output is correct
36 Correct 88 ms 34392 KB Output is correct
37 Correct 76 ms 32776 KB Output is correct
38 Correct 82 ms 32272 KB Output is correct
39 Correct 51 ms 30540 KB Output is correct
40 Correct 55 ms 31212 KB Output is correct
41 Correct 87 ms 32212 KB Output is correct
42 Correct 86 ms 33472 KB Output is correct
43 Correct 84 ms 33480 KB Output is correct
44 Correct 86 ms 32872 KB Output is correct
45 Correct 100 ms 33524 KB Output is correct
46 Correct 87 ms 33416 KB Output is correct
47 Correct 69 ms 32876 KB Output is correct
48 Correct 73 ms 32984 KB Output is correct
49 Correct 63 ms 31308 KB Output is correct
50 Correct 75 ms 32584 KB Output is correct
51 Correct 91 ms 33392 KB Output is correct
52 Correct 87 ms 33412 KB Output is correct
53 Correct 73 ms 32816 KB Output is correct
54 Correct 92 ms 34404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 77 ms 33532 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 26452 KB Output is correct
2 Correct 15 ms 26540 KB Output is correct
3 Correct 14 ms 26452 KB Output is correct
4 Correct 15 ms 26460 KB Output is correct
5 Correct 14 ms 26504 KB Output is correct
6 Correct 14 ms 26440 KB Output is correct
7 Correct 15 ms 26508 KB Output is correct
8 Correct 17 ms 26664 KB Output is correct
9 Correct 15 ms 26452 KB Output is correct
10 Correct 15 ms 26452 KB Output is correct
11 Correct 15 ms 26428 KB Output is correct
12 Correct 15 ms 26440 KB Output is correct
13 Correct 15 ms 26508 KB Output is correct
14 Correct 17 ms 26544 KB Output is correct
15 Correct 14 ms 26452 KB Output is correct
16 Correct 16 ms 26436 KB Output is correct
17 Correct 15 ms 26500 KB Output is correct
18 Correct 15 ms 26452 KB Output is correct
19 Correct 15 ms 26452 KB Output is correct
20 Correct 15 ms 26580 KB Output is correct
21 Incorrect 15 ms 26504 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 26452 KB Output is correct
2 Correct 15 ms 26540 KB Output is correct
3 Correct 14 ms 26452 KB Output is correct
4 Correct 15 ms 26460 KB Output is correct
5 Correct 14 ms 26504 KB Output is correct
6 Correct 14 ms 26440 KB Output is correct
7 Correct 15 ms 26508 KB Output is correct
8 Correct 17 ms 26664 KB Output is correct
9 Correct 15 ms 26452 KB Output is correct
10 Correct 15 ms 26452 KB Output is correct
11 Correct 15 ms 26428 KB Output is correct
12 Correct 15 ms 26440 KB Output is correct
13 Correct 15 ms 26508 KB Output is correct
14 Correct 17 ms 26544 KB Output is correct
15 Correct 14 ms 26452 KB Output is correct
16 Correct 16 ms 26436 KB Output is correct
17 Correct 15 ms 26500 KB Output is correct
18 Correct 15 ms 26452 KB Output is correct
19 Correct 15 ms 26452 KB Output is correct
20 Correct 15 ms 26580 KB Output is correct
21 Incorrect 15 ms 26504 KB Output isn't correct
22 Halted 0 ms 0 KB -