1. /*
  2. n*n暴力 这个很好想
  3. */
  4. #include<cstdio>
  5. #define maxn 100010
  6. #define mod 9901
  7. using namespace std;
  8. int n,k,a[maxn],f[maxn],ans;
  9. int Abs(int a){
  10. return a<?-a:a;
  11. }
  12. int max(int a,int b){
  13. return a<b?b:a;
  14. }
  15. int main()
  16. {
  17. freopen("cin.txt","r",stdin);
  18. freopen("right.out","w",stdout);
  19. scanf("%d%d",&n,&k);
  20. for(int i=;i<=n;i++)
  21. scanf("%d",&a[i]);
  22. for(int i=;i<=n;i++){
  23. for(int j=;j<i;j++){
  24. if(Abs(a[i]-a[j])>k)continue;
  25. f[i]=(f[i]+f[j]+)%mod;
  26. }
  27. ans=(ans+f[i])%mod;
  28. }
  29. printf("%d\n",ans);
  30. return ;
  31. }
  1. /*
  2. 搞个数据结构来优化
  3. 开始想错了题意 就写了线段树+离散化
  4. 后来反应过来了..树状数组就行QAQ
  5. 开始写wa了 改着改着就搞出了两个线段树
  6. 这就跑的有点慢了 但A点没问题
  7. */
  8. #include<iostream>
  9. #include<cstdio>
  10. #include<cstring>
  11. #include<algorithm>
  12. #define maxn 100010
  13. #define mod 9901
  14. #define lc k*2
  15. #define rc k*2+1
  16. #define mid (l+r)/2
  17. using namespace std;
  18. int n,m,d,a[maxn],c[maxn];
  19. int sum[maxn*],tot[maxn*];
  20. int init(){
  21. int x=,f=;char s=getchar();
  22. while(s<''||s>''){if(s=='-')f=-;s=getchar();}
  23. while(s>=''&&s<=''){x=x*+s-'';s=getchar();}
  24. return x*f;
  25. }
  26. void Change(int k,int l,int r,int x,int y){
  27. if(l==x&&r==x){
  28. sum[k]=(sum[k]+y)%mod;return;
  29. }
  30. if(x<=mid)Change(lc,l,mid,x,y);
  31. else Change(rc,mid+,r,x,y);
  32. sum[k]=(sum[lc]+sum[rc])%mod;
  33. }
  34. int Query(int k,int l,int r,int x,int y){
  35. if(x<=l&&y>=r){
  36. return sum[k];
  37. }
  38. int ret=;
  39. if(x<=mid)ret=(ret+Query(lc,l,mid,x,y))%mod;
  40. if(y>mid)ret=(ret+Query(rc,mid+,r,x,y))%mod;
  41. return ret;
  42. }void change(int k,int l,int r,int x,int y){
  43. if(l==x&&r==x){
  44. tot[k]=(tot[k]+y)%mod;return;
  45. }
  46. if(x<=mid)change(lc,l,mid,x,y);
  47. else change(rc,mid+,r,x,y);
  48. tot[k]=(tot[lc]+tot[rc])%mod;
  49. }
  50. int query(int k,int l,int r,int x,int y){
  51. if(x<=l&&y>=r){
  52. return tot[k];
  53. }
  54. int ret=;
  55. if(x<=mid)ret=(ret+query(lc,l,mid,x,y))%mod;
  56. if(y>mid)ret=(ret+query(rc,mid+,r,x,y))%mod;
  57. return ret;
  58. }
  59. int main()
  60. {
  61. while(~scanf("%d%d",&n,&d)){
  62. memset(tot,,sizeof(tot));
  63. memset(sum,,sizeof(sum));
  64. m=;
  65. for(int i=;i<=n;i++){
  66. a[i]=init();c[i]=a[i];
  67. }
  68. sort(c+,c++n);
  69. m=unique(c+,c++n)-c-;
  70. int L,R,M,S,s;
  71. for(int i=;i<=n;i++){
  72. L=lower_bound(c+,c++m,a[i]-d)-c;
  73. R=upper_bound(c+,c++m,a[i]+d)-c-;
  74. M=lower_bound(c+,c++m,a[i])-c;
  75. S=Query(,,m,L,R);
  76. s=query(,,m,L,R);
  77. Change(,,m,M,S+s);
  78. change(,,m,M,);
  79. }
  80. printf("%d\n",sum[]);
  81. }
  82. return ;
  83. }

hdu 3450 Counting Sequences的更多相关文章

  1. HDU 3450 Counting Sequences(线段树)

    Counting Sequences Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/65536 K (Java/Other ...

  2. hdu 5862 Counting Intersections

    传送门:hdu 5862 Counting Intersections 题意:对于平行于坐标轴的n条线段,求两两相交的线段对有多少个,包括十,T型 官方题解:由于数据限制,只有竖向与横向的线段才会产生 ...

  3. HDU 5862 Counting Intersections(离散化+树状数组)

    HDU 5862 Counting Intersections(离散化+树状数组) 题目链接http://acm.split.hdu.edu.cn/showproblem.php?pid=5862 D ...

  4. [hdu 6184 Counting Stars(三元环计数)

    hdu 6184 Counting Stars(三元环计数) 题意: 给一张n个点m条边的无向图,问有多少个\(A-structure\) 其中\(A-structure\)满足\(V=(A,B,C, ...

  5. Hdu 5862 Counting Intersections(有n条线段,每一条线段都是平行于x轴或者y轴,问有多少个交点+树状数组区间求和单点跟新)

    传送门:Hdu 5862 Counting Intersections 题意:有n条线段,每一条线段都是平行于x轴或者y轴,问有多少个交点 分析: 基本的操作流程是:先将所有的线段按照横树坐标x按小的 ...

  6. HDU 1264 Counting Squares(线段树求面积的并)

    Counting Squares Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  7. HDU 5862 Counting Intersections (树状数组)

    Counting Intersections 题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5862 Description Given ...

  8. HDU 5952 Counting Cliques 【DFS+剪枝】 (2016ACM/ICPC亚洲区沈阳站)

    Counting Cliques Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  9. HDU 5862 Counting Intersections 扫描线+树状数组

    题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5862 Counting Intersections Time Limit: 12000/ ...

随机推荐

  1. INI解析模块的C++实现

    INI文件格式是某些平台或软件上的配置文件的非正式标准,以节(section)和键(key)构成,常用于微软Windows操作系统中. 节(section) 节用方括号括起来,单独占一行,例如: [s ...

  2. QT的父子Widget之间消息的传递(如果子类没有accept或ignore该事件,则该事件会被传递给其父亲——Qlabel与QPushButton的处理就不一样)

    以前我一直以为:在父widget上摆一个子widget后,当click子widget时:只会进入到子widget的相关事件处理函数中,比如进入到mousePressEvent()中, 而不会进入到父w ...

  3. ubuntu下virtualbox使用u盘

    1.virtualbox中使用u盘流程 以下是使用U盘的整个流程(参考了网络上其他人的教程,亲测可用): 添加当前用户为vboxusers一员 终端输入:cat /etc/group |grep vb ...

  4. TCP/IP小纪

    链 路 层 主 要 有 三 个 目 的 :( 1 )为 I P 模 块 发 送 和 接收 I P 数 据 报 ; ( 2 )为 A R P 模块发送 A R P 请 求 和 接 收 A R P 应 答 ...

  5. python模块与包加载机制

    模块的搜索路径: When a module named spam is imported, the interpreter searches for a file named spam.py in ...

  6. 开源网络备份软件 bacula 的安装、配置和运行

    安装bacula 1 bacula的几种网络备份拓扑 前面文章介绍了bacula有5个组成部分,在实际的应用中,没有必要将5个部分分别放在不同的服务器上,它们之间的某些部分是可以合并的,常见的bacu ...

  7. soundtouch源码分析__based on csdn :

    1. soundtouch介绍和相关资源 The SoundTouch Library Copyright © Olli Parviainen 2001-2014 SoundTouch is an o ...

  8. 动态规划(树形DP):HDU 5834 Magic boy Bi Luo with his excited tree

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAA8UAAAJbCAIAAABCS6G8AAAgAElEQVR4nOy9fXQcxZ0uXH/hc8i5N+

  9. Best Premium Private Proxy Service | Lime Proxies

    Best Premium Private Proxy Service | Lime Proxies undefined

  10. 2014年河南省第七届ACM大赛总结

    虽然大赛已经结束了两天,不过比赛的场景还是不断地在眼前回放,一遍遍,这次的比赛给了我很深刻的感悟还有教训. 刚开始比赛选择了贩卖武器那道题,也是全场到最后唯一没有被人做出来的一道题,策略的严重错误,大 ...