# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
475655 | Alex_tz307 | Deda (COCI17_deda) | C++17 | 214 ms | 4312 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
struct SegTree {
int Size;
vector<int> tree;
SegTree(int n) {
Size = 1;
while (Size < n) {
Size <<= 1;
}
tree.resize(Size << 1, INF);
}
void update(int x, int lx, int rx, int pos, int val) {
if (lx == rx) {
tree[x] = val;
cout << lx << ' ' << pos << ' ' << val << endl;
return;
}
int mid = (lx + rx) >> 1, lSon = x << 1, rSon = x << 1 | 1;
if (pos <= mid) {
update(lSon, lx, mid, pos, val);
} else {
update(rSon, mid + 1, rx, pos, val);
}
tree[x] = min(tree[lSon], tree[rSon]);
}
int query(int x, int lx, int rx, int pos, int val) {
if (rx < pos) {
return -1;
}
if (tree[x] > val) {
return -1;
}
if (lx == rx) {
if (tree[x] <= val) {
return lx;
}
return -1;
}
int mid = (lx + rx) >> 1, ans = -1;
ans = query(x << 1, lx, mid, pos, val);
if (ans == -1) {
return query(x << 1 | 1, mid + 1, rx, pos, val);
}
return ans;
}
};
void test_case() {
int n, q;
cin >> n >> q;
SegTree tree(n);
for (int i = 1; i <= q; ++i) {
char op;
int x, pos;
cin >> op >> x >> pos;
if (op == 'M') {
tree.update(1, 1, n, pos, x);
} else {
cout << tree.query(1, 1, n, pos, x) << '\n';
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int T = 1;
for (int tc = 1; tc <= T; ++tc) {
test_case();
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |