This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define all(s) s.begin(), s.end()
#define int long long
#define ll long long
#define fr first
#define sc second
#define pb push_back
#define mk make_pair
#define pi pair < int, int >
const int N = 65007;
const int INF = 1e9 + 7;
ll cnt[N];
int n, m, q;
deque < pair < ll , pi > > dq[N];
set < int > s;
set < int > :: iterator itl;
main (){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m >> q;
for (int i = 1; i <= q; i++){
int t;
cin >> t;
if (t == 1){
int l, r, c, k;
cin >> l >> r >> c >> k;
for (int j = l; j <= r; j++){
dq[j].pb({cnt[j], {k, c}});
cnt[j] += k;
s.insert(j);
}
}
else if (t == 2){
int l, r, k;
cin >> l >> r >> k;
int prv = l - 1;
while (!s.empty()){
itl = s.lower_bound(prv + 1);
if (itl == s.end())
break;
int j = *itl;
// cout << l << ' ' << r << ' ' << j << endl;
if (j > r)
break;
int kc = k;
while (!dq[j].empty() && kc){
int a = dq[j].front().sc.fr, b = dq[j].front().sc.sc, cc = dq[j].front().fr;
dq[j].pop_front();
if (a > kc){
dq[j].push_front({cc + kc, {a - kc, b}});
break;
}
kc -= a;
}
if (dq[j].empty())
s.erase(j);
prv = j;
}
}
else {
int a;
ll b;
cin >> a >> b;
if (dq[a].empty()){
cout << 0 << endl;
continue;
}
b += dq[a].front().fr;
if (dq[a].back().fr + 1ll * dq[a].back().sc.fr < b){
cout << 0 << endl;
continue;
}
int l = 0, r = dq[a].size();
while (l + 1 < r){
int mid = (l + r) >> 1;
if (dq[a][mid].fr < b)
l = mid;
else
r = mid;
}
cout << dq[a][l].sc.sc << endl;
}
}
}
Compilation message (stderr)
foodcourt.cpp:24:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
24 | main (){
| ^~~~
# | 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... |