# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
200901 | SamAnd | Deda (COCI17_deda) | C++17 | 861 ms | 52200 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];
int z;
vector<int> v;
map<int, int> mp;
set<int> t[N];
void ubd(int x, int y)
{
while (x <= z)
{
t[x].insert(y);
x += (x & (-x));
}
}
int qry(int x, int y)
{
int ans = INF;
set<int>::iterator it;
while (x)
{
it = t[x].lower_bound(y);
if (it != t[x].end())
ans = min(ans, (*it));
x -= (x & (-x));
}
return ans;
}
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);
}
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(b[i].x, b[i].a);
}
else
{
int ans = qry(b[i].x, b[i].a);
if (ans == INF)
printf("-1\n");
else
printf("%d\n", ans);
}
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |