标签:
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1844 Accepted Submission(s): 677
#include <iostream> #include <stdio.h> #include <string.h> #include <stack> #include <vector> #include <algorithm> using namespace std; typedef long long LL; const int N = 100005; const int mod = 1000000007; int n; int a[N],b[N],c[N]; int lowbit(int x){ return x&(-x); } void update(int idx,int v){ for(int i=idx;i<=n;i+=lowbit(i)){ c[i]=(c[i]+v)%mod; } } int getsum(int idx){ int sum = 0; for(int i=idx;i>=1;i-=lowbit(i)){ sum = (sum+c[i])%mod; } return sum; } int main() { while(scanf("%d",&n)!=EOF){ memset(c,0,sizeof(c)); for(int i=1;i<=n;i++){ scanf("%d",&a[i]); b[i] = a[i]; } sort(b+1,b+1+n); int ans = 0; for(int i=1;i<=n;i++){ int idx = lower_bound(b+1,b+1+n,a[i])-b; ans=getsum(idx); update(idx,ans+1); } printf("%d\n",getsum(n)); } return 0; }
标签:
原文地址:http://www.cnblogs.com/liyinggang/p/5656485.html