# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
545394 |
2022-04-04T12:27:13 Z |
noedit |
Deda (COCI17_deda) |
C++17 |
|
148 ms |
3416 KB |
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx")
using namespace std;
using namespace __gnu_pbds;
typedef long double ld;
template <class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
//#define int long long
typedef long long ll;
const int MAXN = 2e5;
const int INF = 2e9;
int t[4 * MAXN];
void build(int v, int tl, int tr)
{
if (tl == tr)
{
t[v] = INF;
}
else
{
int tm = (tl + tr) >> 1;
build(v * 2, tl, tm);
build(v * 2 + 1, tm + 1, tr);
t[v] = min(t[v * 2], t[v * 2 + 1]);
}
}
void update(int v, int tl, int tr, int p, int x)
{
if (tl == tr)
{
t[v] = x;
return;
}
int tm = (tl + tr) >> 1;
if (p <= tm)
update(v * 2, tl, tm, p, x);
else
update(v * 2 + 1, tm + 1, tr, p, x);
t[v] = min(t[v * 2], t[v * 2 + 1]);
}
int get(int v, int tl, int tr, int y)
{
if (tl == tr)
{
if (t[v] <= y)
return tl;
else
return INF;
}
int tm = (tl + tr) >> 1;
if (t[v * 2] <= y)
return get(v * 2, tl, tm, y);
else
if (t[v * 2 + 1] <= y)
return get(v * 2 + 1, tm + 1, tr, y);
return INF;
}
int get(int v, int tl, int tr, int l, int r, int y)
{
if (l > r || l < tl || tr < r) return INF;
if (tl == l && tr == r)
{
return get(v, tl, tr, y);
}
int tm = (tl + tr) >> 1;
int ql = get(v * 2, tl, tm, l, min(r, tm), y);
int qr = get(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, y);
return min(ql, qr);
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, q;
cin >> n >> q;
build(1, 0, n - 1);
while (q--)
{
char c;
cin >> c;
if (c == 'M')
{
int x, a;
cin >> x >> a;
a--;
update(1, 0, n - 1, a, x);
}
else
{
int y, b;
cin >> y >> b;
b--;
int ans = get(1, 0, n - 1, b, n - 1, y);
if (ans == INF)
cout << -1 << '\n';
else
cout << ans + 1 << '\n';
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
3 ms |
340 KB |
Output is correct |
4 |
Correct |
135 ms |
3416 KB |
Output is correct |
5 |
Correct |
121 ms |
2048 KB |
Output is correct |
6 |
Correct |
143 ms |
3276 KB |
Output is correct |
7 |
Correct |
148 ms |
3412 KB |
Output is correct |