Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2213 Accepted Submission(s): 858
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define ULL unsigned long long 4 #define LL long long 5 LL mod=1e9+7; 6 LL C[100010]; 7 int N; 8 struct node{ 9 int v,d; 10 bool operator<(const node& C)const{ 11 if(v!=C.v) return v<C.v; 12 return d<C.d; 13 } 14 }a[101010]; 15 bool cmp(node A,node B){return A.d<B.d;} 16 int main(){ 17 int i,j; 18 while(scanf("%d",&N)==1){ 19 LL ans=0; 20 for(i=1;i<=N;++i) scanf("%d",&a[i].v),a[i].d=i; 21 sort(a+1,a+1+N); 22 for(i=1;i<=N;++i) a[i].v=i; 23 sort(a+1,a+1+N,cmp); 24 for(i=1;i<=N;++i){ 25 LL tmp=1; 26 for(int x=a[i].v;x>0;x-=(x&-x)) (tmp+=C[x])%=mod; 27 for(int x=a[i].v;x<=N;x+=(x&-x)) (C[x]+=tmp)%=mod; 28 (ans+=tmp)%=mod; 29 } 30 printf("%lld\n",ans); 31 memset(C,0,sizeof(C)); 32 } 33 return 0; 34 }