#include #include using namespace std; int N,P[2<<17]; int mx(int a,int b){return a>N; for(int i=0;i>P[i]; inv[P[i]-1]=i; S[i+1]=S[i]+P[i]; } { atcoder::segtreeQ(N); for(int i=0;iQ(N); for(int i=N;i--;) { R[i]=Q.prod(0,P[i]); Q.set(P[i]-1,i); } } for(int i=0;i>A; int k=inv[i]; long ans=0; if(k-L[k]1) { int mid=(l+r)/2; if(S[mid]-S[x]<=A)l=mid; else r=mid; } ans+=l-k; } } else { for(int y=k;y1) { int mid=(l+r)/2; if(S[y+1]-S[mid+1]<=A)r=mid; else l=mid; } ans+=k-r; } } cout<