Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int niza[1000];
- class node
- {
- public:
- int val;
- node *leftchild;
- node *rightchild;
- int leftbound;
- int rightbound;
- int mid;
- node (int lb, int rb)
- {
- leftbound=lb;
- rightbound=rb;
- if(lb==rb)
- val=niza[lb];
- else
- {
- mid=(lb+rb)/2;
- leftchild= new node(leftbound, mid);
- rightchild=new node( mid+1,rightbound);
- val= min(leftchild->val, rightchild->val);
- }
- }
- void pecati()
- {
- if(leftbound==rightbound)
- {
- cout<<val<<endl;
- return;
- }
- else
- {
- // cout<<leftbound<<" "<<rightbound<<" "<<val<<endl;
- leftchild->pecati();
- rightchild->pecati();
- }
- }
- int find_minimum(int l, int r)
- {
- //cout<<leftbound<<" "<<rightbound<<endl;
- if(l<=leftbound && rightbound<=r)
- return val;
- else if(l<=rightbound && r>=leftbound)
- {
- return min((leftchild->find_minimum(l, r)), (rightchild->find_minimum(l, r)));
- }
- else
- return (1<<30);
- }
- void update(int value, int position){
- if(leftbound==rightbound)
- val=value;
- else{
- if(position>mid)
- rightchild->update(position, value);
- else
- leftchild->update(position, value);
- val=min(leftchild->val, rightchild->val);
- }
- }
- };
- int main()
- {
- int n;
- cin>>n;
- for(int i=0; i<n; i++)
- {
- cin>>niza[i];
- }
- node *root=new node(0, n-1);
- int num_queries;
- cin>>num_queries;
- vector <pair<int, pair<int, int> > > queries;
- for(int i=0; i<num_queries; i++)
- {
- int a, b, c;
- cin>>a>>b>>c;
- queries.push_back(make_pair(a, make_pair(b, c)));
- if(a==0)
- cout<<root->find_minimum(b, c);
- if(a==1)
- root->update(b,c);
- }
- root->pecati();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement