Submission #630532

#TimeUsernameProblemLanguageResultExecution timeMemory
630532petykokusz79Deda (COCI17_deda)C++14
140 / 140
108 ms7888 KiB
#include <iostream> #include <algorithm> #include <vector> #define MAXV 1000000001 using namespace std; struct segtree { vector<int> minS; int size; segtree(int n) { size = n; minS.resize(4 * n, MAXV); } void set(int i, int v, int x, int lx, int rx) { if (lx + 1 == rx) { minS[x] = v; return; } int m = (lx + rx) / 2; if (i < m) { set(i, v, 2 * x + 1, lx, m); } else { set(i, v, 2 * x + 2, m, rx); } minS[x] = min(minS[2 * x + 1], minS[2 * x + 2]); } void set(int i, int v) { set(i, v, 0, 0, size); } int get(int l, int r, int v, int x, int lx, int rx) { if (rx <= l || r <= lx) { return -1; } if (minS[x] > v) { return -1; } if (lx + 1 == rx) { return lx + 1; } int m = (lx + rx) / 2, f = get(l, r, v, 2 * x + 1, lx, m); return f == -1 ? get(l, r, v, 2 * x + 2, m, rx) : f; } int get(int l, int v) { return get(l, size, v, 0, 0, size); } }; int main() { cin.sync_with_stdio(false); cin.tie(nullptr); int N, Q; cin >> N >> Q; segtree stS(N); while (Q--) { char speaker; int stop, child; cin >> speaker >> stop >> child; --child; if (speaker == 'M') { stS.set(child, stop); } else { cout << stS.get(child, stop) << '\n'; } } }
#Verdict Execution timeMemoryGrader output
Fetching results...