Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //http://bkdnoj.dut.udn.vn/public/practice_problem.php?id=IT1
- #include<bits/stdc++.h>
- using namespace std;
- #define FOR(i,a,b) for(int i=a;i<=b;++i)
- #define FOD(i,a,b) for(int i=a;i>=b;--i)
- #define FRSZ(i, a) for(int i = 0 ; i < a.size() ; ++i)
- #define FDSZ(i, a) for(int i = a.size() - 1 ; i >= 0 ; --i)
- #define debug(x) cout << #x << " = " << x << endl;
- #define debugvi(x) {FRSZ(_, x) cout << x[_] << " "; cout << endl;}
- #define debugarr(x, n) {FOR(_, 1, n) cout << x[_] << " "; cout << endl;}
- #define fi first
- #define se second
- #define pb push_back
- #define ll long long
- #define ull long long
- typedef pair<int, int> ii;
- const int MAX = 4*100000;
- const int INF = 0x3f3f3f3f;
- ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
- ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
- ll power(ll a, ll b, ll ret = 1LL) {
- while (b--) ret = (ret * a);
- return ret;
- }
- ll sqr(int a){return (ll)(a*a);}
- int st[MAX], arr[MAX], n, q;
- void build(int id, int l, int r)
- {
- if (l==r)
- {
- st[id]=arr[l];
- return;
- }
- int mid=(l+r)/2;
- build(2*id,l,mid);
- build(2*id+1,mid+1,r);
- st[id] = min(st[2*id],st[2*id+1]);
- }
- int get(int id, int l, int r, int s, int e)
- {
- if (s<=l && e>=r) return st[id];
- else if (e<l || s>r) return INT_MAX;
- else
- {
- int mid=(l+r)/2;
- return min(get(2*id,l,mid,s,e),get(2*id+1,mid+1,r,s,e));
- }
- }
- void update(int id, int s, int e, int index, int val)
- {
- if (s==e)
- {
- arr[index]=val;
- st[id]=min(st[id],val);
- }
- else
- {
- int mid=(s+e)/2;
- if (s<=index && index<=mid) update(id*2,s,mid,index,val);
- else update(2*id+1,mid+1,e,index,val);
- st[id]=min(st[2*id],st[2*id+1]);
- }
- }
- int main()
- {
- ios::sync_with_stdio(false);
- cin.tie(NULL);cout.tie(NULL);
- freopen("data.inp","r",stdin);
- freopen("data.out","w",stdout);
- memset(st,INT_MAX,sizeof(st));
- cin>>n>>q;
- FOR(i,1,n) cin>>arr[i];
- build(1,1,n);
- while(q--)
- {
- char type;cin>>type;
- if (type=='u')
- {
- int index, val;cin>>index>>val;
- update(1,1,n,index,val);
- }
- else
- if (type=='q')
- {
- int left, right;
- cin>>left>>right;
- cout<<get(1,1,n,left,right)<<"\n";
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement