# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1127781 | VinhLuu | Food Court (JOI21_foodcourt) | C++20 | 62 ms | 14408 KiB |
#include <bits/stdc++.h>
#define ll long long
#define all(lpv) lpv.begin(), lpv.end()
#define pot(x, y) lower_bound(x.begin(), x.end(), y) - x.begin() + 1
using namespace std;
#define lpv
#ifndef lpv
#include "AC.h"
#endif // lpv
#define int long long
const int N = 2e5 + 5;
int n, m, q, T[N], L[N], R[N], C[N], K[N], sz[N];
namespace sub1 {
deque<pair<int,int>> dq[2002];
void solve() {
for(int i = 1; i <= q; i ++) {
if(T[i] == 1) {
for(int j = L[i]; j <= R[i]; j ++) {
dq[j].push_back({C[i], K[i]});
sz[j] += K[i];
}
}
else if (T[i] == 2) {
for(int j = L[i]; j <= R[i]; j ++) {
int cnt = K[i];
sz[j] = max(0ll, sz[j] - K[i]);
while(!dq[j].empty() && cnt != 0) {
if(dq[j].front().second <= cnt) {
cnt -= dq[j].front().second;
dq[j].pop_front();
} else {
int x, y; tie(x, y) = dq[j].front();
dq[j].pop_front();
dq[j].push_front({x, y - cnt});
cnt = 0;
}
}
}
} else {
// cerr << L[i] << " " << dq[L[i]].size() << " g\n";
if(sz[L[i]] < R[i]) cout << 0 << "\n";
else {
int cnt = R[i];
for(auto [x, y] : dq[L[i]]) {
if(cnt <= y) {
cout << x << "\n";
break;
} else cnt -= y;
}
}
}
}
}
}
#ifdef lpv
signed main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define task "v"
if(fopen(task ".inp","r")) {
freopen(task ".inp","r",stdin);
freopen(task ".out","w",stdout);
}
cin >> n >> m >> q;
for(int i = 1; i <= q; i ++) {
cin >> T[i];
if(T[i] == 1) cin >> L[i] >> R[i] >> C[i] >> K[i];
else if(T[i] == 2) cin >> L[i] >> R[i] >> K[i];
else cin >> L[i] >> R[i];
}
sub1 :: solve();
}
#endif // lpv
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |