bzoj5055: 膜法師(BIT)
阿新 • • 發佈:2017-10-21
lis delta ostream play ons opened string none fin
大水題WA了兩發T T
記錄一下a[i]的前綴和,a[i]*a[j]就是sigma(a[j]*sumi[j-1])
記錄一下a[i]*a[j]的前綴和,a[i]*a[j]*a[k]就是sigma(a[k]*sumij[k-1])
因為要求ai<aj<ak,所以前綴和必須用權值樹狀數組來統計
#include<iostream> #include<cstring> #include<cstdlib> #include<cstdio> #include<cmath> #includeView Code<algorithm> #define MOD(x) ((x)>=mod?(x)-mod:(x)) using namespace std; const int maxn=500010,mod=19260817; int n,N,ans; int a[maxn],b[maxn],lisan[maxn],tree[2][maxn]; char buf[80000010],*ptr=buf-1; inline int read() { char c=*++ptr;int s=0,t=1; while(c<48||c>57)c=*++ptr; while(c>=48&&c<=57){s=s*10+c-‘0‘;c=*++ptr;} return s*t; } inline int lowbit(int x){return x&-x;} inline void add(int x,int delta,int ty){for(;x<=N;x+=lowbit(x))tree[ty][x]=MOD(tree[ty][x]+delta);} inline int query(int x,int ty){int sum=0;for(;x;x-=lowbit(x))sum=MOD(sum+tree[ty][x]);returnsum;} int main() { fread(buf,1,sizeof(buf),stdin);n=read(); for(int i=1;i<=n;i++)a[i]=read(),a[i]%=mod,b[i]=a[i];N=n; sort(b+1,b+1+N);N=unique(b+1,b+1+N)-b-1; for(int i=1;i<=n;i++)lisan[i]=lower_bound(b+1,b+1+N,a[i])-b; for(int i=1;i<=n;i++) { ans=(ans+1ll*a[i]*query(lisan[i]-1,1))%mod; int x=1ll*a[i]*query(lisan[i]-1,0)%mod; add(lisan[i],a[i],0);add(lisan[i],x,1); } printf("%d\n",ans); }
bzoj5055: 膜法師(BIT)