区间最小值(2)

Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 65535/32768K (Java/Other)
Total Submission(s) : 26   Accepted Submission(s) : 9

Font: Times New Roman | Verdana | Georgia

Font Size: ← →

Problem Description

给定一个数字序列以及一些操作,查询随意给定区间内数字的最小值。

Input

输入包括多组測试数据,最多5组。

输入包括多组測试用例。每组測试用例的开头为一个整数n(1<=n<=100000),代表数字序列的长度。

接下去一行给出n个数字,代表数字序列。数字在int范围内。

下一行为一个整数t(1<=t<=10000)。代表操作的次数。

最后t行。每行给出一个操作,1 l r代表查询区间 [l,r]的最小值,0 l r c代表将区间[l r]的值所有替换为c (1<=l<=r<=n),c在整形范围内。

Output

对于每一个查询,输出区间[l,r]内的最小值。

Sample Input

  1. 5
  2. 1 2 3 4 5
  3. 7
  4. 1 1 5
  5. 0 1 3 6
  6. 1 1 4
  7. 1 2 3
  8. 0 2 2 0
  9. 1 1 2
  10. 1 3 5

Sample Output

  1. 1
  2. 4
  3. 6
  4. 0
  5. 4

Author

吴迎

迟到了五分钟才做了。

。感觉做的是对的。

尽管没能提交上。

找了一天了。。TM我最终找到怎么做了。。上午的时候事实上就知道怎么更新区间了。仅仅只是一个地方写错了

导致结果不正确 就放弃了。

今天下午尝试了那么多。

。o(︶︿︶)o 唉 刚刚发现上午写的是对的。

  1. <pre name="code" class="cpp">#include <stdio.h>
  2. #include <string.h>
  3. #include <algorithm>
  4. using namespace std;
  5. int num[100005];
  6. struct node
  7. {
  8. int left,right,val;
  9. }c[100005*4];
  10. void build_tree(int l,int r,int root)
  11. {
  12. c[root].left=l;
  13. c[root].right=r;
  14. if(l==r)
  15. {
  16. c[root].val=num[l];
  17. return ;
  18. }
  19. int mid=(l+r)/2;
  20. build_tree(l,mid,root*2);
  21. build_tree(mid+1,r,root*2+1);
  22. c[root].val=min(c[root*2].val,c[root*2+1].val);
  23. }
  24. void find_tree(int l,int r,int &min1,int root)
  25. {
  26. if(c[root].left==l&&c[root].right==r)
  27. {
  28. min1=c[root].val;
  29. return ;
  30. }
  31. int mid=(c[root].left+c[root].right)/2;
  32. if(mid<l)
  33. find_tree(l,r,min1,root*2+1);
  34. else if(mid>=r)
  35. find_tree(l,r,min1,root*2);
  36. else
  37. {
  38. int min2;
  39. find_tree(l,mid,min1,root*2);
  40. find_tree(mid+1,r,min2,root*2+1);
  41. min1=min(min1,min2);
  42. }
  43.  
  44. }
  45. void update_tree(int l,int r,int x,int root)
  46. {
  47. if(c[root].left==c[root].right)
  48. {
  49. c[root].val=x;
  50. return ;
  51. }
  52. int mid=(c[root].left+c[root].right)/2;
  53. if(mid<l)
  54. update_tree(l,r,x,root*2+1);
  55. else if(mid>=r)
  56. update_tree(l,r,x,root*2);
  57. else
  58. {
  59. update_tree(l,mid,x,root*2);
  60. update_tree(mid+1,r,x,root*2+1);
  61. }
  62. c[root].val=min(c[root*2].val,c[root*2+1].val);
  63. }
  64. int main()
  65. {
  66. int n,k;
  67. while(scanf("%d",&n)!=EOF)
  68. {
  69. for(int i=1;i<=n;i++)
  70. scanf("%d",&num[i]);
  71. build_tree(1,n,1);
  72. scanf("%d",&k);
  73. while(k--)
  74. {
  75. int a,b,min1,flag;
  76. scanf("%d",&flag);
  77. if(flag)
  78. {
  79. scanf("%d %d",&a,&b);
  80. find_tree(a,b,min1,1);
  81. printf("%d\n",min1);
  82. }
  83. else
  84. {
  85. int x;
  86. scanf("%d %d %d",&a,&b,&x);
  87. update_tree(a,b,x,1);
  88. //for(int i=1;i<=9;i++)
  89. //printf("[%d %d] %d\n",c[i].left,c[i].right,c[i].val);//自己測试的。
  90.  

  91. }
  92. }
  93. }
  94. return 0;
  95. }
  1.  

区间最小值(2) (线段树 更新区间)2015年 JXNU_ACS 算法组暑假第一次周赛的更多相关文章

  1. 区间最小值 线段树 (2015年 JXNU_ACS 算法组暑假第一次周赛)

    区间最小值 Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 65535/32768K (Java/Other) Total Submiss ...

  2. CSU-1110 RMQ with Shifts (单点更新+区间最小值 zkw线段树)

    In the traditional RMQ (Range Minimum Query) problem, we have a static array A. Then for each query ...

  3. hdu 1556:Color the ball(线段树,区间更新,经典题)

    Color the ball Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  4. hdu 1698:Just a Hook(线段树,区间更新)

    Just a Hook Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  5. UVA 12436-Rip Van Winkle's Code(线段树的区间更新)

    题意: long long data[250001]; void A( int st, int nd ) { for( int i = st; i \le nd; i++ ) data[i] = da ...

  6. hdu1698线段树的区间更新区间查询

    Just a Hook Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tota ...

  7. hihoCoder #1078 : 线段树的区间修改(线段树区间更新板子题)

    #1078 : 线段树的区间修改 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 对于小Ho表现出的对线段树的理解,小Hi表示挺满意的,但是满意就够了么?于是小Hi将问题 ...

  8. HDU 1556 Color the ball(线段树:区间更新)

    http://acm.hdu.edu.cn/showproblem.php?pid=1556 题意: N个气球,每次[a,b]之间的气球涂一次色,统计每个气球涂色的次数. 思路: 这道题目用树状数组和 ...

  9. zoj3686(线段树的区间更新)

    对线段树的区间更新有了初步的了解... A Simple Tree Problem Time Limit: 3 Seconds      Memory Limit: 65536 KB Given a ...

随机推荐

  1. 虚拟机安装教程(linux、centOS)

    前提: Windows7系统 64位 VMware-workstation-full-11.0.0-2305329.exe CentOS-6.6-x86_64-bin-DVD1.iso 安装步骤: 看 ...

  2. RSA进阶之共模攻击

    适用场景: 同一个n,对相同的m进行了加密,e取值不一样. e1和e2互质,gcd(e1,e2)=1 如果满足上述条件,那么就可以在不分解n的情况下求解m 原理 复杂的东西简单说: 如果gcd(e1, ...

  3. BugKu 杂项-这么多数据包

    前边的都是些无关紧要,只要有点网络的基础我想应该都能懂,往下看,一直到NO104,这是在干什么? 源ip138一直向目标ip159发送syn握手包,想要建立连接,其实就是端口扫描,原理就是,想和你某个 ...

  4. 几种常见的Android自动化测试框架及其应用

    随着Android应用得越来越广,越来越多的公司推出了自己移动应用测试平台.例如,百度的MTC.东软易测云.Testin云测试平台…….由于自己所在项目组就是做终端测试工具的,故抽空了解了下几种常见的 ...

  5. MySQL5.7(三)数据表操作

    概念在数据库中,数据表是数据库中最重要.最基本的操作对象,是数据存储的基本单位.数据表被定义为列的集合,数据在表中是按照行和列的格式来存储的.每一行代表一条唯一的记录,每一列代表记录中的一个域.1.创 ...

  6. SDRAM学习(二)之初始化

    目录 1.SDRAM初始化的内容(结合英文数据手册) 2.SDRAM初始化的时序 3.代码的编写 4.modesim的仿真 SDRAM初始化的内容 SDRAMs must be powered up ...

  7. startActivityForResult用法

    使用场景:A界面(activity) 可跳转到一个(假设为 B)或多个子Activity,要求B处理完工作之后返回A 界面,或许同时返回一些数据交给A继续处理.如 由登陆界面A跳转到注册界面B,注册成 ...

  8. getRequestURI,getRequestURL的区别,获取各种路径的方法

    getRequestURI,getRequestURL的区别 test1.jsp======================= <a href ="test.jsp?p=fuck&qu ...

  9. hdu 4258 斜率DP

    思路:dp[i]=dp[j]+(num[i]-num[j+1])^2; #include<iostream> #include<cstring> #include<alg ...

  10. 【WC2019笔记】IOI2018 / ACM题目选讲

    哇!济南的 rqy 大佬讲课!就是 $luogu$ 上有名的那位! 上面这句话写错了,请大家无视 XylophoneIOI2018 练习赛 T2题意:交互提有一个 $0\sim n-1$ 的排列,保证 ...