답안 #794160

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
794160 2023-07-26T10:01:48 Z ymm 푸드 코트 (JOI21_foodcourt) C++17
68 / 100
1000 ms 225948 KB
#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= (l); --x)
typedef long long ll;
//typedef std::pair<int,int> pii;
typedef std::pair<ll,ll> pll;
using namespace std;

const int N = 250'010;
const ll inf = 1e18;

namespace beats {
	struct node {
		ll lzyadd, lzyaddmn;
		ll mn, mn2;
	} t[4*N];
	int sz;

	void up(int i, ll add, ll addmn) {
		t[i].lzyadd += add;
		t[i].mn += add;
		t[i].mn2 += add;
		t[i].lzyaddmn += addmn;
		t[i].mn += addmn;
	}
	void ppg(int i) {
		up(2*i+1, t[i].lzyadd, t[2*i+1].mn + t[i].lzyadd + t[i].lzyaddmn == t[i].mn? t[i].lzyaddmn: 0);
		up(2*i+2, t[i].lzyadd, t[2*i+2].mn + t[i].lzyadd + t[i].lzyaddmn == t[i].mn? t[i].lzyaddmn: 0);
		t[i].lzyadd = 0;
		t[i].lzyaddmn = 0;
	}
	void merge(int i) {
		node &v = t[i], &l = t[2*i+1], &r = t[2*i+2];
		v.mn = min(l.mn, r.mn);
		if (l.mn < r.mn)
			v.mn2 = min(l.mn2, r.mn);
		if (l.mn > r.mn)
			v.mn2 = min(l.mn, r.mn2);
		if (l.mn == r.mn)
			v.mn2 = min(l.mn2, r.mn2);
	}
	void init(int n) {
		sz = n;
		Loop (i,0,4*sz) {
			t[i].lzyadd = 0;
			t[i].lzyaddmn = 0;
			t[i].mn = 0;
			t[i].mn2 = inf;
		}
	}
	void add(int l, int r, ll x, int i, int b, int e) {
		if (l <= b && e <= r) {
			up(i, x, 0);
			return;
		}
		if (r <= b || e <= l)
			return;
		ppg(i);
		add(l, r, x, 2*i+1, b, (b+e)/2);
		add(l, r, x, 2*i+2, (b+e)/2, e);
		merge(i);
	}

	void mvup(int i, int b, int e) {
		if (t[i].mn >= 0)
			return;
		if (t[i].mn2 > 0) {
			up(i, 0, -t[i].mn);
			return;
		}
		ppg(i);
		mvup(2*i+1, b, (b+e)/2);
		mvup(2*i+2, (b+e)/2, e);
		merge(i);
	}

	void add(int l, int r, ll x) {
		add(l, r, x, 0, 0, sz);
		mvup(0, 0, sz);
	}

	ll get(int p, int i, int b, int e) {
		if (e-b == 1)
			return t[i].mn;
		ppg(i);
		if (p < (b+e)/2)
			return get(p, 2*i+1, b, (b+e)/2);
		else
			return get(p, 2*i+2, (b+e)/2, e);
	}
	ll get(int p) { return get(p, 0, 0, sz); }
}

namespace seg {
	struct node {
		ll cnt, cachev;
		int l, r;
		int cache;
	} nd[(1<<28)/sizeof(node)];
	int nxt = 1;
	vector<pair<int,int>> rts;
	int sz;

	void init(int n) {
		sz = n;
		rts = {{0,-1}};
	}
	int add(int t, int l, int r, ll x, int b, int e) {
		int ans = nxt++;
		if (l <= b && e <= r) {
			nd[ans].cnt = nd[t].cnt + x;
			nd[ans].l = nd[t].l;
			nd[ans].r = nd[t].r;
			return ans;
		}
		nd[ans] = nd[t];
		if (l < (b+e)/2)
			nd[ans].l = add(nd[t].l, l, r, x, b, (b+e)/2);
		if ((b+e)/2 < r)
			nd[ans].r = add(nd[t].r, l, r, x, (b+e)/2, e);
		return ans;
	}
	ll get(int t, int p, int b, int e) {
		if (!t)
			return 0;
		if (e-b == 1)
			return nd[t].cnt;
		if (nd[t].cache == p+1)
			return nd[t].cachev;
		ll ans;
		if (p < (b+e)/2)
			ans = nd[t].cnt + get(nd[t].l, p, b, (b+e)/2);
		else
			ans = nd[t].cnt + get(nd[t].r, p, (b+e)/2, e);
		nd[t].cachev = ans;
		return ans;
	}
	void add(int l, int r, ll x, int c) {
		int rt = rts.back().first;
		int rt2 = add(rt, l, r, x, 0, sz);
		rts.push_back({rt2, c});
	}
	ll get(int p) { return get(rts.back().first, p, 0, sz); }
	int bin(int p, ll i) {
		int l = 1, r = rts.size()-1;
		while (l < r) {
			int m = (l+r)/2;
			if (get(rts[m].first, p, 0, sz) > i)
				r = m;
			else
				l = m+1;
		}
		return rts[l].second;
	}
}

int main()
{
	cin.tie(0) -> sync_with_stdio(false);
	int n, m, q;
	cin >> n >> m >> q;
	seg::init(n);
	beats::init(n);
	Loop (i,0,q) {
		int t;
		cin >> t;
		if (t == 1) {
			int l, r, c, k;
			cin >> l >> r >> c >> k;
			--l;
			seg::add(l, r, k, c);
			beats::add(l, r, k);
		}
		if (t == 2) {
			int l, r, k;
			cin >> l >> r >> k;
			--l;
			beats::add(l, r, -k);
		}
		if (t == 3) {
			ll a, b;
			cin >> a >> b;
			--a; --b;
			ll cur = beats::get(a);
			ll tot = seg::get(a);
			b += tot - cur;
			if (b >= tot)
				cout << "0\n";
			else
				cout << seg::bin(a, b) << '\n';
		}
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 852 KB Output is correct
2 Correct 2 ms 1108 KB Output is correct
3 Correct 2 ms 1108 KB Output is correct
4 Correct 2 ms 1484 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 2 ms 1236 KB Output is correct
8 Correct 2 ms 1236 KB Output is correct
9 Correct 2 ms 1236 KB Output is correct
10 Correct 2 ms 1236 KB Output is correct
11 Correct 2 ms 1236 KB Output is correct
12 Correct 2 ms 1236 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 1108 KB Output is correct
16 Correct 2 ms 1236 KB Output is correct
17 Correct 2 ms 980 KB Output is correct
18 Correct 2 ms 1192 KB Output is correct
19 Correct 2 ms 1236 KB Output is correct
20 Correct 2 ms 1364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 852 KB Output is correct
2 Correct 2 ms 1108 KB Output is correct
3 Correct 2 ms 1108 KB Output is correct
4 Correct 2 ms 1484 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 2 ms 1236 KB Output is correct
8 Correct 2 ms 1236 KB Output is correct
9 Correct 2 ms 1236 KB Output is correct
10 Correct 2 ms 1236 KB Output is correct
11 Correct 2 ms 1236 KB Output is correct
12 Correct 2 ms 1236 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 1108 KB Output is correct
16 Correct 2 ms 1236 KB Output is correct
17 Correct 2 ms 980 KB Output is correct
18 Correct 2 ms 1192 KB Output is correct
19 Correct 2 ms 1236 KB Output is correct
20 Correct 2 ms 1364 KB Output is correct
21 Correct 2 ms 1108 KB Output is correct
22 Correct 2 ms 1108 KB Output is correct
23 Correct 3 ms 1240 KB Output is correct
24 Correct 3 ms 1364 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 2 ms 1236 KB Output is correct
28 Correct 2 ms 1236 KB Output is correct
29 Correct 2 ms 1236 KB Output is correct
30 Correct 2 ms 1236 KB Output is correct
31 Correct 2 ms 1236 KB Output is correct
32 Correct 3 ms 1236 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Correct 1 ms 596 KB Output is correct
35 Correct 2 ms 1108 KB Output is correct
36 Correct 2 ms 1236 KB Output is correct
37 Correct 1 ms 1108 KB Output is correct
38 Correct 2 ms 1364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 77 ms 22392 KB Output is correct
2 Correct 84 ms 29496 KB Output is correct
3 Correct 76 ms 23632 KB Output is correct
4 Correct 88 ms 23528 KB Output is correct
5 Correct 83 ms 31236 KB Output is correct
6 Correct 85 ms 31184 KB Output is correct
7 Correct 13 ms 1240 KB Output is correct
8 Correct 15 ms 1352 KB Output is correct
9 Correct 75 ms 24008 KB Output is correct
10 Correct 78 ms 24072 KB Output is correct
11 Correct 80 ms 24104 KB Output is correct
12 Correct 79 ms 24220 KB Output is correct
13 Correct 79 ms 26188 KB Output is correct
14 Correct 85 ms 31564 KB Output is correct
15 Correct 82 ms 40152 KB Output is correct
16 Correct 88 ms 43644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 637 ms 142940 KB Output is correct
2 Correct 500 ms 114892 KB Output is correct
3 Correct 707 ms 157788 KB Output is correct
4 Correct 701 ms 171520 KB Output is correct
5 Correct 639 ms 164780 KB Output is correct
6 Correct 959 ms 225948 KB Output is correct
7 Correct 62 ms 3912 KB Output is correct
8 Correct 76 ms 5280 KB Output is correct
9 Execution timed out 1101 ms 199624 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 852 KB Output is correct
2 Correct 2 ms 1108 KB Output is correct
3 Correct 2 ms 1108 KB Output is correct
4 Correct 2 ms 1484 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 2 ms 1236 KB Output is correct
8 Correct 2 ms 1236 KB Output is correct
9 Correct 2 ms 1236 KB Output is correct
10 Correct 2 ms 1236 KB Output is correct
11 Correct 2 ms 1236 KB Output is correct
12 Correct 2 ms 1236 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 1108 KB Output is correct
16 Correct 2 ms 1236 KB Output is correct
17 Correct 2 ms 980 KB Output is correct
18 Correct 2 ms 1192 KB Output is correct
19 Correct 2 ms 1236 KB Output is correct
20 Correct 2 ms 1364 KB Output is correct
21 Correct 77 ms 22392 KB Output is correct
22 Correct 84 ms 29496 KB Output is correct
23 Correct 76 ms 23632 KB Output is correct
24 Correct 88 ms 23528 KB Output is correct
25 Correct 83 ms 31236 KB Output is correct
26 Correct 85 ms 31184 KB Output is correct
27 Correct 13 ms 1240 KB Output is correct
28 Correct 15 ms 1352 KB Output is correct
29 Correct 75 ms 24008 KB Output is correct
30 Correct 78 ms 24072 KB Output is correct
31 Correct 80 ms 24104 KB Output is correct
32 Correct 79 ms 24220 KB Output is correct
33 Correct 79 ms 26188 KB Output is correct
34 Correct 85 ms 31564 KB Output is correct
35 Correct 82 ms 40152 KB Output is correct
36 Correct 88 ms 43644 KB Output is correct
37 Correct 108 ms 33068 KB Output is correct
38 Correct 109 ms 43068 KB Output is correct
39 Correct 12 ms 1264 KB Output is correct
40 Correct 15 ms 1692 KB Output is correct
41 Correct 153 ms 42116 KB Output is correct
42 Correct 165 ms 42140 KB Output is correct
43 Correct 114 ms 41848 KB Output is correct
44 Correct 139 ms 41904 KB Output is correct
45 Correct 152 ms 42048 KB Output is correct
46 Correct 141 ms 42140 KB Output is correct
47 Correct 24 ms 9552 KB Output is correct
48 Correct 76 ms 42672 KB Output is correct
49 Correct 86 ms 29880 KB Output is correct
50 Correct 113 ms 37732 KB Output is correct
51 Correct 133 ms 43356 KB Output is correct
52 Correct 126 ms 43260 KB Output is correct
53 Correct 68 ms 34940 KB Output is correct
54 Correct 86 ms 43620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 174 ms 46616 KB Output is correct
2 Correct 187 ms 49124 KB Output is correct
3 Correct 211 ms 51808 KB Output is correct
4 Correct 120 ms 39520 KB Output is correct
5 Correct 168 ms 46540 KB Output is correct
6 Correct 218 ms 53180 KB Output is correct
7 Correct 18 ms 1752 KB Output is correct
8 Correct 20 ms 2028 KB Output is correct
9 Correct 33 ms 9944 KB Output is correct
10 Correct 69 ms 42636 KB Output is correct
11 Correct 116 ms 59984 KB Output is correct
12 Correct 135 ms 59716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 852 KB Output is correct
2 Correct 2 ms 1108 KB Output is correct
3 Correct 2 ms 1108 KB Output is correct
4 Correct 2 ms 1484 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 2 ms 1236 KB Output is correct
8 Correct 2 ms 1236 KB Output is correct
9 Correct 2 ms 1236 KB Output is correct
10 Correct 2 ms 1236 KB Output is correct
11 Correct 2 ms 1236 KB Output is correct
12 Correct 2 ms 1236 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 1108 KB Output is correct
16 Correct 2 ms 1236 KB Output is correct
17 Correct 2 ms 980 KB Output is correct
18 Correct 2 ms 1192 KB Output is correct
19 Correct 2 ms 1236 KB Output is correct
20 Correct 2 ms 1364 KB Output is correct
21 Correct 2 ms 1108 KB Output is correct
22 Correct 2 ms 1108 KB Output is correct
23 Correct 3 ms 1240 KB Output is correct
24 Correct 3 ms 1364 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 2 ms 1236 KB Output is correct
28 Correct 2 ms 1236 KB Output is correct
29 Correct 2 ms 1236 KB Output is correct
30 Correct 2 ms 1236 KB Output is correct
31 Correct 2 ms 1236 KB Output is correct
32 Correct 3 ms 1236 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Correct 1 ms 596 KB Output is correct
35 Correct 2 ms 1108 KB Output is correct
36 Correct 2 ms 1236 KB Output is correct
37 Correct 1 ms 1108 KB Output is correct
38 Correct 2 ms 1364 KB Output is correct
39 Correct 77 ms 22392 KB Output is correct
40 Correct 84 ms 29496 KB Output is correct
41 Correct 76 ms 23632 KB Output is correct
42 Correct 88 ms 23528 KB Output is correct
43 Correct 83 ms 31236 KB Output is correct
44 Correct 85 ms 31184 KB Output is correct
45 Correct 13 ms 1240 KB Output is correct
46 Correct 15 ms 1352 KB Output is correct
47 Correct 75 ms 24008 KB Output is correct
48 Correct 78 ms 24072 KB Output is correct
49 Correct 80 ms 24104 KB Output is correct
50 Correct 79 ms 24220 KB Output is correct
51 Correct 79 ms 26188 KB Output is correct
52 Correct 85 ms 31564 KB Output is correct
53 Correct 82 ms 40152 KB Output is correct
54 Correct 88 ms 43644 KB Output is correct
55 Correct 108 ms 33068 KB Output is correct
56 Correct 109 ms 43068 KB Output is correct
57 Correct 12 ms 1264 KB Output is correct
58 Correct 15 ms 1692 KB Output is correct
59 Correct 153 ms 42116 KB Output is correct
60 Correct 165 ms 42140 KB Output is correct
61 Correct 114 ms 41848 KB Output is correct
62 Correct 139 ms 41904 KB Output is correct
63 Correct 152 ms 42048 KB Output is correct
64 Correct 141 ms 42140 KB Output is correct
65 Correct 24 ms 9552 KB Output is correct
66 Correct 76 ms 42672 KB Output is correct
67 Correct 86 ms 29880 KB Output is correct
68 Correct 113 ms 37732 KB Output is correct
69 Correct 133 ms 43356 KB Output is correct
70 Correct 126 ms 43260 KB Output is correct
71 Correct 68 ms 34940 KB Output is correct
72 Correct 86 ms 43620 KB Output is correct
73 Correct 174 ms 46616 KB Output is correct
74 Correct 187 ms 49124 KB Output is correct
75 Correct 211 ms 51808 KB Output is correct
76 Correct 120 ms 39520 KB Output is correct
77 Correct 168 ms 46540 KB Output is correct
78 Correct 218 ms 53180 KB Output is correct
79 Correct 18 ms 1752 KB Output is correct
80 Correct 20 ms 2028 KB Output is correct
81 Correct 33 ms 9944 KB Output is correct
82 Correct 69 ms 42636 KB Output is correct
83 Correct 116 ms 59984 KB Output is correct
84 Correct 135 ms 59716 KB Output is correct
85 Correct 115 ms 32428 KB Output is correct
86 Correct 115 ms 37464 KB Output is correct
87 Correct 120 ms 46864 KB Output is correct
88 Correct 142 ms 53080 KB Output is correct
89 Correct 90 ms 28844 KB Output is correct
90 Correct 140 ms 42208 KB Output is correct
91 Correct 88 ms 32492 KB Output is correct
92 Correct 95 ms 31160 KB Output is correct
93 Correct 112 ms 41936 KB Output is correct
94 Correct 145 ms 42108 KB Output is correct
95 Correct 114 ms 40392 KB Output is correct
96 Correct 115 ms 42320 KB Output is correct
97 Correct 149 ms 42180 KB Output is correct
98 Correct 95 ms 34060 KB Output is correct
99 Correct 28 ms 9488 KB Output is correct
100 Correct 63 ms 35928 KB Output is correct
101 Correct 75 ms 42396 KB Output is correct
102 Correct 104 ms 41752 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 852 KB Output is correct
2 Correct 2 ms 1108 KB Output is correct
3 Correct 2 ms 1108 KB Output is correct
4 Correct 2 ms 1484 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 2 ms 1236 KB Output is correct
8 Correct 2 ms 1236 KB Output is correct
9 Correct 2 ms 1236 KB Output is correct
10 Correct 2 ms 1236 KB Output is correct
11 Correct 2 ms 1236 KB Output is correct
12 Correct 2 ms 1236 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 1108 KB Output is correct
16 Correct 2 ms 1236 KB Output is correct
17 Correct 2 ms 980 KB Output is correct
18 Correct 2 ms 1192 KB Output is correct
19 Correct 2 ms 1236 KB Output is correct
20 Correct 2 ms 1364 KB Output is correct
21 Correct 2 ms 1108 KB Output is correct
22 Correct 2 ms 1108 KB Output is correct
23 Correct 3 ms 1240 KB Output is correct
24 Correct 3 ms 1364 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 2 ms 1236 KB Output is correct
28 Correct 2 ms 1236 KB Output is correct
29 Correct 2 ms 1236 KB Output is correct
30 Correct 2 ms 1236 KB Output is correct
31 Correct 2 ms 1236 KB Output is correct
32 Correct 3 ms 1236 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Correct 1 ms 596 KB Output is correct
35 Correct 2 ms 1108 KB Output is correct
36 Correct 2 ms 1236 KB Output is correct
37 Correct 1 ms 1108 KB Output is correct
38 Correct 2 ms 1364 KB Output is correct
39 Correct 77 ms 22392 KB Output is correct
40 Correct 84 ms 29496 KB Output is correct
41 Correct 76 ms 23632 KB Output is correct
42 Correct 88 ms 23528 KB Output is correct
43 Correct 83 ms 31236 KB Output is correct
44 Correct 85 ms 31184 KB Output is correct
45 Correct 13 ms 1240 KB Output is correct
46 Correct 15 ms 1352 KB Output is correct
47 Correct 75 ms 24008 KB Output is correct
48 Correct 78 ms 24072 KB Output is correct
49 Correct 80 ms 24104 KB Output is correct
50 Correct 79 ms 24220 KB Output is correct
51 Correct 79 ms 26188 KB Output is correct
52 Correct 85 ms 31564 KB Output is correct
53 Correct 82 ms 40152 KB Output is correct
54 Correct 88 ms 43644 KB Output is correct
55 Correct 637 ms 142940 KB Output is correct
56 Correct 500 ms 114892 KB Output is correct
57 Correct 707 ms 157788 KB Output is correct
58 Correct 701 ms 171520 KB Output is correct
59 Correct 639 ms 164780 KB Output is correct
60 Correct 959 ms 225948 KB Output is correct
61 Correct 62 ms 3912 KB Output is correct
62 Correct 76 ms 5280 KB Output is correct
63 Execution timed out 1101 ms 199624 KB Time limit exceeded
64 Halted 0 ms 0 KB -