P5459 [BJOI2016] 回转寿司
P5459 [BJOI2016] 回转寿司
https://www.luogu.com.cn/problem/P5459
https://www.luogu.com.cn/article/nnyrsj3m
空间,由于单点修改操作至多涉及
#include<iostream>
using namespace std;
typedef long long ll;
const int N=100010,M=6e6;
const ll INF=1e10;
bool _u;
int n,L,R,v[M],rt,l[M],r[M],idx;
ll ans,a[N];
bool _v;
void pushup(int p){
v[p]=v[l[p]]+v[r[p]];
}
int query(int &p,ll ql,ll qr,ll L=-INF,ll R=INF){
if(!p)p=++idx;
if(ql<=L&&R<=qr)return v[p];
ll mid=L+R>>1,res=0;
if(ql<=mid)res=query(l[p],ql,qr,L,mid);
if(qr>mid)res+=query(r[p],ql,qr,mid+1,R);
return res;
}
void modify(int &p,ll x,ll L=-INF,ll R=INF){
if(!p)p=++idx;
if(L==R){
++v[p];
return;
}
ll mid=L+R>>1;
if(x<=mid)modify(l[p],x,L,mid);
else modify(r[p],x,mid+1,R);
pushup(p);
}
int main(){
#ifdef LOCAL
freopen("1.txt","r",stdin);
#endif
#ifndef LOCAL
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
#endif
cerr<<(&_v-&_u)/1024.0/1024.0<<'\n';
cin>>n>>L>>R;
for(int i=1;i<=n;++i){
int x;
cin>>x;
a[i]=a[i-1]+x;
}
modify(rt,0);
for(int i=1;i<=n;++i){
ans+=query(rt,a[i]-R,a[i]-L);
modify(rt,a[i]);
}
cout<<ans;
return 0;
}
本文作者:wscqwq
本文链接:https://www.cnblogs.com/wscqwq/p/18376315
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
2023-08-23 translate
2023-08-23 SG函数
2023-08-23 nim游戏
2023-08-23 [ABC305G]