标签:cout code getchar == res space getc int span
1 #include <bits/stdc++.h> 2 #define il inline 3 #define RG register 4 #define ll long long 5 #define rhl (19260817) 6 #define N (300010) 7 8 using namespace std; 9 10 int sum[20*N],ls[20*N],rs[20*N],rt[N],a[N],hsh[N],n,sz,tot,ans; 11 12 il int gi(){ 13 RG int x=0,q=1; RG char ch=getchar(); 14 while ((ch<‘0‘ || ch>‘9‘) && ch!=‘-‘) ch=getchar(); 15 if (ch==‘-‘) q=-1,ch=getchar(); 16 while (ch>=‘0‘ && ch<=‘9‘) x=x*10+ch-48,ch=getchar(); 17 return q*x; 18 } 19 20 il void insert(RG int x,RG int &y,RG int l,RG int r,RG int p,RG int v){ 21 sum[y=++sz]=sum[x]+v; if (sum[y]>=rhl) sum[y]-=rhl; 22 ls[y]=ls[x],rs[y]=rs[x]; if (l==r) return; RG int mid=(l+r)>>1; 23 p<=mid?insert(ls[x],ls[y],l,mid,p,v):insert(rs[x],rs[y],mid+1,r,p,v); return; 24 } 25 26 il int query(RG int x,RG int y,RG int l,RG int r,RG int xl,RG int xr){ 27 if (x==y) return 0; 28 if (xl<=l && r<=xr){ 29 RG int res=sum[y]-sum[x]; 30 return res<0 ? res+rhl : res; 31 } 32 RG int mid=(l+r)>>1; 33 if (xr<=mid) return query(ls[x],ls[y],l,mid,xl,xr); 34 if (xl>mid) return query(rs[x],rs[y],mid+1,r,xl,xr); 35 RG int res=query(ls[x],ls[y],l,mid,xl,mid)+query(rs[x],rs[y],mid+1,r,mid+1,xr); 36 return res>=rhl ? res-rhl : res; 37 } 38 39 int main(){ 40 #ifndef ONLINE_JUDGE 41 freopen("mogic.in","r",stdin); 42 freopen("mogic.out","w",stdout); 43 #endif 44 n=gi(); for (RG int i=1;i<=n;++i) a[i]=gi(),hsh[++tot]=a[i]; 45 sort(hsh+1,hsh+tot+1),tot=unique(hsh+1,hsh+tot+1)-hsh-1; 46 for (RG int i=1;i<=n;++i){ 47 a[i]=lower_bound(hsh+1,hsh+tot+1,a[i])-hsh; 48 insert(rt[i-1],rt[i],1,tot,a[i],hsh[a[i]]%rhl); 49 } 50 for (RG int i=2,l,r;i<n;++i){ 51 l=a[i]>1 ? query(rt[0],rt[i],1,tot,1,a[i]-1) : 0; 52 r=a[i]<tot ? query(rt[i],rt[n],1,tot,a[i]+1,tot) : 0; 53 ans=(ans+1LL*l*r%rhl*hsh[a[i]])%rhl; 54 } 55 cout<<ans; return 0; 56 }
标签:cout code getchar == res space getc int span
原文地址:http://www.cnblogs.com/wfj2048/p/7622910.html