A factory produces thimbles in bulk. Typically, it can produce up to a thimbles a day. However, some of the machinery is defective, so it can currently only produce b thimbles each day. The factory intends to choose a k-day period to do maintenance and construction; it cannot produce any thimbles during this time, but will be restored to its full production of a thimbles per day after the k days are complete.
Initially, no orders are pending. The factory receives updates of the form di, ai, indicating that ai new orders have been placed for the di-th day. Each order requires a single thimble to be produced on precisely the specified day. The factory may opt to fill as many or as few of the orders in a single batch as it likes.
As orders come in, the factory owner would like to know the maximum number of orders he will be able to fill if he starts repairs on a given day pi. Help the owner answer his questions.
The first line contains five integers n, k, a, b, and q (1 ≤ k ≤ n ≤ 200 000, 1 ≤ b < a ≤ 10 000, 1 ≤ q ≤ 200 000) — the number of days, the length of the repair time, the production rates of the factory, and the number of updates, respectively.
The next q lines contain the descriptions of the queries. Each query is of one of the following two forms:
- 1 diai (1 ≤ di ≤ n, 1 ≤ ai ≤ 10 000), representing an update of ai orders on day di, or
- 2 pi (1 ≤ pi ≤ n - k + 1), representing a question: at the moment, how many orders could be filled if the factory decided to commence repairs on day pi?
It's guaranteed that the input will contain at least one query of the second type.
For each query of the second type, print a line containing a single integer — the maximum number of orders that the factory can fill over all n days.
5 2 2 1 8 1 1 2 1 5 3 1 2 1 2 2 1 4 2 1 3 2 2 1 2 3
3 6 4
5 4 10 1 6 1 1 5 1 5 5 1 3 2 1 5 2 2 1 2 2
7 1
Consider the first sample.
We produce up to 1 thimble a day currently and will produce up to 2 thimbles a day after repairs. Repairs take 2 days.
For the first question, we are able to fill 1 order on day 1, no orders on days 2 and 3 since we are repairing, no orders on day 4 since no thimbles have been ordered for that day, and 2 orders for day 5 since we are limited to our production capacity, for a total of 3 orders filled.
For the third question, we are able to fill 1 order on day 1, 1 order on day 2, and 2 orders on day 5, for a total of 4 orders.
#include<bits/stdc++.h>
#define ls(o) (o<<1)
#define rs(o) (o<<1|1)
using namespace std;
typedef long long ll;
using namespace std;
/*
线段树模版题,我还想着建造两颗树
事实就是我们保留两个值,感觉有时候很sb
*/
const int maxn=2e5+10;
struct Tree{
int l,r;
ll sum_min,sum_max,val;
}tr[maxn*4];
ll a,b;
void build(int l,int r,int o){
tr[o].l=l,tr[o].r=r;
tr[o].val=tr[o].sum_min=tr[o].sum_max=0;
if(l==r) return;
int mid=(l+r)>>1;
build(l,mid,ls(o));
build(mid+1,r,rs(o));
}
void update(int pos,ll val,int o){
if(tr[o].l==tr[o].r){
tr[o].val+=val;
tr[o].sum_min=min(tr[o].val,b);
tr[o].sum_max=min(tr[o].val,a);
return;
}
int mid=(tr[o].l+tr[o].r)>>1;
if(pos<=mid)
update(pos,val,ls(o));
else
update(pos,val,rs(o));
tr[o].sum_min=tr[ls(o)].sum_min+tr[rs(o)].sum_min;
tr[o].sum_max=tr[ls(o)].sum_max+tr[rs(o)].sum_max;
// printf("o:%d l:%d r:%d mi:%lld mx:%lld\n",o,tr[o].l,tr[o].r,tr[o].sum_min,tr[o].sum_max);
}
ll query(int flag,int l,int r,int o){
// printf("o:%d l:%d r:%d %d %d\n",o,l,r,tr[o].l,tr[o].r);
if(tr[o].l>=l&&tr[o].r<=r){
if(flag)
return tr[o].sum_max;
else
return tr[o].sum_min;
}
int mid=(tr[o].l+tr[o].r)>>1;
if(r<=mid)
return query(flag,l,r,ls(o));
else if(l>mid)
return query(flag,l,r,rs(o));
else{
return query(flag,l,mid,ls(o))+query(flag,mid+1,r,rs(o));
}
}
int main(){
int n,k,q;
scanf("%d %d %lld %lld %d",&n,&k,&a,&b,&q);
build(1,n,1);
for(int i=1;i<=q;i++){
int t,d;ll p;
scanf("%d",&t);
if(t==1){
scanf("%d %lld",&d,&p);
update(d,p,1);
}
else{
scanf("%d",&d);
ll ans1=d-1<1?0:query(0,1,d-1,1);
ll ans2=d+k>n?0:query(1,d+k,n,1);
ll ans=ans1+ans2;
printf("%lld\n",ans);
}
}
return 0;
}