# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
162035 | DifferentHeaven | Deda (COCI17_deda) | C++17 | 732 ms | 9592 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 <bits/stdc++.h>
#define ii pair <int, int>
#define x first
#define y second
#define db(x) cerr << #x << " = " << x << endl;
#define _ << " _ " <<
using namespace std;
const int N = 2e5 + 7;
const int oo = 1e9 + 7;
int n, m;
struct segTree{
int tree[N << 3];
segTree() {
for (int i = 0; i < (N << 3); i++)
tree[i] = oo;
}
void Update(int x, int l, int r, int i, int j, int val){
if (l > j || r < i) return;
if (l >= i && r <= j){
tree[x] = val;
return;
}
int mid = l + r >> 1;
Update(2 * x, l, mid, i, j, val);
Update(2 * x + 1, mid + 1, r, i, j, val);
tree[x] = min(tree[2 * x], tree[2 * x + 1]);
}
int Find(int x, int l, int r, int i, int j, int val){
if (l > j || r < i) return -1;
if (l >= i && r <= j){
while (l < r){
int mid = l + r >> 1;
if (tree[2 * x] <= val){
r = mid;
x = 2 * x;
}
else{
l = mid + 1;
x = 2 * x + 1;
}
}
if (tree[x] <= val) return r;
return -1;
}
int mid = l + r >> 1;
int L = Find(2 * x, l, mid, i, j, val);
if (L != -1) return L;
int R = Find(2 * x + 1, mid + 1, r, i, j, val);
return R;
}
}IT;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
if(fopen("test.inp", "r")) freopen("test.inp", "r", stdin), freopen("test.out", "w", stdout);
cin >> n >> m;
for (int i = 1; i <= m; i++){
char ch;
int x, y;
cin >> ch >> x >> y;
if (ch == 'M'){
IT.Update(1, 1, n, y, y, x);
}
else{
cout << IT.Find(1, 1, n, y, n, x) << endl;
}
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |