Submission #1342860

#TimeUsernameProblemLanguageResultExecution timeMemory
1342860AblablaDeda (COCI17_deda)C++20
140 / 140
273 ms3412 KiB
#include <bits/stdc++.h>
using namespace std;

const int INF = 1e9 + 7;

struct segTree{
    int meret = 1;
    vector<int> fa;

    void inic(int n){
        while(meret < n){
            meret *= 2;
        }

        fa.assign(2*meret-1, INF);
    }

    int valt(int a, int b, int ind, int hely, int ert){
        if(hely < a || b < hely){
            return fa[ind];
        } else if(a == b){
            return fa[ind] = ert;
        }

        int k = (a + b) / 2;

        return fa[ind] = min(valt(a, k, 2*ind + 1, hely, ert), valt(k+1, b, 2*ind + 2, hely, ert));
    }

    int keres(int a, int b, int ind, int l, int ert){
        if(b < l){
            return -1;
        } else if(fa[ind] > ert){
            return -1;
        } else if(a == b){
            return a;
        }

        int k = (a+b) / 2;

        int egy = keres(a, k, 2*ind + 1, l, ert);

        if(egy != -1){
            return egy;
        }

        return keres(k + 1, b, 2*ind + 2, l, ert);
    }
};

int main() {
    int n, m;
    cin >> n >> m;

    segTree fa;
    fa.inic(n);

    while(m--){
        char a; int b, c;
        cin >> a >> b >> c;

        if(a == 'M'){
            c--;
            fa.valt(0, fa.meret - 1, 0, c, b);
        } else{
            c--;
            int egy = fa.keres(0, fa.meret - 1, 0, c, b);
            cout << egy + (egy != -1) << "\n";
        }
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...