Analysis: This kind of problem is bad Street, n^2, and then the data structure is optimized to Nlogn, discretization
#include <cstdio>#include<cstring>#include<queue>#include<Set>#include<map>#include<stack>#include<cstdlib>#include<algorithm>#include<vector>#include<cmath>using namespaceStd;typedefLong LongLl;typedef pair<int,int>PII;Const intn=1e5+5;Const intinf=0x3f3f3f3f;Const intMod=1000000007;intP[n],n,a[n],c[n];intCNT;voidAddintXintt) { for(inti=x;i<=cnt;i+=i& (-i)) C[i]= (c[i]+t)%MoD;}intAskintx) { if(x==0)return 0; intans=0; for(intI=x;i>0;i-=i& (-i)) ans= (Ans+c[i])%MoD; returnans;}intMain () { while(~SCANF ("%d",&N)) { for(intI=1; i<=n;++i) scanf ("%d", &a[i]), p[i]=A[i]; Sort (P+1, p+1+N); CNT=unique (p+1, p+1+n)-p-1; Memset (c,0,sizeof(c)); intans=0; for(intI=1; i<=n;++i) { intPos=lower_bound (p+1, p+1+cnt,a[i])-p; intTmp= (Ask (pos-1)+1)%MoD; Add (pos,tmp); Ans= (ans+tmp)%MoD; } printf ("%d\n", ans); } return 0;}
View Code
FZU2236 14th target dp+ tree-like array optimization