# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
200900 | SamAnd | Deda (COCI17_deda) | C++17 | 496 ms | 65540 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>
using namespace std;
const int N = 200005, INF = 1000000009;
struct ban
{
char ty;
int x, a;
};
int n, q;
ban b[N];
set<int> t[N * 4];
void ubd(int tl, int tr, int x, int y, int pos)
{
t[pos].insert(y);
if (tl == tr)
return;
int m = (tl + tr) / 2;
if (x <= m)
ubd(tl, m, x, y, pos * 2);
else
ubd(m + 1, tr, x, y, pos * 2 + 1);
}
int qry(int tl, int tr, int l, int r, int y, int pos)
{
if (l > r)
return INF;
if (tl == l && tr == r)
{
set<int>::iterator it = t[pos].lower_bound(y);
if (it != t[pos].end())
return (*it);
return INF;
}
int m = (tl + tr) / 2;
return min(qry(tl, m, l, min(m, r), y, pos * 2),
qry(m + 1, tr, max(m + 1, l), r, y, pos * 2 + 1));
}
int main()
{
scanf("%d%d", &n, &q);
for (int i = 1; i <= q; ++i)
{
scanf(" %c%d%d", &b[i].ty, &b[i].x, &b[i].a);
}
int z = 0;
vector<int> v;
map<int, int> mp;
for (int i = 1; i <= q; ++i)
v.push_back(b[i].x);
sort(v.begin(), v.end());
for (int i = 0; i < v.size(); ++i)
{
if (!i || v[i] != v[i - 1])
mp[v[i]] = ++z;
}
for (int i = 1; i <= q; ++i)
{
b[i].x = mp[b[i].x];
}
for (int i = 1; i <= q; ++i)
{
if (b[i].ty == 'M')
{
ubd(1, z, b[i].x, b[i].a, 1);
}
else
{
int ans = qry(1, z, 1, b[i].x, b[i].a, 1);
if (ans == INF)
printf("-1\n");
else
printf("%d\n", ans);
}
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |