답안 #416277

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
416277 2021-06-02T09:20:24 Z amoo_safar 푸드 코트 (JOI21_foodcourt) C++17
68 / 100
707 ms 19528 KB
// vaziat meshki-ghermeze !
#include <bits/stdc++.h>

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x << '\n'

using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;

const ll Mod = 1000000007LL;
const int N = 65e3 + 10;
const ll Inf = 2242545357980376863LL;
const ll Log = 30;

typedef pll pii;

pii seg[N << 2]; // sum ans
pii nl = {0, 0};
pii Merge(pii &A, pii &B){
	return {A.F + B.F, min(A.S, A.F + B.S)};
}
void Apply(int id, pii &X){
	seg[id].S = min(seg[id].S, seg[id].F + X.S);
	seg[id].F += X.F;
}
void Shift(int id){
	Apply(id << 1, seg[id]);
	Apply(id << 1 | 1, seg[id]);
	seg[id] = nl;
}
void Add(int id, int l, int r, pii X, int L, int R){
	if(r <= L || R <= l) return ;
	if(l <= L && R <= r){
		Apply(id, X);
		return ;
	}
	int mid = (L + R) >> 1;
	Shift(id);
	Add(id << 1, l, r, X, L, mid);
	Add(id<<1|1, l, r, X, mid, R);
}
pll Get(int id, int idx, int L, int R){
	if(L + 1 == R) return seg[id];
	int mid = (L + R) >> 1;
	Shift(id);
	if(idx < mid)
		return Get(id << 1, idx, L, mid);
	return Get(id << 1 | 1, idx, mid, R);
}

ll fen[N];
void Add(int idx, ll x){
	for(; idx < N; idx += idx & (-idx))
		fen[idx] += x;
}
ll Get(int idx){
	ll res = 0;
	for(; idx; idx -= idx & (-idx))
		res += fen[idx];
	return res;
}


int t[N];
ll a[N], b[N], c[N], d[N], ps[N];
int lf[N], rt[N];
vector<int> V[N];


int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, m, q;
	cin >> n >> m >> q;
	for(int i = 1; i <= q; i++){
		cin >> t[i];
		if(t[i] == 1)
			cin >> a[i] >> b[i] >> c[i] >> d[i];
		if(t[i] == 2){
			cin >> a[i] >> b[i] >> c[i];
			Add(a[i], c[i]);
			Add(b[i] + 1, -c[i]);
		}
		if(t[i] == 3){
			cin >> a[i] >> b[i];
			lf[i] = m == 1 ? i - 1 : 0;
			rt[i] = i + 1;
			ps[i] = Get(a[i]);
		}
	}
	for(int _ = 0; _ < 20; _++){
		// debug(_);
		for(int i = 1; i <= q; i++) V[i].clear();
		memset(fen, 0, sizeof fen);
		fill(seg, seg + (N << 2), nl);

		int mid;
		int fl = 0;
		for(int i = 1; i <= q; i++){
			if(t[i] == 3 && lf[i] + 1 < rt[i]){
				// if(_>18) debug(_);
				mid = (lf[i] + rt[i]) >> 1;
				// debug(mid);
				V[mid].pb(i);
				fl = 1;
			}
		}
		if(!fl) break;

		for(int i = 1; i <= q; i++){
			// debug(i);
			if(t[i] == 1){
				Add(1, a[i], b[i] + 1, {d[i], 0}, 1, n + 1);
			} else if(t[i] == 2){
				Add(1, a[i], b[i] + 1, {-c[i], -c[i]}, 1, n + 1);
				
				Add(a[i], c[i]);
				Add(b[i] + 1, -c[i]);
			}
			for(int q_id : V[i]){
				pll res = Get(1, a[q_id], 1, n + 1);
				ll nw = res.F - res.S;
				ll dec = (ps[q_id] - Get(a[q_id]));
				nw -= dec; 
				if(nw >= b[q_id])
					rt[q_id] = i;
				else
					lf[q_id] = i;
			}
		}
	}
	for(int i = 1; i <= q; i++){
		if(t[i] != 3) continue;
		if(rt[i] == i + 1) cout << "0\n";
		else
			cout << (m == 1 ? 1 : c[rt[i]]) << '\n';
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 6476 KB Output is correct
2 Correct 16 ms 6604 KB Output is correct
3 Correct 13 ms 6532 KB Output is correct
4 Correct 21 ms 6620 KB Output is correct
5 Correct 9 ms 6576 KB Output is correct
6 Correct 10 ms 6580 KB Output is correct
7 Correct 16 ms 6604 KB Output is correct
8 Correct 17 ms 6612 KB Output is correct
9 Correct 20 ms 6616 KB Output is correct
10 Correct 20 ms 6580 KB Output is correct
11 Correct 19 ms 6616 KB Output is correct
12 Correct 16 ms 6612 KB Output is correct
13 Correct 10 ms 6476 KB Output is correct
14 Correct 10 ms 6604 KB Output is correct
15 Correct 13 ms 6552 KB Output is correct
16 Correct 15 ms 6600 KB Output is correct
17 Correct 15 ms 6476 KB Output is correct
18 Correct 17 ms 6604 KB Output is correct
19 Correct 14 ms 6476 KB Output is correct
20 Correct 15 ms 6600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 6476 KB Output is correct
2 Correct 16 ms 6604 KB Output is correct
3 Correct 13 ms 6532 KB Output is correct
4 Correct 21 ms 6620 KB Output is correct
5 Correct 9 ms 6576 KB Output is correct
6 Correct 10 ms 6580 KB Output is correct
7 Correct 16 ms 6604 KB Output is correct
8 Correct 17 ms 6612 KB Output is correct
9 Correct 20 ms 6616 KB Output is correct
10 Correct 20 ms 6580 KB Output is correct
11 Correct 19 ms 6616 KB Output is correct
12 Correct 16 ms 6612 KB Output is correct
13 Correct 10 ms 6476 KB Output is correct
14 Correct 10 ms 6604 KB Output is correct
15 Correct 13 ms 6552 KB Output is correct
16 Correct 15 ms 6600 KB Output is correct
17 Correct 15 ms 6476 KB Output is correct
18 Correct 17 ms 6604 KB Output is correct
19 Correct 14 ms 6476 KB Output is correct
20 Correct 15 ms 6600 KB Output is correct
21 Correct 16 ms 6600 KB Output is correct
22 Correct 16 ms 6592 KB Output is correct
23 Correct 16 ms 6568 KB Output is correct
24 Correct 20 ms 6604 KB Output is correct
25 Correct 10 ms 6476 KB Output is correct
26 Correct 10 ms 6476 KB Output is correct
27 Correct 17 ms 6604 KB Output is correct
28 Correct 18 ms 6608 KB Output is correct
29 Correct 16 ms 6576 KB Output is correct
30 Correct 17 ms 6596 KB Output is correct
31 Correct 16 ms 6604 KB Output is correct
32 Correct 16 ms 6616 KB Output is correct
33 Correct 10 ms 6476 KB Output is correct
34 Correct 13 ms 6604 KB Output is correct
35 Correct 19 ms 6548 KB Output is correct
36 Correct 15 ms 6612 KB Output is correct
37 Correct 11 ms 6524 KB Output is correct
38 Correct 14 ms 6584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 598 ms 11752 KB Output is correct
2 Correct 620 ms 11704 KB Output is correct
3 Correct 631 ms 11736 KB Output is correct
4 Correct 593 ms 11824 KB Output is correct
5 Correct 587 ms 11716 KB Output is correct
6 Correct 536 ms 11808 KB Output is correct
7 Correct 97 ms 11460 KB Output is correct
8 Correct 107 ms 11548 KB Output is correct
9 Correct 533 ms 11580 KB Output is correct
10 Correct 601 ms 11800 KB Output is correct
11 Correct 550 ms 11668 KB Output is correct
12 Correct 555 ms 11776 KB Output is correct
13 Correct 402 ms 11280 KB Output is correct
14 Correct 480 ms 11788 KB Output is correct
15 Correct 435 ms 11528 KB Output is correct
16 Correct 453 ms 11632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 119 ms 19528 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 6476 KB Output is correct
2 Correct 16 ms 6604 KB Output is correct
3 Correct 13 ms 6532 KB Output is correct
4 Correct 21 ms 6620 KB Output is correct
5 Correct 9 ms 6576 KB Output is correct
6 Correct 10 ms 6580 KB Output is correct
7 Correct 16 ms 6604 KB Output is correct
8 Correct 17 ms 6612 KB Output is correct
9 Correct 20 ms 6616 KB Output is correct
10 Correct 20 ms 6580 KB Output is correct
11 Correct 19 ms 6616 KB Output is correct
12 Correct 16 ms 6612 KB Output is correct
13 Correct 10 ms 6476 KB Output is correct
14 Correct 10 ms 6604 KB Output is correct
15 Correct 13 ms 6552 KB Output is correct
16 Correct 15 ms 6600 KB Output is correct
17 Correct 15 ms 6476 KB Output is correct
18 Correct 17 ms 6604 KB Output is correct
19 Correct 14 ms 6476 KB Output is correct
20 Correct 15 ms 6600 KB Output is correct
21 Correct 598 ms 11752 KB Output is correct
22 Correct 620 ms 11704 KB Output is correct
23 Correct 631 ms 11736 KB Output is correct
24 Correct 593 ms 11824 KB Output is correct
25 Correct 587 ms 11716 KB Output is correct
26 Correct 536 ms 11808 KB Output is correct
27 Correct 97 ms 11460 KB Output is correct
28 Correct 107 ms 11548 KB Output is correct
29 Correct 533 ms 11580 KB Output is correct
30 Correct 601 ms 11800 KB Output is correct
31 Correct 550 ms 11668 KB Output is correct
32 Correct 555 ms 11776 KB Output is correct
33 Correct 402 ms 11280 KB Output is correct
34 Correct 480 ms 11788 KB Output is correct
35 Correct 435 ms 11528 KB Output is correct
36 Correct 453 ms 11632 KB Output is correct
37 Correct 613 ms 11344 KB Output is correct
38 Correct 565 ms 10764 KB Output is correct
39 Correct 93 ms 10820 KB Output is correct
40 Correct 117 ms 11404 KB Output is correct
41 Correct 649 ms 11372 KB Output is correct
42 Correct 661 ms 11716 KB Output is correct
43 Correct 628 ms 11752 KB Output is correct
44 Correct 636 ms 11564 KB Output is correct
45 Correct 665 ms 11732 KB Output is correct
46 Correct 642 ms 11844 KB Output is correct
47 Correct 191 ms 11844 KB Output is correct
48 Correct 543 ms 11900 KB Output is correct
49 Correct 436 ms 10148 KB Output is correct
50 Correct 539 ms 10984 KB Output is correct
51 Correct 650 ms 11852 KB Output is correct
52 Correct 644 ms 11852 KB Output is correct
53 Correct 334 ms 10496 KB Output is correct
54 Correct 435 ms 11660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 507 ms 11332 KB Output is correct
2 Correct 558 ms 11936 KB Output is correct
3 Correct 575 ms 12136 KB Output is correct
4 Correct 397 ms 10308 KB Output is correct
5 Correct 489 ms 11224 KB Output is correct
6 Correct 560 ms 11944 KB Output is correct
7 Correct 100 ms 11404 KB Output is correct
8 Correct 108 ms 11176 KB Output is correct
9 Correct 266 ms 11956 KB Output is correct
10 Correct 353 ms 10348 KB Output is correct
11 Correct 512 ms 11988 KB Output is correct
12 Correct 544 ms 12028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 6476 KB Output is correct
2 Correct 16 ms 6604 KB Output is correct
3 Correct 13 ms 6532 KB Output is correct
4 Correct 21 ms 6620 KB Output is correct
5 Correct 9 ms 6576 KB Output is correct
6 Correct 10 ms 6580 KB Output is correct
7 Correct 16 ms 6604 KB Output is correct
8 Correct 17 ms 6612 KB Output is correct
9 Correct 20 ms 6616 KB Output is correct
10 Correct 20 ms 6580 KB Output is correct
11 Correct 19 ms 6616 KB Output is correct
12 Correct 16 ms 6612 KB Output is correct
13 Correct 10 ms 6476 KB Output is correct
14 Correct 10 ms 6604 KB Output is correct
15 Correct 13 ms 6552 KB Output is correct
16 Correct 15 ms 6600 KB Output is correct
17 Correct 15 ms 6476 KB Output is correct
18 Correct 17 ms 6604 KB Output is correct
19 Correct 14 ms 6476 KB Output is correct
20 Correct 15 ms 6600 KB Output is correct
21 Correct 16 ms 6600 KB Output is correct
22 Correct 16 ms 6592 KB Output is correct
23 Correct 16 ms 6568 KB Output is correct
24 Correct 20 ms 6604 KB Output is correct
25 Correct 10 ms 6476 KB Output is correct
26 Correct 10 ms 6476 KB Output is correct
27 Correct 17 ms 6604 KB Output is correct
28 Correct 18 ms 6608 KB Output is correct
29 Correct 16 ms 6576 KB Output is correct
30 Correct 17 ms 6596 KB Output is correct
31 Correct 16 ms 6604 KB Output is correct
32 Correct 16 ms 6616 KB Output is correct
33 Correct 10 ms 6476 KB Output is correct
34 Correct 13 ms 6604 KB Output is correct
35 Correct 19 ms 6548 KB Output is correct
36 Correct 15 ms 6612 KB Output is correct
37 Correct 11 ms 6524 KB Output is correct
38 Correct 14 ms 6584 KB Output is correct
39 Correct 598 ms 11752 KB Output is correct
40 Correct 620 ms 11704 KB Output is correct
41 Correct 631 ms 11736 KB Output is correct
42 Correct 593 ms 11824 KB Output is correct
43 Correct 587 ms 11716 KB Output is correct
44 Correct 536 ms 11808 KB Output is correct
45 Correct 97 ms 11460 KB Output is correct
46 Correct 107 ms 11548 KB Output is correct
47 Correct 533 ms 11580 KB Output is correct
48 Correct 601 ms 11800 KB Output is correct
49 Correct 550 ms 11668 KB Output is correct
50 Correct 555 ms 11776 KB Output is correct
51 Correct 402 ms 11280 KB Output is correct
52 Correct 480 ms 11788 KB Output is correct
53 Correct 435 ms 11528 KB Output is correct
54 Correct 453 ms 11632 KB Output is correct
55 Correct 613 ms 11344 KB Output is correct
56 Correct 565 ms 10764 KB Output is correct
57 Correct 93 ms 10820 KB Output is correct
58 Correct 117 ms 11404 KB Output is correct
59 Correct 649 ms 11372 KB Output is correct
60 Correct 661 ms 11716 KB Output is correct
61 Correct 628 ms 11752 KB Output is correct
62 Correct 636 ms 11564 KB Output is correct
63 Correct 665 ms 11732 KB Output is correct
64 Correct 642 ms 11844 KB Output is correct
65 Correct 191 ms 11844 KB Output is correct
66 Correct 543 ms 11900 KB Output is correct
67 Correct 436 ms 10148 KB Output is correct
68 Correct 539 ms 10984 KB Output is correct
69 Correct 650 ms 11852 KB Output is correct
70 Correct 644 ms 11852 KB Output is correct
71 Correct 334 ms 10496 KB Output is correct
72 Correct 435 ms 11660 KB Output is correct
73 Correct 507 ms 11332 KB Output is correct
74 Correct 558 ms 11936 KB Output is correct
75 Correct 575 ms 12136 KB Output is correct
76 Correct 397 ms 10308 KB Output is correct
77 Correct 489 ms 11224 KB Output is correct
78 Correct 560 ms 11944 KB Output is correct
79 Correct 100 ms 11404 KB Output is correct
80 Correct 108 ms 11176 KB Output is correct
81 Correct 266 ms 11956 KB Output is correct
82 Correct 353 ms 10348 KB Output is correct
83 Correct 512 ms 11988 KB Output is correct
84 Correct 544 ms 12028 KB Output is correct
85 Correct 545 ms 11360 KB Output is correct
86 Correct 612 ms 11928 KB Output is correct
87 Correct 586 ms 11076 KB Output is correct
88 Correct 665 ms 11788 KB Output is correct
89 Correct 426 ms 9796 KB Output is correct
90 Correct 707 ms 11740 KB Output is correct
91 Correct 526 ms 10960 KB Output is correct
92 Correct 484 ms 10636 KB Output is correct
93 Correct 677 ms 11780 KB Output is correct
94 Correct 680 ms 11604 KB Output is correct
95 Correct 652 ms 11792 KB Output is correct
96 Correct 659 ms 11764 KB Output is correct
97 Correct 650 ms 11844 KB Output is correct
98 Correct 538 ms 11068 KB Output is correct
99 Correct 206 ms 11960 KB Output is correct
100 Correct 464 ms 11104 KB Output is correct
101 Correct 555 ms 11936 KB Output is correct
102 Correct 512 ms 11200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 6476 KB Output is correct
2 Correct 16 ms 6604 KB Output is correct
3 Correct 13 ms 6532 KB Output is correct
4 Correct 21 ms 6620 KB Output is correct
5 Correct 9 ms 6576 KB Output is correct
6 Correct 10 ms 6580 KB Output is correct
7 Correct 16 ms 6604 KB Output is correct
8 Correct 17 ms 6612 KB Output is correct
9 Correct 20 ms 6616 KB Output is correct
10 Correct 20 ms 6580 KB Output is correct
11 Correct 19 ms 6616 KB Output is correct
12 Correct 16 ms 6612 KB Output is correct
13 Correct 10 ms 6476 KB Output is correct
14 Correct 10 ms 6604 KB Output is correct
15 Correct 13 ms 6552 KB Output is correct
16 Correct 15 ms 6600 KB Output is correct
17 Correct 15 ms 6476 KB Output is correct
18 Correct 17 ms 6604 KB Output is correct
19 Correct 14 ms 6476 KB Output is correct
20 Correct 15 ms 6600 KB Output is correct
21 Correct 16 ms 6600 KB Output is correct
22 Correct 16 ms 6592 KB Output is correct
23 Correct 16 ms 6568 KB Output is correct
24 Correct 20 ms 6604 KB Output is correct
25 Correct 10 ms 6476 KB Output is correct
26 Correct 10 ms 6476 KB Output is correct
27 Correct 17 ms 6604 KB Output is correct
28 Correct 18 ms 6608 KB Output is correct
29 Correct 16 ms 6576 KB Output is correct
30 Correct 17 ms 6596 KB Output is correct
31 Correct 16 ms 6604 KB Output is correct
32 Correct 16 ms 6616 KB Output is correct
33 Correct 10 ms 6476 KB Output is correct
34 Correct 13 ms 6604 KB Output is correct
35 Correct 19 ms 6548 KB Output is correct
36 Correct 15 ms 6612 KB Output is correct
37 Correct 11 ms 6524 KB Output is correct
38 Correct 14 ms 6584 KB Output is correct
39 Correct 598 ms 11752 KB Output is correct
40 Correct 620 ms 11704 KB Output is correct
41 Correct 631 ms 11736 KB Output is correct
42 Correct 593 ms 11824 KB Output is correct
43 Correct 587 ms 11716 KB Output is correct
44 Correct 536 ms 11808 KB Output is correct
45 Correct 97 ms 11460 KB Output is correct
46 Correct 107 ms 11548 KB Output is correct
47 Correct 533 ms 11580 KB Output is correct
48 Correct 601 ms 11800 KB Output is correct
49 Correct 550 ms 11668 KB Output is correct
50 Correct 555 ms 11776 KB Output is correct
51 Correct 402 ms 11280 KB Output is correct
52 Correct 480 ms 11788 KB Output is correct
53 Correct 435 ms 11528 KB Output is correct
54 Correct 453 ms 11632 KB Output is correct
55 Runtime error 119 ms 19528 KB Execution killed with signal 11
56 Halted 0 ms 0 KB -