Submission #876607

#TimeUsernameProblemLanguageResultExecution timeMemory
876607vjudge1Deda (COCI17_deda)C++17
140 / 140
747 ms4640 KiB
#include <bits/stdc++.h> using namespace std; #define TOF_io ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0) #define file_io freopen("input.txt","r",stdin);freopen("output.txt","w",stdout); #define pb push_back #define Mp make_pair #define F first #define S second #define all(x) (x).begin(), (x).end() #define SZ(x) (int) (x).size() typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<long long, long long> pll; typedef unsigned long long int ull; const long long inf = 2147483647, INF = 1e18; const int md = 1e9 + 7; const int lg = 30 + 2; const int sq = 320; const int N = 200 * 1000 + 5; const int MAXN = 1000 * 1000 + 5; int n; int q; int seg[N << 2]; void upd(int id, int s, int e, int l, int r, int x) { if (r <= s || e <= l) return; if (l <= s && e <= r) { seg[id] = x; return; } int mid = (s + e) / 2; upd(2 * id, s, mid, l, r, x); upd(2 * id + 1, mid, e, l, r, x); seg[id] = min(seg[2 * id], seg[2 * id + 1]); } int get(int id, int s, int e, int l, int r) { if (r <= s || e <= l) return inf; if (l <= s && e <= r) return seg[id]; int mid = (s + e) / 2; return min(get(2 * id, s, mid, l, r), get(2 * id + 1, mid, e, l, r)); } int main() { TOF_io; cin >> n >> q; fill(seg, seg + (N << 2), inf); for (int i = 0, x, a; i < q; i ++) { char c; cin >> c; cin >> x >> a; if (c == 'M') { upd(1, 0, n, a - 1, a, x); } else { int l = a - 1, r = n; while (r - l > 1) { int mid = (l + r) / 2; if (get(1, 0, n, l, mid) < x + 1) r = mid; else l = mid; } if (get(1, 0, n, l, l + 1) > x) cout << -1 << '\n'; else cout << l + 1 << '\n'; } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...