比赛 |
2025.5.4 |
评测结果 |
AAAAAAAAAA |
题目名称 |
数列操作η |
最终得分 |
100 |
用户昵称 |
wdsjl |
运行时间 |
1.748 s |
代码语言 |
C++ |
内存使用 |
9.34 MiB |
提交时间 |
2025-05-04 11:28:49 |
显示代码纯文本
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const int N = 100010;
int n,q;
int lc[N*4],rc[N*4],nd[N*4],sum[N*4],b[N*4],ans[N*4];
void build(int p,int ll,int rr){
lc[p]=ll;
rc[p]=rr;
if(ll==rr){
scanf("%d",b+p);
nd[p]=b[p];
return ;
}
int mid=(ll+rr)/2;
build(p<<1,ll,mid);
build(p<<1|1,mid+1,rr);
nd[p]=min(nd[p<<1],nd[p<<1|1]);
}
void ad_tag(int p,int v)
{
sum[p] += v;
nd[p] -= v;
if(lc[p]==rc[p])
{
ans[p] += (sum[p]/ b[p]);
nd[p] =b[p]- (sum[p] % b[p]);
sum[p] %=b[p] ;
}
if(nd[p]<=0)
{
ad_tag(p<<1, sum[p]);
ad_tag(p<<1|1, sum[p]);
sum[p] = 0;
ans[p] = ans[p<<1] + ans[p<<1|1];
nd[p]=min(nd[p<<1], nd[p<<1|1]);
}
}
void push_down(int p){
if(sum[p]){
sum[p<<1]+=sum[p];
nd[p<<1]-=sum[p];
sum[p<<1|1]+=sum[p];
nd[p<<1|1]-=sum[p];
sum[p]=0;
}
return ;
}
void add(int p,int ll,int rr){
if(lc[p]==rc[p]){
sum[p]++;
nd[p]--;
ans[p]+=(sum[p]/b[p]);
nd[p]=b[p]-(sum[p]%b[p]);
sum[p]%=b[p];
return ;
}
if(lc[p]==ll&&rc[p]==rr){
sum[p]++;
nd[p]--;
if(nd[p]>0)return ;
ad_tag(p<<1,sum[p]);
ad_tag(p<<1|1,sum[p]);
nd[p]=min(nd[p<<1],nd[p<<1|1]);
ans[p]=ans[p<<1]+ans[p<<1|1];
sum[p]=0;
return ;
}
int mid=(lc[p]+rc[p])>>1;
push_down(p);
if(rr<=mid){
add(p<<1,ll,rr);
nd[p]=min(nd[p<<1],nd[p<<1|1]);
ans[p]=ans[p<<1]+ans[p<<1|1];
return ;
}else if(ll>mid){
add(p<<1|1,ll,rr);
nd[p]=min(nd[p<<1],nd[p<<1|1]);
ans[p]=ans[p<<1]+ans[p<<1|1];
return ;
}else{
add(p<<1,ll,mid);
add(p<<1|1,mid+1,rr);
ans[p]=ans[p<<1]+ans[p<<1|1];
nd[p]=min(nd[p<<1],nd[p<<1|1]);
return;
}
}
int query(int p,int ll,int rr){
if(lc[p]==ll&&rc[p]==rr){
return ans[p];
}
int mid =(lc[p]+rc[p])/2;
push_down(p);
if(rr<=mid){
return query(p<<1,ll,rr);
}else if(ll>mid){
return query(p<<1|1,ll,rr);
}else{
return query(p<<1,ll,mid)+query(p<<1|1,mid+1,rr);
}
}
char s[10];
int main(){
freopen("eta.in","r",stdin);
freopen("eta.out","w",stdout);
scanf("%d%d",&n,&q);
build(1,1,n);
for(int i=0;i<q;i++){
// cout<<"E"<<i<<endl;
int x,y;
scanf("%s",s);
scanf("%d%d",&x,&y);
// cout<<"er"<<query(1,1,n)<<endl;
if(s[0]=='a'){
add(1,x,y);
}else{
printf("%d\n",query(1,x,y));
}
}
return 0;
}