赞
踩
5 1 2 3 4 5 7 1 1 5 0 1 3 6 1 1 4 1 2 3 0 2 2 0 1 1 2 1 3 5
1 4 6 0 4
迟到了五分钟才做了。。感觉做的是对的。虽然没能提交上。
找了一天了。。TM我终于找到怎么做了。。上午的时候其实就知道怎么更新区间了,只不过一个地方写错了
导致结果不对 就放弃了。。
今天下午尝试了那么多。。o(︶︿︶)o 唉 刚刚发现上午写的是对的。
- <pre name="code" class="cpp">#include <stdio.h>
- #include <string.h>
- #include <algorithm>
- using namespace std;
- int num[100005];
- struct node
- {
- int left,right,val;
- }c[100005*4];
- void build_tree(int l,int r,int root)
- {
- c[root].left=l;
- c[root].right=r;
- if(l==r)
- {
- c[root].val=num[l];
- return ;
- }
- int mid=(l+r)/2;
- build_tree(l,mid,root*2);
- build_tree(mid+1,r,root*2+1);
- c[root].val=min(c[root*2].val,c[root*2+1].val);
- }
- void find_tree(int l,int r,int &min1,int root)
- {
- if(c[root].left==l&&c[root].right==r)
- {
- min1=c[root].val;
- return ;
- }
- int mid=(c[root].left+c[root].right)/2;
- if(mid<l)
- find_tree(l,r,min1,root*2+1);
- else if(mid>=r)
- find_tree(l,r,min1,root*2);
- else
- {
- int min2;
- find_tree(l,mid,min1,root*2);
- find_tree(mid+1,r,min2,root*2+1);
- min1=min(min1,min2);
- }
-
- }
- void update_tree(int l,int r,int x,int root)
- {
- if(c[root].left==c[root].right)
- {
- c[root].val=x;
- return ;
- }
- int mid=(c[root].left+c[root].right)/2;
- if(mid<l)
- update_tree(l,r,x,root*2+1);
- else if(mid>=r)
- update_tree(l,r,x,root*2);
- else
- {
- update_tree(l,mid,x,root*2);
- update_tree(mid+1,r,x,root*2+1);
- }
- c[root].val=min(c[root*2].val,c[root*2+1].val);
- }
- int main()
- {
- int n,k;
- while(scanf("%d",&n)!=EOF)
- {
- for(int i=1;i<=n;i++)
- scanf("%d",&num[i]);
- build_tree(1,n,1);
- scanf("%d",&k);
- while(k--)
- {
- int a,b,min1,flag;
- scanf("%d",&flag);
- if(flag)
- {
- scanf("%d %d",&a,&b);
- find_tree(a,b,min1,1);
- printf("%d\n",min1);
- }
- else
- {
- int x;
- scanf("%d %d %d",&a,&b,&x);
- update_tree(a,b,x,1);
- //for(int i=1;i<=9;i++)
- //printf("[%d %d] %d\n",c[i].left,c[i].right,c[i].val);//自己测试的。。
- }
- }
- }
- return 0;
- }

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。