#include <bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;
const int N = 3e5+10;
const int INF = INT_MAX;
const int mod = 1e9+7;
const string NAME = "solve";
int n,m,q;
ll tree[4*N],lazy[4*N];
void down(int id, int l, int r) {
ll t = lazy[id];
tree[id] += t;
tree[id] = max(0LL,tree[id]);
if(l < r) {
lazy[id << 1] += t;
lazy[id << 1 | 1] += t;
}
lazy[id] = 0;
}
void update(int u, int v, ll val, int id = 1, int l = 1, int r = n) {
down(id,l,r);
if(v < l or r < u) {
return;
}
if(u <= l and r <= v) {
lazy[id] += val;
down(id,l,r);
return;
}
int mid = l + r >> 1;
update(u,v,val,id << 1,l,mid);
update(u,v,val,id << 1 | 1,mid+1,r);
tree[id] = min(tree[id << 1],tree[id << 1 | 1]);
}
ll get(int pos, int id = 1, int l = 1, int r = n) {
down(id,l,r);
if(r < pos or pos < l) {
return 0;
}
if(l == r) {
return tree[id];
}
int mid = l + r >> 1;
return get(pos,id << 1,l,mid)+get(pos,id << 1 | 1,mid+1,r);
}
signed main()
{
if (fopen((NAME + ".inp").c_str(), "r")) {
freopen((NAME + ".inp").c_str(), "r", stdin);
freopen((NAME + ".out").c_str(), "w", stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m >> q;
assert(m == 1);
while(q--) {
int type; cin >> type;
if(type == 1) {
ll l,r,c,k; cin >> l >> r >> c >> k;
update(l,r,k);
}
else if(type == 2) {
ll l,r,k; cin >> l >> r >> k;
update(l,r,-k);
}
else {
ll a,b; cin >> a >> b;
ll val = get(a);
// for(int i = 1 ; i <= n ; i++) {
// cout << get(i) << '\n';
// }
// return 0;
// cout << val << '\n';
if(b <= val) {
cout << 1 << '\n';
}
else {
cout << 0 << '\n';
}
}
}
return 0;
}
Compilation message
foodcourt.cpp: In function 'void update(int, int, long long int, int, int, int)':
foodcourt.cpp:36:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
36 | int mid = l + r >> 1;
| ~~^~~
foodcourt.cpp: In function 'long long int get(int, int, int, int)':
foodcourt.cpp:50:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
50 | int mid = l + r >> 1;
| ~~^~~
foodcourt.cpp: In function 'int main()':
foodcourt.cpp:57:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
57 | freopen((NAME + ".inp").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
foodcourt.cpp:58:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
58 | freopen((NAME + ".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
600 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
600 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
163 ms |
8796 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
600 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
600 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
600 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |