Created
May 7, 2014 15:04
-
-
Save Rag0n/a547c1f195d842d97154 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include<iostream> | |
| #include<algorithm> | |
| using namespace std; | |
| #include<string.h> | |
| #include<math.h> | |
| #define inf 0x7fffffff | |
| int arr[200000]; | |
| int tree[800000]; | |
| int lazy[800000]; | |
| int StrCompare(char *Str1,char *Str2) | |
| { | |
| while(*Str1==*Str2 && *Str1!=0) | |
| { | |
| Str1++; | |
| Str2++; | |
| } | |
| return *Str1-*Str2; | |
| } | |
| void build_tree(int node, int a, int b) { | |
| if(a > b) return; | |
| if(a == b) { | |
| tree[node] = arr[a]; | |
| return; | |
| } | |
| build_tree(node*2, a, (a+b)/2); | |
| build_tree(node*2+1, 1+(a+b)/2, b); | |
| tree[node] = min(tree[node*2], tree[node*2+1]); | |
| } | |
| void update_tree(int node, int a, int b, int i, int j, int value) { | |
| if(lazy[node] != 0) { | |
| tree[node] += lazy[node]; | |
| if(a != b) { | |
| lazy[node*2] += lazy[node]; | |
| lazy[node*2+1] += lazy[node]; | |
| } | |
| lazy[node] = 0; | |
| } | |
| if(a > b || a > j || b < i) | |
| return; | |
| if(a >= i && b <= j) { | |
| tree[node] = value; | |
| if(a != b) { | |
| lazy[node*2] = value; | |
| lazy[node*2+1] = value; | |
| } | |
| return; | |
| } | |
| update_tree(node*2, a, (a+b)/2, i, j, value); | |
| update_tree(1+node*2, 1+(a+b)/2, b, i, j, value); | |
| tree[node] = min(tree[node*2], tree[node*2+1]); | |
| } | |
| int query_tree(int node, int a, int b, int i, int j) { | |
| if(a > b || a > j || b < i) return inf; | |
| if(lazy[node] != 0) { | |
| tree[node] += lazy[node]; | |
| if(a != b) { | |
| lazy[node*2] += lazy[node]; | |
| lazy[node*2+1] += lazy[node]; | |
| } | |
| lazy[node] = 0; | |
| } | |
| if(a >= i && b <= j) | |
| return tree[node]; | |
| int q1 = query_tree(node*2, a, (a+b)/2, i, j); | |
| int q2 = query_tree(1+node*2, 1+(a+b)/2, b, i, j); | |
| int res = min(q1, q2); | |
| return res; | |
| } | |
| int main() { | |
| int k,m,i; | |
| char input[4]; | |
| char Min1[]="Min"; | |
| char Set1[]="Set"; | |
| int buf1,buf2; | |
| unsigned long int a[200000],buf3; | |
| std::cin>>k>>m; | |
| for(i=0;i<k;i++) | |
| std::cin>>arr[i]; | |
| build_tree(1, 0, k-1); | |
| memset(lazy, 0, sizeof lazy);; | |
| for(i=0;i<m;i++) | |
| { | |
| std::cin>>input; | |
| if(StrCompare(input,Set1)==0) | |
| { | |
| std::cin>>buf1>>buf3; | |
| update_tree(1, 0, k-1, buf1-1, buf1-1, buf3); | |
| } | |
| if(StrCompare(input,Min1)==0) | |
| { | |
| std::cin>>buf1>>buf2; | |
| std::cout<<query_tree(1, 0, k-1, buf1-1, buf2-1)<<"\n"; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment