Tranvick

Untitled

Apr 12th, 2012
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.80 KB | None | 0 0
  1. #include <cstdio>
  2. #include <algorithm>
  3. #define forn(I,B) for (int I=1;I<=(B);I++)
  4. #define rep(I,B) for (int I=0;I<(B);I++)
  5. #define ropen(X) freopen(X,"r",stdin)
  6. #define wopen(X) freopen(X,"w",stdout)
  7.  
  8. using namespace std;
  9.  
  10. typedef long long ll;
  11. const int N=111111;
  12. const ll MOD=1000000007;
  13.  
  14. int a[N],n,sor[N];
  15. ll s[N];
  16.  
  17. inline void update(int pos,ll val){
  18.     for (;pos<=n;pos=(pos|(pos-1))+1) s[pos]+=val;
  19. }
  20.  
  21. inline ll get(int pos){
  22.     ll res=0;
  23.     for (;pos;pos&=pos-1) res=(res+s[pos])%MOD;
  24.     return res;
  25. }
  26.  
  27. int main(){
  28.     ropen("input.txt");
  29.     wopen("output.txt");
  30.     scanf("%d",&n);
  31.     rep(i,n){
  32.         scanf("%d",&a[i]);
  33.         sor[i]=a[i];
  34.     }
  35.     sort(sor,sor+n);
  36.     rep(i,n) a[i]=lower_bound(sor,sor+n,a[i])-sor+1;
  37.     rep(i,n) update(a[i],(get(a[i]-1)+1)%MOD);
  38.     printf("%I64d\n",get(n));
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment