#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 clr[N];
int n, m, q;
vector < pi > nxt[N];
vector < pi > gt[N];
int ans[N];
int t[4 * N];
void upd (int v, int l, int r, int pos, int val){
if (l == r)
t[v] += val;
else {
int mid = (l + r) >> 1;
if (pos <= mid)
upd(v + v, l, mid, pos, val);
else
upd(v + v + 1, mid + 1, r, pos, val);
t[v] = t[v + v] + t[v + v + 1];
}
}
int get (int v, int l, int r, int pos, int val){
// cout << v << ' ' << l << ' ' << r << endl;
if (l > pos)
return 0;
int mid = (l + r) >> 1;
if (r <= pos){
if (l == r)
return clr[l];
if (t[v] < val)
return 0;
if (t[v + v] >= val)
return get(v + v, l, mid, pos, val);
val -= t[v + v];
return get(v + v + 1, mid + 1, r, pos, val);
}
else {
int r1 = get(v + v, l, mid, pos, val);
int r2 = get(v + v + 1, mid + 1, r, pos, val);
if (r2)
return r2;
return r1;
}
}
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;
clr[i] = c;
nxt[l].pb({i, k});
nxt[r + 1].pb({i, -k});
}
else if (t == 3){
int a;
ll b;
cin >> a >> b;
gt[a].pb({i, b});
}
else
return 0;
}
for (int i = 1; i <= n; i++){
for (auto it : nxt[i]){
upd(1, 1, q, it.fr, it.sc);
}
for (auto it : gt[i]){
ans[it.fr] = get(1, 1, q, it.fr, it.sc);
}
}
for (int i = 1; i <= q; i++){
if (ans[i] == -1)
cout << 0 << endl;
else if (ans[i])
cout << ans[i] << endl;
}
}
Compilation message
foodcourt.cpp:64:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
64 | main (){
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
3296 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
3296 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
3276 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
7 ms |
6644 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
3296 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
86 ms |
7684 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
3296 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
3296 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |