/*input
8 5
D 6 43
M 44 6
M 19 3
D 1 28
M 3 6
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;
vector<int> t;
int query(int v, int tl, int tr, int l, int r, int x)
{
if(tl > r || tr < l) return -2;
if(l <= tl && tr <= r)
{
if(t[v] > x) return -2;
while(tl != tr)
{
int tm = (tl + tr)/2;
if(t[2 * v] <= x)
{
v = 2 * v;
tr = tm;
}
else
{
v = 2 * v + 1;
tl = tm + 1;
}
}
return tl;
}
int tm = (tl + tr)/2;
int res = query(2 * v, tl, tm, l, r, x);
if(res != -2) return res;
return query(2 * v + 1, tm + 1, tr, l, r, x);
}
void update(int v, int tl, int tr, int pos, int x)
{
if(tl == tr) t[v] = x;
else
{
int tm = (tl + tr)/2;
if(pos <= tm) update(2 * v, tl, tm, pos, x);
else update(2 * v + 1, tm + 1, tr, pos, x);
t[v] = min(t[2 * v], t[2 * v + 1]);
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, q; cin >> n >> q;
t.resize(4 * n);
for(int i = 0; i < 4 * n; i++) t[i] = INF32;
while(q--)
{
char c; cin >> c;
if(c == 'D') //query
{
int y, b; cin >> y >> b;
b--;
cout << query(1, 0, n - 1, b, n - 1, y) + 1 << endl;
}
else //update
{
int x, a; cin >> x >> a;
a--;
update(1, 0, n - 1, a, x);
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
6 ms |
384 KB |
Output is correct |
3 |
Correct |
19 ms |
384 KB |
Output is correct |
4 |
Correct |
589 ms |
4608 KB |
Output is correct |
5 |
Correct |
404 ms |
2728 KB |
Output is correct |
6 |
Correct |
448 ms |
3636 KB |
Output is correct |
7 |
Correct |
446 ms |
4472 KB |
Output is correct |