和之前的hdu3030都快一样了
可以参考之前的题解
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> using namespace std; const int maxn = 1e5+5; long long n; long long a[maxn]; long long b[maxn]; long long c[maxn]; long long mod = 1e9+7; void add(long long c[],long long i,long long j); long long getsum(long long c[],long long i); int main() { int i,j,k; while(scanf("%lld",&n) != EOF) { memset(c, 0, sizeof(c)); for(i=1;i<=n;++i) { scanf("%lld",a+i); b[i] = a[i]; } sort(b+1,b+n+1); long long sum = 0; for(i=1;i<=n;++i) { long long ans=0; long long pos=lower_bound(b+1,b+n+1,a[i]) - b; ans = getsum(c,pos); sum += ans+1; sum %= mod; add(c, pos, ans+1); } printf("%lld ",sum); } } long long lowbit(long long k) { return k&(-k); } void add(long long c[],long long i,long long j) { while(i<=n) { c[i] += j; c[i] %= mod; i += lowbit(i); } } long long getsum(long long c[],long long i) { long long sum = 0; while(i > 0) { sum += c[i]; sum %= mod; i -= lowbit(i); } return sum; }