Submission #82875

# Submission time Handle Problem Language Result Execution time Memory
82875 2018-11-02T09:50:22 Z Milki Deda (COCI17_deda) C++14
140 / 140
228 ms 17136 KB
#include <bits/stdc++.h>
using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<
#define sz(x) (int)x.size()
#define pb(x) push_back(x)

typedef long long ll;
typedef pair<int, int> point;

const int INF = 1e9 + 5, MAXN = 2e5 + 5, off = 1 << 18;

struct Tournament{
    int t[2 * off];

    Tournament(){ REP(i, 2 * off) t[i] = INF;}

    void update(int x, int lo, int hi, int a, int b, int val){
        if(lo >= b || hi <= a) return;
        if(lo >= a && hi <= b) { t[x] = val; return; }

        int mid = (lo + hi) >> 1;
        update(x * 2, lo, mid, a, b, val);
        update(x * 2 + 1, mid, hi, a, b, val);
        t[x] = min(t[x * 2], t[x * 2 + 1]);
    }

    int get(int x, int lo, int hi, int a, int b, int threshold){
        if(lo >= b || hi <= a) return INF;
        if(lo >= a && hi <= b){
            int mid = (lo + hi) >> 1;
            if(x >= off) return t[x] <= threshold ? x - off : INF;
            else if(t[x * 2] <= threshold) return get(x * 2, lo, mid, a, b, threshold);
            else if(t[x * 2 + 1] <= threshold) return get(x * 2 + 1, mid, hi, a, b, threshold);
            else return INF;
        }

        int mid = (lo + hi) >> 1;
        int X = get(x * 2, lo, mid, a, b, threshold);
        int Y = get(x * 2 + 1, mid, hi, a, b, threshold);
        return min(X, Y);
    }
}T;

int n, q;

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0);

    cin >> n >> q;
    REP(i, q){
        char c; int a, b;
        cin >> c >> a >> b;
        if(c == 'M'){
            T.update(1, 0, off, b, b + 1, a);
        }
        else{
            int val = T.get(1, 0, off, b, off, a);
            if(val == INF) cout << -1 << "\n";
            else cout << val << "\n";
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2424 KB Output is correct
2 Correct 5 ms 2560 KB Output is correct
3 Correct 6 ms 2692 KB Output is correct
4 Correct 182 ms 7048 KB Output is correct
5 Correct 193 ms 10132 KB Output is correct
6 Correct 228 ms 13556 KB Output is correct
7 Correct 214 ms 17136 KB Output is correct