//#pragma GCC optimize("Ofast,O3")
//#pragma GCC target("avx,avx2")
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debugger.cpp"
#else
#define debug(...)
#endif
template<class T>
int len(T &a){
return a.size();
}
using ll = long long;
using pii = pair<int,int>;
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
string fileio = "";
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
const int MOD = 1e9 + 7;
const int inf = 1e9;
const ll infl = 1e18;
const int maxn = 1e5 + 1;
struct SegmentTree{
//To change
struct Node{
//defaults
ll A = 0;
ll x = 0;
void apply(ll B){
A = max(B, A + B);
x = max(0ll, A);
}
};
void push(int x){
if(t[x].A){
t[x << 1].apply(t[x].A);
t[x << 1 | 1].apply(t[x].A);
t[x].A = 0;
}
}
vector<Node> t;
int n;
//construction
void init(int _n){
n = _n;
t.resize(4 * n);
}
void upd(int x, int lx, int rx, int l, int r, int val){
if(rx < l || r < lx) return;
if(l <= lx && rx <= r){
t[x].apply(val); return;
}
push(x);
int mx = (lx + rx) >> 1;
upd(x << 1, lx, mx, l, r, val);
upd(x << 1 | 1, mx + 1, rx, l, r, val);
}
ll get(int x, int l, int r, int ind){
if(l == r){
return t[x].x;
}
push(x);
int m = (l + r) / 2;
if(ind <= m) return get(x << 1, l, m, ind);
return get(x << 1 | 1, m + 1, r, ind);
}
void upd(int l, int r, int k){
upd(1, 0, n - 1, l, r, k);
}
ll get(int ind){
return get(1, 0, n - 1, ind);
}
};
void solve(){
int n, m, q; cin >> n >> m >> q;
SegmentTree t;
t.init(n);
while(q --){
int tt; cin >> tt;
if(tt == 1){
int l, r, c, k;
cin >> l >> r >> c >> k;
l --; r --; c --;
t.upd(l, r, k);
}else if(tt == 2){
int l, r, k; cin >> l >> r >> k;
l --; r --;
t.upd(l, r, -k);
}else{
int a, b; cin >> a >> b;
a --;
debug(t.get(a));
cout << (t.get(a) >= b ? 1 : 0) << '\n';
}
}
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
auto start = chrono::high_resolution_clock::now();
#ifndef LOCAL
if(fileio.size()){
freopen((fileio + ".in").c_str(), "r", stdin);
freopen((fileio + ".out").c_str(), "w", stdout);
}
#endif
int testcases = 1;
#ifdef Tests
cin >> testcases;
#endif
while(testcases --){
solve();
if(testcases) cout << '\n';
#ifdef LOCAL
else cout << '\n';
cout << "_________________________" << endl;
#endif
}
#ifdef LOCAL
auto duration = chrono::duration_cast<chrono::microseconds>(chrono::high_resolution_clock::now() - start);
cout << "time: " << (double)duration.count()/1000.0 << " milliseconds" << endl;
#endif
return 0;
}
Compilation message
foodcourt.cpp: In function 'int main()':
foodcourt.cpp:124:10: warning: variable 'start' set but not used [-Wunused-but-set-variable]
124 | auto start = chrono::high_resolution_clock::now();
| ^~~~~
foodcourt.cpp:127:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
127 | freopen((fileio + ".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
foodcourt.cpp:128:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
128 | freopen((fileio + ".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
30 ms |
5564 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
26 ms |
14804 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
8 ms |
4444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |