Interval Minimum (2) (segment Tree update interval) 2015 JXNU_ACS algorithm group the first week of the summer

Source: Internet
Author: User

Interval min (2) Time limit:3000/1000ms (java/other) Memory limit:65535/32768k (Java/other) total submission (s): Accepte D Submission (s): 9Font:Times New Roman|Verdana|GeorgiaFont Size:←→Problem description Given a sequence of numbers and some operations, the minimum value of a number in any given interval is queried. Input inputs contain multiple sets of test data, up to 5 groups.
The input contains multiple sets of test cases, each set of test cases beginning with an integer n (1<=n<=100000), representing the length of the number sequence.
The next line gives an n number, which represents a sequence of numbers. The number is within the INT range.
The next behavior is an integer t (1<=t<=10000) that represents the number of operations.
The last T line, each row gives an operation, 1 L r represents the minimum value of the query interval [l,r], 0 L r C represents the value of the interval [l R] replaced by all C (1<=l<=r<=n), C in the shaping range. Output for each query, the minimum value within the range [L,r]. Sample Input
51 2 3 4 571 1 50 1 3 61 1 41 2 30 2 2 01 1 21 3 5
Sample Output
14604
Author Wu Yu Statistic | Submit | Back

I was five minutes late to do it. The feeling is doing the right thing. Although not able to submit on.

Looking for a day. TM I finally found out what to do. In the morning when you actually know how to update the interval, but a place to write the wrong

Cause the result is wrong to give up.

I tried so much this afternoon. O (︶^︶) o Alas just found that the morning was right.

#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);p rintf ("%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);//Test yourself. }}}return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Interval Minimum (2) (segment Tree update interval) 2015 JXNU_ACS algorithm group the first week of the summer

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.