题意:机器好的时候一天完成a件工作,坏的时候一天完成b件工作,开始为坏的,修机器需要k天,q个询问,每次给两个操作,1,在d天新来a间工作,2在p天开始修机器,修机器时不能完成工作。对于每个2操作输出n天总共能完成多少工作。
思路:
线段树的每个叶结点维护两个数,修理前和修理后,这段区间的几天能做的工作的总和,叶节点我处理的比较麻烦,应该有更好的方式。注意细节
ac代码:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<map>
#include<unordered_map>
#include<set>
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int maxn=200100;
struct node{int l,r;ll va,vb;
}tr[maxn<<2];
int n,k,a,b,q,d,p,op;
void pushup(int cur){tr[cur].va=0;//初始化tr[cur].vb=0;if(tr[cur<<1].l==tr[cur<<1].r){if(tr[cur<<1].va>=0)tr[cur].va+=a;else tr[cur].va+=a+tr[cur<<1].va;if(tr[cur<<1].vb>=0)tr[cur].vb+=b;else tr[cur].vb+=b+tr[cur<<1].vb;}else{tr[cur].va+=tr[cur<<1].va;tr[cur].vb+=tr[cur<<1].vb;}if(tr[cur<<1|1].l==tr[cur<<1|1].r){if(tr[cur<<1|1].va>=0)tr[cur].va+=a;else tr[cur].va+=a+tr[cur<<1|1].va;if(tr[cur<<1|1].vb>=0)tr[cur].vb+=b;else tr[cur].vb+=b+tr[cur<<1|1].vb;}else{tr[cur].vb+=tr[cur<<1|1].vb;tr[cur].va+=tr[cur<<1|1].va;//少写了一半}
}
void build(int l,int r,int cur){int mid=(l+r)>>1;tr[cur].l=l;tr[cur].r=r;tr[cur].va=0;tr[cur].vb=0;if(l==r){tr[cur].va=-a;tr[cur].vb=-b;return ;}build(l,mid,cur<<1);build(mid+1,r,cur<<1|1);pushup(cur);
}
void update(int tar,int val,int cur){if(tr[cur].l==tr[cur].r){tr[cur].va+=val;tr[cur].vb+=val;return ;}if(tr[cur<<1].r>=tar)update(tar,val,cur<<1);if(tr[cur<<1|1].l<=tar)update(tar,val,cur<<1|1);pushup(cur);
}
ll query(int pl,int pr,int op,int cur){ll res=0;if(pl<=tr[cur].l&&pr>=tr[cur].r){if(op==0){if(tr[cur].l==tr[cur].r) return tr[cur].vb>=0?b:b+tr[cur].vb;else return tr[cur].vb;}else{if(tr[cur].l==tr[cur].r) return tr[cur].va>=0?a:a+tr[cur].va;else return tr[cur].va;}}if(pl<=tr[cur<<1].r) res+=query(pl,pr,op,cur<<1);if(pr>=tr[cur<<1|1].l) res+=query(pl,pr,op,cur<<1|1);return res;
}
int main(){scanf("%d%d%d%d%d",&n,&k,&a,&b,&q);build(1,n,1);while(q--){scanf("%d",&op);if(op==1){scanf("%d%d",&d,&p);update(d,p,1);}else {scanf("%d",&p);ll res=0;if(p-1>=1) res+=query(1,p-1,0,1);if(p+k<=n) res+=query(p+k,n,1,1);printf("%lld\n",res);}}return 0;
}