比赛 |
2025.5.4 |
评测结果 |
AAAAAAAAAA |
题目名称 |
数列操作η |
最终得分 |
100 |
用户昵称 |
徐诗畅 |
运行时间 |
2.977 s |
代码语言 |
C++ |
内存使用 |
7.94 MiB |
提交时间 |
2025-05-04 11:22:02 |
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int n,q,b[N];
struct tree{
int tag,ans,w,k;
}t[N<<2];
void push_up(int p){
t[p].k=min(t[p<<1].k,t[p<<1|1].k);
t[p].ans=t[p<<1].ans+t[p<<1|1].ans;
}
void build(int p,int l,int r){
if(l==r){
t[p].tag=t[p].ans=0;
t[p].w=t[p].k=b[l];
return;
}
int mid=(l+r)>>1;
build(p<<1,l,mid);
build(p<<1|1,mid+1,r);
push_up(p);
}
void addtag(int p,int d){
t[p].tag+=d;
t[p].k-=d;
}
void push_down(int p){
if(t[p].tag){
addtag(p<<1,t[p].tag);
addtag(p<<1|1,t[p].tag);
t[p].tag = 0;
}
}
void update(int p,int l,int r,int L,int R,int d){
if(L<=l&&R>=r){
addtag(p,d);
if(t[p].k<=0){
if(l==r){
t[p].ans++; t[p].k=t[p].w; t[p].tag=0;
}
else{
push_down(p);
int mid=(l+r)>>1;
update(p<<1,l,mid,l,r,0);
update(p<<1|1,mid+1,r,l,r,0);
push_up(p);
}
}
return;
}
push_down(p);
int mid=(l+r)>>1;
if(L<=mid) update(p<<1,l,mid,L,R,d);
if(R>mid) update(p<<1|1,mid+1,r,L,R,d);
push_up(p);
}
int query(int p,int l,int r,int L,int R){
if(L<=l && R>=r) return t[p].ans;
push_down(p);
int mid=(l+r)>>1,res=0;
if(L<=mid) res+=query(p<<1,l,mid,L,R);
if(R>mid) res+=query(p<<1|1,mid+1,r,L,R);
return res;
}
int main(){
freopen("eta.in","r",stdin);
freopen("eta.out","w",stdout);
scanf("%d%d",&n,&q);
for(int i=1;i<=n;i++) scanf("%d",&b[i]);
build(1,1,n);
while(q--){
string s; int l,r;
cin>>s>>l>>r;
if(s[0]=='a') update(1,1,n,l,r,1);
else printf("%d\n",query(1,1,n,l,r));
}
return 0;
}