Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <algorithm>
- #define forn(I,B) for (int I=1;I<=(B);I++)
- #define rep(I,B) for (int I=0;I<(B);I++)
- #define ropen(X) freopen(X,"r",stdin)
- #define wopen(X) freopen(X,"w",stdout)
- using namespace std;
- typedef long long ll;
- const int N=111111;
- const ll MOD=1000000007;
- int a[N],n,sor[N];
- ll s[N];
- inline void update(int pos,ll val){
- for (;pos<=n;pos=(pos|(pos-1))+1) s[pos]+=val;
- }
- inline ll get(int pos){
- ll res=0;
- for (;pos;pos&=pos-1) res=(res+s[pos])%MOD;
- return res;
- }
- int main(){
- ropen("input.txt");
- wopen("output.txt");
- scanf("%d",&n);
- rep(i,n){
- scanf("%d",&a[i]);
- sor[i]=a[i];
- }
- sort(sor,sor+n);
- rep(i,n) a[i]=lower_bound(sor,sor+n,a[i])-sor+1;
- rep(i,n) update(a[i],(get(a[i]-1)+1)%MOD);
- printf("%I64d\n",get(n));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment