# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
870159 | vjudge1 | Deda (COCI17_deda) | C++17 | 39 ms | 65536 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 <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;
#define f first
#define s second
#define mk make_pair
#define dg cout << "------------------" << endl
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
const int N = 1e6 + 7;
int Point[N], Ans, n, m;
pair<int, int> Ar[N];
ordered_set adj[N];
vector<int> node;
map<int, int> mp;
char Ml[N];
void update(int u, int w) {
if (u < 1) return;
adj[u].insert(w), update(u / 2, w);
}
void Segment(int u, int w, int ul, int ur) {
if (ul >= w) {
node.push_back(u);
return;
}
if (ur - ul <= 1 || w > ur - 1) return;
int mid = (ur + ul) / 2;
Segment(u * 2, w, ul, mid);
Segment(u * 2 + 1, w, mid, ur);
}
void solve1(int Check, int po) {
node.clear(), Ans = -1;
Segment(1, Ar[po].s, 1, (n + 1));
for (int i = 0; i < node.size(); i++) {
int l = adj[node[i]].order_of_key(Check + 1);
if (l > 0) {
Ans = mp[*adj[node[i]].find_by_order(l - 1)];
break;
}
}
cout << Ans << "\n";
}
void solve() {
for (int i = 1; i <= m; i++) {
if (Ml[i] == 'M') update(Point[Ar[i].s], Ar[i].f);
if (Ml[i] == 'D') solve1(Ar[i].f, i);
}
}
void build(int u, int ul, int ur) {
if (ur - ul <= 1) {
Point[ul] = u;
return;
}
int mid = (ur + ul) / 2;
build(u * 2, ul, mid);
build(u * 2 + 1, mid, ur);
}
void input() {
cin >> n >> m;
for (int i = 1; i <= m; i++)
cin >> Ml[i] >> Ar[i].f >> Ar[i].s, mp[Ar[i].f] = Ar[i].s;
}
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
input(), build(1, 1, (n + 1)), solve();
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |