标签:des style blog color java os strong io
Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 722 Accepted Submission(s):
268
1 #include<iostream> 2 #include<string> 3 #include<cstdio> 4 #include<vector> 5 #include<queue> 6 #include<stack> 7 #include<algorithm> 8 #include<cstring> 9 #include<stdlib.h> 10 #include<string> 11 #include<cmath> 12 #include<map> 13 using namespace std; 14 #define mod 9901 15 #define pb push_back 16 #define LL __int64 17 #define mmax 100000+10 18 LL p[mmax],love[mmax],fuck[mmax],cnt,n,m; 19 int search1(LL x){ //找到>=x的第一个数 20 int l=1,r=cnt,mid,tmp=cnt+1; 21 while(l<=r){ 22 mid=(l+r)>>1; 23 if(fuck[mid]>=x) r=mid-1,tmp=min(tmp,mid); 24 else l=mid+1; 25 } 26 return tmp; 27 } 28 int search2(LL x){ //找到<=x的最后一个数 29 int l=1,r=cnt,mid,tmp=0; 30 // cout<<"x="<<x<<endl; 31 while(l<=r){ 32 mid=(l+r)>>1; 33 if(fuck[mid]<=x){ 34 // cout<<"tmp="<<tmp<<endl; 35 l=mid+1,tmp=max(tmp,mid); 36 // cout<<"tmp="<<tmp<<endl; 37 } 38 else r=mid-1; 39 } 40 return tmp; 41 } 42 void update(int pos,int x){ 43 while(pos<=cnt){ 44 p[pos]+=x; 45 p[pos]%=mod; 46 pos+=pos&(-pos); 47 } 48 } 49 int getnum(int pos){ 50 LL sum=0; 51 while(pos>=1){ 52 sum+=p[pos]; 53 pos-=pos&(-pos); 54 } 55 return sum%mod; 56 } 57 int main(){ 58 #ifndef ONLINE_JUDGE 59 freopen("input.txt","r" ,stdin); 60 #endif // ONLINE_JUDGE 61 while(cin>>n>>m){ 62 cnt=0; 63 for(int i=1;i<=n;i++) scanf("%I64d",&love[i]); 64 fuck[++cnt]=love[1]; 65 for(int i=2;i<=n;i++) if(love[i]!=love[i-1]) fuck[++cnt]=love[i]; 66 sort(fuck+1,fuck+1+cnt); 67 LL sum=0;memset(p,0,sizeof(p)); 68 for(int i=1;i<=n;i++){ 69 int a=search1(love[i]-m),b=search2(love[i]+m),c=search1(love[i]); 70 int tmp=getnum(b)-getnum(a-1); 71 //tmp%=mod; 不着为啥下面的改成这样就错了 72 tmp=(tmp%mod+mod)%mod; 73 sum+=tmp; 74 sum%=mod; 75 update(c,tmp+1); 76 } 77 cout<<sum<<endl; 78 } 79 }
hdu 2836 Traversal,布布扣,bubuko.com
标签:des style blog color java os strong io
原文地址:http://www.cnblogs.com/ainixu1314/p/3890838.html