#ifdef Home
#define _GLIBCXX_DEBUG
#endif // Home
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef deque < pair < int, int > > QQ;
QQ ShopsL[2222], ShopsR[2222];
void del(int i, int K) {
if(ShopsL[i].empty() || ShopsL[i].back().first < K) {
if(!ShopsL[i].empty()) {
K -= ShopsL[i].back().first;
}
for(; !ShopsL[i].empty(); ShopsL[i].pop_back());
for(int cnt; !ShopsR[i].empty();) {
cnt = ShopsR[i].back().first - (ShopsR[i].size() == 1 ? 0ll : ShopsR[i][ShopsR[i].size() - 2].first);
ShopsL[i].push_back({(ShopsL[i].empty() ? 0ll : ShopsL[i].back().first) + cnt, ShopsR[i].back().second});
ShopsR[i].pop_back();
}
}
for(int cnt; K && !ShopsL[i].empty();) {
cnt = ShopsL[i].back().first - (ShopsL[i].size() == 1 ? 0ll : ShopsL[i][ShopsL[i].size() - 2].first);
if(K < cnt) {
ShopsL[i].back().first -= K;
K = 0;
} else {
K -= cnt;
ShopsL[i].pop_back();
}
}
}
void add(int i, ll K, int C) {
if(!C) {
del(i, K);
return;
}
ShopsR[i].push_back({K + (ShopsR[i].empty() ? 0ll : ShopsR[i].back().first), C});
}
int get(int i, ll K) {
if((ShopsL[i].empty() ? 0ll : ShopsL[i].back().first) + (ShopsR[i].empty() ? 0ll : ShopsR[i].back().first) < K) {
return 0;
}
if(ShopsL[i].empty() || ShopsL[i].back().first < K) {
if(!ShopsL[i].empty()) {
K -= ShopsL[i].back().first;
}
int l = -1, r = ShopsR[i].size() - 1, m;
for(; l + 1 < r;) {
m = (l + r) / 2;
(ShopsR[i][m].first < K ? l : r) = m;
}
return ShopsR[i].empty() ? 0ll : ShopsR[i][r].second;
}
int l = 0, r = ShopsL[i].size(), m;
for(; l + 1 < r;) {
m = (l + r) / 2;
(ShopsL[i][m].first < K ? r : l) = m;
}
return ShopsL[i].empty() ? 0ll : ShopsL[i][l].second;
}
queue < pair < int, int > > tree[4444];
void relax(int x, int i) {
for(; !tree[x].empty(); tree[x].pop()) {
add(i, tree[x].front().first, tree[x].front().second);
}
}
void Push(pair < int, int > tmp, int x) {
if(tree[x].empty() || tree[x].back().second != tmp.second) {
tree[x].push(tmp);
return;
}
tree[x].back().first += tmp.first;
}
void push(int x) {
int l = x * 2 + 1, r = x * 2 + 2;
for(; !tree[x].empty(); tree[x].pop()) {
Push(tree[x].front(), l);
Push(tree[x].front(), r);
}
}
void add_to_que(int l, int r, pair < int, int > tmp, int x, int lx, int rx) {
if(r <= lx || rx <= l) {
return;
}
if(l <= lx && rx <= r) {
Push(tmp, x);
return;
}
push(x);
int m = (lx + rx) / 2;
add_to_que(l, r, tmp, x * 2 + 1, lx, m);
add_to_que(l, r, tmp, x * 2 + 2, m, rx);
}
int get(int pos, ll K, int x, int lx, int rx) {
if(lx + 1 == rx) {
relax(x, lx);
return get(lx, K);
}
push(x);
int m = (lx + rx) / 2;
return pos < m ?
get(pos, K, x * 2 + 1, lx, m) :
get(pos, K, x * 2 + 2, m, rx) ;
}
main() {
#ifdef Home
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif // Home
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m, q, k = 1;
pair < int, int > tmp;
ll T;
for(cin >> n >> m >> q; k <= n; k <<= 1);
for(int t, L, R, C, K; q --> 0;) {
cin >> t;
if(t == 1) {
cin >> L >> R >> C >> K;
tmp = {K, C};
++ R;
add_to_que(L, R, tmp, 0, 0, k);
} else if(t == 2) {
cin >> L >> R >> K;
++ R;
tmp = {K, 0};
add_to_que(L, R, tmp, 0, 0, k);
} else {
cin >> C >> T;
cout << get(C, T, 0, 0, k) << '\n';
}
}
}
Compilation message
foodcourt.cpp:120:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
120 | main() {
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
8 ms |
7764 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
8 ms |
7764 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
8 ms |
12500 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
7 ms |
12524 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
8 ms |
7764 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
8 ms |
12492 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
8 ms |
7764 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
8 ms |
7764 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |