#include using namespace std; #define ALL(x) begin(x),end(x) #define rep(i,n) for(int i=0;i<(n);i++) #define debug(v) cout<<#v<<":";for(auto x:v){cout<bool chmax(T &a,const T &b){if(abool chmin(T &a,const T &b){if(b ostream &operator<<(ostream &os,const vector&v){ for(int i=0;i<(int)v.size();i++) os< istream &operator>>(istream &is,vector&v){ for(T &x:v)is>>x; return is; } signed main(){ int N;cin>>N; vector P(N); for(auto &x:P){ cin>>x;x--; } vector A(N); cin>>A; vector S(N+1,0); for(int i=0;i pos(N,0); rep(i,N) pos[P[i]]=i; set st; st.insert(-1); st.insert(N); for(int k=0;kp-l){ for(int i=p;i>l;i--){ int lw=p,hi=r-1,res=-1; while(lw<=hi){ int mid=(lw+hi)/2; ll sum=get(i,mid+1); if(sum<=A[k]) res=mid,lw=mid+1; else hi=mid-1; } if(res>=0) ans+=1ll+res-p; } }else{ for(int i=p;i=0) ans+=1ll+p-res; } } st.insert(p); cout<