#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
const ll inf = 1e16+1;
struct segtree_beats{
struct node{
ll mn[2], cnt[2];
ll sm, lazy_add;
node(){
mn[0] = 0, mn[1] = inf;
cnt[0] = 1, cnt[1] = 0;
sm = 0;
lazy_add = 0;
}
node operator+(node a){
node rt;
if(mn[0] < a.mn[0]){
rt.mn[0] = mn[0], rt.cnt[0] = cnt[0];
if(mn[1] < a.mn[0]) rt.mn[1] = mn[1], rt.cnt[1] = cnt[1];
else if(mn[1] > a.mn[0]) rt.mn[1] = a.mn[0], rt.cnt[1] = a.cnt[0];
else rt.mn[1] = mn[1], rt.cnt[1] = cnt[1]+a.cnt[0];
}
else if(mn[0] > a.mn[0]){
rt.mn[0] = a.mn[0], rt.cnt[0] = a.cnt[0];
if(mn[0] < a.mn[1]) rt.mn[1] = mn[0], rt.cnt[1] = cnt[0];
else if(mn[0] > a.mn[1]) rt.mn[1] = a.mn[1], rt.cnt[1] = a.cnt[1];
else rt.mn[1] = mn[0], rt.cnt[1] = cnt[0]+a.cnt[1];
}
else{
rt.mn[0] = mn[0], rt.cnt[0] = cnt[0]+a.cnt[0];
if(mn[1] < a.mn[1]) rt.mn[1] = mn[1], rt.cnt[1] = cnt[1];
else if(mn[1] > a.mn[1]) rt.mn[1] = a.mn[1], rt.cnt[1] = a.cnt[1];
else rt.mn[1] = mn[1], rt.cnt[1] = cnt[1]+a.cnt[1];
}
rt.sm = sm+a.sm;
return rt;
}
void propagate(node nd, int sz){
lazy_add+=nd.lazy_add;
sm+=nd.lazy_add*sz;
mn[0]+=nd.lazy_add;
if(mn[1] != inf) mn[1]+=nd.lazy_add;
if(nd.mn[0] <= mn[0]) return;
sm+=(nd.mn[0]-mn[0])*sz;
mn[0] = nd.mn[0];
}
};
int k;
vector<node> v;
segtree_beats(int n){
k = 1;
while(k < n) k*=2;
k*=2;
v.resize(k, node());
for(int i = k/2-1; i > 0; i--) v[i] = v[2*i]+v[2*i+1];
}
void add(int l, int r, int nd, int a, int b, ll x){
if(a > r || b < l){
return;
}
if(a >= l && b <= r){
node nd0;
nd0.lazy_add = x;
nd0.mn[0] = -inf+1;
v[nd].propagate(nd0, b-a+1);
return;
}
int md = (a+b)/2;
v[2*nd].propagate(v[nd], md-a+1);
v[2*nd+1].propagate(v[nd], b-md);
v[nd].lazy_add = 0;
add(l, r, 2*nd, a, md, x);
add(l, r, 2*nd+1, md+1, b, x);
v[nd] = v[2*nd]+v[2*nd+1];
}
void add(int l, int r, ll x){
add(l, r, 1, 0, k/2-1, x);
}
void chmx(int l, int r, int nd, int a, int b, ll x){
if(a > r || b < l || v[nd].mn[0] >= x){
return;
}
if(a >= l && b <= r && v[nd].mn[1] > x){
node nd0;
nd0.mn[0] = x;
v[nd].propagate(nd0, b-a+1);
return;
}
int md = (a+b)/2;
v[2*nd].propagate(v[nd], md-a+1);
v[2*nd+1].propagate(v[nd], b-md);
v[nd].lazy_add = 0;
chmx(l, r, 2*nd, a, md, x);
chmx(l, r, 2*nd+1, md+1, b, x);
v[nd] = v[2*nd]+v[2*nd+1];
}
void chmx(int l, int r, ll x){
chmx(l, r, 1, 0, k/2-1, x);
}
ll sum(int l, int r, int nd, int a, int b){
if(a > r || b < l){
return 0;
}
if(a >= l && b <= r){
return v[nd].sm;
}
int md = (a+b)/2;
v[2*nd].propagate(v[nd], md-a+1);
v[2*nd+1].propagate(v[nd], b-md);
v[nd].lazy_add = 0;
ll rt = sum(l, r, 2*nd, a, md) + sum(l, r, 2*nd+1, md+1, b);
v[nd] = v[2*nd]+v[2*nd+1];
return rt;
}
ll sum(int l, int r){
return sum(l, r, 1, 0, k/2-1);
}
};
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m, q; cin >> n >> m >> q;
segtree_beats beats(n);
while(q--){
int tt; cin >> tt;
if(tt == 1){
int l, r, c; ll k; cin >> l >> r >> c >> k; l--, r--;
beats.add(l, r, k);
}
else if(tt == 2){
int l, r; ll k; cin >> l >> r >> k; l--, r--;
beats.add(l, r, -k);
beats.chmx(l, r, 0LL);
}
else{
int a; ll b; cin >> a >> b; a--;
cout << (beats.sum(a, a) >= b ? 1:0) << "\n";
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
576 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
576 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
117 ms |
7620 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
554 ms |
30420 KB |
Output is correct |
2 |
Correct |
456 ms |
29252 KB |
Output is correct |
3 |
Correct |
569 ms |
31052 KB |
Output is correct |
4 |
Correct |
471 ms |
29380 KB |
Output is correct |
5 |
Correct |
395 ms |
29784 KB |
Output is correct |
6 |
Correct |
560 ms |
31180 KB |
Output is correct |
7 |
Correct |
95 ms |
4664 KB |
Output is correct |
8 |
Correct |
94 ms |
4532 KB |
Output is correct |
9 |
Correct |
500 ms |
31252 KB |
Output is correct |
10 |
Correct |
478 ms |
31192 KB |
Output is correct |
11 |
Correct |
560 ms |
31256 KB |
Output is correct |
12 |
Correct |
528 ms |
31208 KB |
Output is correct |
13 |
Correct |
544 ms |
31024 KB |
Output is correct |
14 |
Correct |
615 ms |
31072 KB |
Output is correct |
15 |
Correct |
660 ms |
31132 KB |
Output is correct |
16 |
Correct |
678 ms |
31060 KB |
Output is correct |
17 |
Correct |
646 ms |
31056 KB |
Output is correct |
18 |
Correct |
606 ms |
31488 KB |
Output is correct |
19 |
Correct |
570 ms |
31064 KB |
Output is correct |
20 |
Correct |
587 ms |
31088 KB |
Output is correct |
21 |
Correct |
637 ms |
30980 KB |
Output is correct |
22 |
Correct |
630 ms |
31040 KB |
Output is correct |
23 |
Correct |
596 ms |
31072 KB |
Output is correct |
24 |
Correct |
621 ms |
31176 KB |
Output is correct |
25 |
Correct |
425 ms |
30580 KB |
Output is correct |
26 |
Correct |
436 ms |
30688 KB |
Output is correct |
27 |
Correct |
483 ms |
30816 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
576 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
93 ms |
7904 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
576 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
576 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |