题意:有
n天,每天普通情况下可以产生b个东西,维修完机器的情况下可以产生a个东西,
由普通的情况到好的情况需要k天的休息,就这k天啥也干不了,现在有
q次询问
现在你有两个操作
1 x y,表示订单第x天需要y个东西
2 x 在第x天进行休息,然后问你最多能够满足多少个东西的需求
思路:直接树状数组维护一下,k天以前每个点的最大值为b,k天以后每个点的最大值为a,记录区间和
#include <cstdio>
#include <queue>
#include <cstring>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <set>
#include <ctime>
#include <cmath>
#include <cctype>
using namespace std;
#define maxn 200000+100
#define LL long long
int cas=1,T;
int n,k,a,b,q;
int c[maxn][2];
int A[maxn];
int lowbit(int x)
{
return x&(-x);
}
void update(int x,int y,int z)
{
for (int i = x;i<maxn;i+=lowbit(i))
c[i][z]+=y;
}
int getsum(int x,int z)
{
int ans = 0;
for (int i = x;i;i-=lowbit(i))
ans+=c[i][z];
return ans;
}
int main()
{
while (scanf("%d%d%d%d%d",&n,&k,&a,&b,&q)!=EOF)
{
for (int i = 1;i<=q;i++)
{
int op;
scanf("%d",&op);
if (op==1)
{
int x,y;
scanf("%d%d",&x,&y);
int temp = A[x];
A[x]+=y;
update(x,min(b,A[x])-min(b,temp),0);
update(x,min(a,A[x])-min(a,temp),1);
}
else
{
int x;
scanf("%d",&x);
printf("%d\n",getsum(x-1,0)+getsum(n,1)-getsum(x+k-1,1));
}
}
}
//freopen("in","r",stdin);
//scanf("%d",&T);
//printf("time=%.3lf",(double)clock()/CLOCKS_PER_SEC);
return 0;
}