# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
630532 | petykokusz79 | Deda (COCI17_deda) | C++14 | 108 ms | 7888 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |