#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define all(x) begin(x), end(x)
#define x first
#define y second
typedef long long ll;
typedef long double ld;
template<typename T>
using ordered_set_ = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T>
using normal_queue = priority_queue<T, vector<T>, greater<T>>;
const int MAX_TREE = 1 << 19, MAX_N = 1 << 18, INF = 0x3f3f3f3f;
int tre[MAX_TREE];
void build() {
fill(tre, tre + MAX_TREE, +INF);
}
void set_(int i, int x) {
i += MAX_N;
tre[i] = x;
i /= 2;
while (i) {
tre[i] = min(tre[2 * i], tre[2 * i + 1]);
i /= 2;
}
}
int get(int l, int r) {
l += MAX_N;
r += MAX_N;
int res = +INF;
while (l <= r) {
if (l & 1) res = min(res, tre[l]);
if (!(r & 1)) res = min(res, tre[r]);
l = (l + 1) / 2;
r = (r - 1) / 2;
}
return res;
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
build();
for (int i = 0; i < m; ++i) {
char type;
cin >> type;
if (type == 'M') {
int x, a;
cin >> x >> a;
--a;
set_(a, x);
} else {
int y, b;
cin >> y >> b;
--b;
int lef = b - 1, rig = n;
while (rig - lef > 1) {
int mid = (lef + rig) / 2;
if (get(b, mid) <= y)
rig = mid;
else
lef = mid;
}
if (rig == n)
cout << "-1\n";
else
cout << rig + 1 << "\n";
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2432 KB |
Output is correct |
2 |
Correct |
7 ms |
2432 KB |
Output is correct |
3 |
Correct |
9 ms |
2432 KB |
Output is correct |
4 |
Correct |
494 ms |
6904 KB |
Output is correct |
5 |
Correct |
262 ms |
6392 KB |
Output is correct |
6 |
Correct |
308 ms |
6776 KB |
Output is correct |
7 |
Correct |
358 ms |
6924 KB |
Output is correct |