# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
642104 |
2022-09-18T13:29:21 Z |
vovamr |
Deda (COCI17_deda) |
C++17 |
|
202 ms |
17308 KB |
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fi first
#define se second
#define ll long long
#define ld long double
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mpp make_pair
#define ve vector
using namespace std;
using namespace __gnu_pbds;
template<class T> using oset = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
const ll inf = 1e18; const int iinf = 1e9;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T> inline bool chmin(T& a, T b) { return (a > b ? a = b, 1 : 0); }
template <typename T> inline bool chmax(T& a, T b) { return (a < b ? a = b, 1 : 0); }
const int N = 2e5 + 10;
int t[4 * N];
inline void upd(int v, int vl, int vr, int pos, int x) {
chmin(t[v], x);
if (vl == vr) return;
int m = vl + vr >> 1;
if (pos <= m) upd(2 * v + 1, vl, m, pos, x);
else upd(2 * v + 2, m + 1, vr, pos, x);
}
inline int get(int v, int vl, int vr, int sf, int x) {
if (sf > vr || t[v] > x) return iinf;
else if (vl == vr) return vl;
int m = vl + vr >> 1;
if (sf > m) return get(2 * v + 2, m + 1, vr, sf, x);
else {
int a = get(2 * v + 1, vl, m, sf, x);
if (a != iinf) return a;
return get(2 * v + 2, m + 1, vr, sf, x);
}
}
inline void solve() {
fill(t, t + 4 * N, iinf);
int n, q;
cin >> n >> q;
set<int> alive;
for (int i = 1; i <= n; ++i) alive.insert(i);
while (q--) {
char c;
cin >> c;
if (c == 'M') {
int x, a;
cin >> x >> a;
alive.erase(a);
upd(0, 1, n, a, x);
}
else {
int b, y;
cin >> y >> b;
int ans = get(0, 1, n, b, y);
cout << (ans == iinf ? -1 : ans) << '\n';
}
}
}
signed main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int q = 1; // cin >> q;
while (q--) solve();
cerr << fixed << setprecision(3) << "Time execution: " << (double)clock() / CLOCKS_PER_SEC << endl;
}
Compilation message
deda.cpp: In function 'void upd(int, int, int, int, int)':
deda.cpp:29:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
29 | int m = vl + vr >> 1;
| ~~~^~~~
deda.cpp: In function 'int get(int, int, int, int, int)':
deda.cpp:38:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
38 | int m = vl + vr >> 1;
| ~~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3412 KB |
Output is correct |
2 |
Correct |
2 ms |
3412 KB |
Output is correct |
3 |
Correct |
4 ms |
3452 KB |
Output is correct |
4 |
Correct |
114 ms |
17308 KB |
Output is correct |
5 |
Correct |
127 ms |
12068 KB |
Output is correct |
6 |
Correct |
142 ms |
14756 KB |
Output is correct |
7 |
Correct |
202 ms |
17228 KB |
Output is correct |