# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
412906 | JerryLiu06 | Deda (COCI17_deda) | C++17 | 1091 ms | 8688 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;
using ll = long long;
using db = long double;
using str = string;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using pd = pair<db, db>;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<ll>;
using vd = vector<db>;
using vs = vector<str>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vpd = vector<pd>;
#define mp make_pair
#define f first
#define s second
#define sz(x) (int)(x).size()
#define bg(x) begin(x)
#define all(x) bg(x), end(x)
#define sor(x) sort(all(x))
#define ft front()
#define bk back()
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define R0F(i, a) ROF(i, 0, a)
#define EACH(a, x) for (auto& a : x)
const int MOD = 1e9 + 7;
const int MX = 2e5 + 10;
const ll INF = 1e18;
int N, Q, P[MX]; int tree[4 * MX];
void update(int x, int l, int r, int pos, int val) { int mid = (l + r) / 2;
if (l > pos || r < pos) return ; if (l == r) { tree[x] = val; return ; }
update(2 * x, l, mid, pos, val); update(2 * x + 1, mid + 1, r, pos, val);
tree[x] = min(tree[2 * x], tree[2 * x + 1]);
}
int query(int x, int l, int r, int tl, int tr) { int mid = (l + r) / 2;
if (l > tr || r < tl) return MOD; if (tl <= l && r <= tr) return tree[x];
return min(query(2 * x, l, mid, tl, tr), query(2 * x + 1, mid + 1, r, tl, tr));
}
int first(int tl, int tr, int val) { int mid = (tl + tr) / 2;
if (tl == tr) { if (P[tl] <= val) return tl; return -1; }
if (query(1, 1, N, tl, mid) <= val) return first(tl, mid, val);
if (query(1, 1, N, mid + 1, tr) <= val) return first(mid + 1, tr, val); return -1;
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> N >> Q; FOR(i, 1, 4 * MX) tree[i] = MOD;
F0R(i, Q) {
char C; int A, B; cin >> C >> A >> B;
if (C == 'M') update(1, 1, N, B, A), P[B] = A; else cout << first(B, N, A) << "\n";
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |