#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll mxn = 250005;
#define tlll tuple<ll,ll,ll>
#define pll pair<ll,ll>
#define fs first
#define sc second
#define ls now*2+1
#define rs now*2+2
#define mid ((l+r)>>1)
struct SEG1{
struct node{
ll in,out,debt;
node(ll ii = 0,ll oo = 0,ll dd = 0){
in = ii,out = oo,debt = dd;
}
};
node seg[mxn*4];
node addtag(node u,node d){
ll dif = min(u.debt,d.in);
d.in -= dif;
u.debt -= dif;
d.out = u.out+d.out+dif;
d.debt = d.debt+u.debt;
d.in = d.in+u.in;
return d;
}
void push(int now,int l,int r){
seg[ls] = addtag(seg[now],seg[ls]);
seg[rs] = addtag(seg[now],seg[rs]);
seg[now].in = seg[now].out = seg[now].debt = 0;
return;
}
void add(int now,int l,int r,int s,int e,ll v){
if(l>=s&&e>=r){
seg[now].in += v;
return;
}
push(now,l,r);
if(mid>=s)add(ls,l,mid,s,e,v);
if(mid<e)add(rs,mid+1,r,s,e,v);
return;
}
void del(int now,int l,int r,int s,int e,ll v){
if(l>=s&&e>=r){
seg[now] = addtag(node(0,0,v),seg[now]);
return;
}
push(now,l,r);
if(mid>=s)del(ls,l,mid,s,e,v);
if(mid<e)del(rs,mid+1,r,s,e,v);
}
int getval(int now,int l,int r,int p,ll cnt){
if(l == r){
if(seg[now].in<cnt)return -1;
else return seg[now].out+cnt;
}
push(now,l,r);
if(mid>=p)return getval(ls,l,mid,p,cnt);
else return getval(rs,mid+1,r,p,cnt);
}
};
struct SEG2{
ll seg[mxn*4];
void modify(int now,int l,int r,int p,ll v){
if(l == r){
seg[now] += v;
return;
}
if(mid>=p)modify(ls,l,mid,p,v);
else modify(rs,mid+1,r,p,v);
seg[now] = seg[ls]+seg[rs];
}
ll getbig(int now,int l,int r,ll tar){
if(l == r)return l;
if(seg[ls]>=tar)return getbig(ls,l,mid,tar);
else return getbig(rs,mid+1,r,tar-seg[ls]);
}
};
#undef ls
#undef rs
#undef mid
SEG1 seg1;
SEG2 seg2;
ll N,M,Q;
int col[mxn];
vector<pll> req[mxn];
int ans[mxn];
vector<pll> op[mxn];
vector<int> askid;
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>N>>M>>Q;
for(int i = 1;i<=Q;i++){
int t;
cin>>t;
if(t == 1){
ll l,r,c,k;
cin>>l>>r>>c>>k;
op[l].push_back(pll(i,k));
op[r+1].push_back(pll(i,-k));
col[i] = c;
seg1.add(0,1,N,l,r,k);
}
else if(t == 2){
ll l,r,k;
cin>>l>>r>>k;
seg1.del(0,1,N,l,r,k);
}
else{
int a,b;
cin>>a>>b;
askid.push_back(i);
auto tmp = seg1.getval(0,1,N,a,b);
if(tmp == -1)ans[i] = -1;
else req[a].push_back(pll(i,tmp));
}
}
for(int i = 1;i<=N;i++){
for(auto &j:op[i]){
seg2.modify(0,1,Q,j.fs,j.sc);
}
for(auto &j:req[i]){
ans[j.fs] = col[seg2.getbig(0,1,Q,j.sc)];
}
}
for(auto &i:askid)cout<<max(ans[i],0)<<'\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
36952 KB |
Output is correct |
2 |
Correct |
8 ms |
36956 KB |
Output is correct |
3 |
Correct |
7 ms |
37080 KB |
Output is correct |
4 |
Correct |
9 ms |
36956 KB |
Output is correct |
5 |
Correct |
8 ms |
37080 KB |
Output is correct |
6 |
Correct |
8 ms |
36956 KB |
Output is correct |
7 |
Correct |
8 ms |
36956 KB |
Output is correct |
8 |
Correct |
10 ms |
37016 KB |
Output is correct |
9 |
Correct |
8 ms |
36952 KB |
Output is correct |
10 |
Correct |
8 ms |
36956 KB |
Output is correct |
11 |
Correct |
8 ms |
36956 KB |
Output is correct |
12 |
Correct |
8 ms |
36956 KB |
Output is correct |
13 |
Correct |
8 ms |
37120 KB |
Output is correct |
14 |
Correct |
8 ms |
36956 KB |
Output is correct |
15 |
Correct |
9 ms |
36956 KB |
Output is correct |
16 |
Correct |
9 ms |
37068 KB |
Output is correct |
17 |
Correct |
9 ms |
36956 KB |
Output is correct |
18 |
Correct |
9 ms |
36956 KB |
Output is correct |
19 |
Correct |
9 ms |
37208 KB |
Output is correct |
20 |
Correct |
9 ms |
37156 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
36952 KB |
Output is correct |
2 |
Correct |
8 ms |
36956 KB |
Output is correct |
3 |
Correct |
7 ms |
37080 KB |
Output is correct |
4 |
Correct |
9 ms |
36956 KB |
Output is correct |
5 |
Correct |
8 ms |
37080 KB |
Output is correct |
6 |
Correct |
8 ms |
36956 KB |
Output is correct |
7 |
Correct |
8 ms |
36956 KB |
Output is correct |
8 |
Correct |
10 ms |
37016 KB |
Output is correct |
9 |
Correct |
8 ms |
36952 KB |
Output is correct |
10 |
Correct |
8 ms |
36956 KB |
Output is correct |
11 |
Correct |
8 ms |
36956 KB |
Output is correct |
12 |
Correct |
8 ms |
36956 KB |
Output is correct |
13 |
Correct |
8 ms |
37120 KB |
Output is correct |
14 |
Correct |
8 ms |
36956 KB |
Output is correct |
15 |
Correct |
9 ms |
36956 KB |
Output is correct |
16 |
Correct |
9 ms |
37068 KB |
Output is correct |
17 |
Correct |
9 ms |
36956 KB |
Output is correct |
18 |
Correct |
9 ms |
36956 KB |
Output is correct |
19 |
Correct |
9 ms |
37208 KB |
Output is correct |
20 |
Correct |
9 ms |
37156 KB |
Output is correct |
21 |
Incorrect |
7 ms |
36956 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
42 ms |
41044 KB |
Output is correct |
2 |
Correct |
47 ms |
41508 KB |
Output is correct |
3 |
Correct |
42 ms |
41040 KB |
Output is correct |
4 |
Correct |
41 ms |
40880 KB |
Output is correct |
5 |
Correct |
49 ms |
41420 KB |
Output is correct |
6 |
Correct |
53 ms |
41560 KB |
Output is correct |
7 |
Correct |
22 ms |
40220 KB |
Output is correct |
8 |
Correct |
23 ms |
40328 KB |
Output is correct |
9 |
Correct |
48 ms |
40796 KB |
Output is correct |
10 |
Correct |
45 ms |
41040 KB |
Output is correct |
11 |
Correct |
46 ms |
41044 KB |
Output is correct |
12 |
Correct |
48 ms |
41044 KB |
Output is correct |
13 |
Correct |
45 ms |
41296 KB |
Output is correct |
14 |
Correct |
47 ms |
41808 KB |
Output is correct |
15 |
Correct |
51 ms |
42588 KB |
Output is correct |
16 |
Correct |
54 ms |
42664 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
43 ms |
38872 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
36952 KB |
Output is correct |
2 |
Correct |
8 ms |
36956 KB |
Output is correct |
3 |
Correct |
7 ms |
37080 KB |
Output is correct |
4 |
Correct |
9 ms |
36956 KB |
Output is correct |
5 |
Correct |
8 ms |
37080 KB |
Output is correct |
6 |
Correct |
8 ms |
36956 KB |
Output is correct |
7 |
Correct |
8 ms |
36956 KB |
Output is correct |
8 |
Correct |
10 ms |
37016 KB |
Output is correct |
9 |
Correct |
8 ms |
36952 KB |
Output is correct |
10 |
Correct |
8 ms |
36956 KB |
Output is correct |
11 |
Correct |
8 ms |
36956 KB |
Output is correct |
12 |
Correct |
8 ms |
36956 KB |
Output is correct |
13 |
Correct |
8 ms |
37120 KB |
Output is correct |
14 |
Correct |
8 ms |
36956 KB |
Output is correct |
15 |
Correct |
9 ms |
36956 KB |
Output is correct |
16 |
Correct |
9 ms |
37068 KB |
Output is correct |
17 |
Correct |
9 ms |
36956 KB |
Output is correct |
18 |
Correct |
9 ms |
36956 KB |
Output is correct |
19 |
Correct |
9 ms |
37208 KB |
Output is correct |
20 |
Correct |
9 ms |
37156 KB |
Output is correct |
21 |
Correct |
42 ms |
41044 KB |
Output is correct |
22 |
Correct |
47 ms |
41508 KB |
Output is correct |
23 |
Correct |
42 ms |
41040 KB |
Output is correct |
24 |
Correct |
41 ms |
40880 KB |
Output is correct |
25 |
Correct |
49 ms |
41420 KB |
Output is correct |
26 |
Correct |
53 ms |
41560 KB |
Output is correct |
27 |
Correct |
22 ms |
40220 KB |
Output is correct |
28 |
Correct |
23 ms |
40328 KB |
Output is correct |
29 |
Correct |
48 ms |
40796 KB |
Output is correct |
30 |
Correct |
45 ms |
41040 KB |
Output is correct |
31 |
Correct |
46 ms |
41044 KB |
Output is correct |
32 |
Correct |
48 ms |
41044 KB |
Output is correct |
33 |
Correct |
45 ms |
41296 KB |
Output is correct |
34 |
Correct |
47 ms |
41808 KB |
Output is correct |
35 |
Correct |
51 ms |
42588 KB |
Output is correct |
36 |
Correct |
54 ms |
42664 KB |
Output is correct |
37 |
Correct |
49 ms |
41040 KB |
Output is correct |
38 |
Correct |
44 ms |
40996 KB |
Output is correct |
39 |
Correct |
20 ms |
39996 KB |
Output is correct |
40 |
Correct |
21 ms |
40188 KB |
Output is correct |
41 |
Correct |
57 ms |
40788 KB |
Output is correct |
42 |
Correct |
52 ms |
41296 KB |
Output is correct |
43 |
Correct |
55 ms |
41296 KB |
Output is correct |
44 |
Correct |
55 ms |
41044 KB |
Output is correct |
45 |
Correct |
57 ms |
41312 KB |
Output is correct |
46 |
Correct |
65 ms |
41284 KB |
Output is correct |
47 |
Correct |
27 ms |
40656 KB |
Output is correct |
48 |
Correct |
48 ms |
41300 KB |
Output is correct |
49 |
Correct |
39 ms |
40236 KB |
Output is correct |
50 |
Correct |
59 ms |
40924 KB |
Output is correct |
51 |
Correct |
53 ms |
41296 KB |
Output is correct |
52 |
Correct |
58 ms |
41300 KB |
Output is correct |
53 |
Correct |
46 ms |
41708 KB |
Output is correct |
54 |
Correct |
63 ms |
42580 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
18 ms |
38996 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
36952 KB |
Output is correct |
2 |
Correct |
8 ms |
36956 KB |
Output is correct |
3 |
Correct |
7 ms |
37080 KB |
Output is correct |
4 |
Correct |
9 ms |
36956 KB |
Output is correct |
5 |
Correct |
8 ms |
37080 KB |
Output is correct |
6 |
Correct |
8 ms |
36956 KB |
Output is correct |
7 |
Correct |
8 ms |
36956 KB |
Output is correct |
8 |
Correct |
10 ms |
37016 KB |
Output is correct |
9 |
Correct |
8 ms |
36952 KB |
Output is correct |
10 |
Correct |
8 ms |
36956 KB |
Output is correct |
11 |
Correct |
8 ms |
36956 KB |
Output is correct |
12 |
Correct |
8 ms |
36956 KB |
Output is correct |
13 |
Correct |
8 ms |
37120 KB |
Output is correct |
14 |
Correct |
8 ms |
36956 KB |
Output is correct |
15 |
Correct |
9 ms |
36956 KB |
Output is correct |
16 |
Correct |
9 ms |
37068 KB |
Output is correct |
17 |
Correct |
9 ms |
36956 KB |
Output is correct |
18 |
Correct |
9 ms |
36956 KB |
Output is correct |
19 |
Correct |
9 ms |
37208 KB |
Output is correct |
20 |
Correct |
9 ms |
37156 KB |
Output is correct |
21 |
Incorrect |
7 ms |
36956 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
36952 KB |
Output is correct |
2 |
Correct |
8 ms |
36956 KB |
Output is correct |
3 |
Correct |
7 ms |
37080 KB |
Output is correct |
4 |
Correct |
9 ms |
36956 KB |
Output is correct |
5 |
Correct |
8 ms |
37080 KB |
Output is correct |
6 |
Correct |
8 ms |
36956 KB |
Output is correct |
7 |
Correct |
8 ms |
36956 KB |
Output is correct |
8 |
Correct |
10 ms |
37016 KB |
Output is correct |
9 |
Correct |
8 ms |
36952 KB |
Output is correct |
10 |
Correct |
8 ms |
36956 KB |
Output is correct |
11 |
Correct |
8 ms |
36956 KB |
Output is correct |
12 |
Correct |
8 ms |
36956 KB |
Output is correct |
13 |
Correct |
8 ms |
37120 KB |
Output is correct |
14 |
Correct |
8 ms |
36956 KB |
Output is correct |
15 |
Correct |
9 ms |
36956 KB |
Output is correct |
16 |
Correct |
9 ms |
37068 KB |
Output is correct |
17 |
Correct |
9 ms |
36956 KB |
Output is correct |
18 |
Correct |
9 ms |
36956 KB |
Output is correct |
19 |
Correct |
9 ms |
37208 KB |
Output is correct |
20 |
Correct |
9 ms |
37156 KB |
Output is correct |
21 |
Incorrect |
7 ms |
36956 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |