# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
871996 |
2023-11-12T06:02:27 Z |
vjudge1 |
Deda (COCI17_deda) |
C++17 |
|
180 ms |
65536 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define len(x) (int) x.size()
#define pb push_back
struct query {
char type;
int a, b;
};
const int N = 2e5 + 7;
map<int, int> mp;
set<int> seg[N << 2];
vector<query> qu;
vector<int> vec;
int n, q;
void read_input() {
cin >> n >> q;
for (int i = 0; i < q; i++) {
query t;
cin >> t.type >> t.a >> t.b;
vec.pb(t.a);
qu.pb(t);
}
}
void prepare() {
sort(all(vec));
vec.resize(unique(all(vec)) - vec.begin());
for (int i = 0; i < len(vec); i++)
mp[vec[i]] = i;
}
void upd(int p, int x, int id = 1, int st = 0, int en = len(vec)) {
seg[id].insert(x);
if (en - st == 1)
return;
int mid = (st + en) >> 1;
if (p < mid)
upd(p, x, id << 1, st, mid);
else
upd(p, x, id << 1 | 1, mid, en);
}
int get(int l, int r, int b, int id = 1, int st = 0, int en = len(vec)) {
if (r <= st || l >= en)
return INT_MAX;
if (st >= l && en <= r) {
if (seg[id].empty())
return INT_MAX;
if (*(--seg[id].end()) < b)
return INT_MAX;
return *seg[id].lower_bound(b);
}
int mid = (st + en) >> 1;
return min(get(l, r, b, id << 1, st, mid), get(l, r, b, id << 1 | 1, mid, en));
}
void solve() {
for (auto q: qu) {
char type;
int a, b;
type = q.type, a = q.a, b = q.b;
a = mp[a];
if (type == 'M') {
upd(a, b);
}
else {
//int t = get(0, a + 1, b);
int t = INT_MAX;
cout << (t == INT_MAX? -1: t) << '\n';
}
}
}
int32_t main() {
ios:: sync_with_stdio(0), cin.tie(0), cout.tie(0);
read_input(), prepare(), solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
37980 KB |
Output isn't correct |
2 |
Incorrect |
8 ms |
38096 KB |
Output isn't correct |
3 |
Incorrect |
11 ms |
38748 KB |
Output isn't correct |
4 |
Incorrect |
132 ms |
49552 KB |
Output isn't correct |
5 |
Runtime error |
166 ms |
65536 KB |
Execution killed with signal 9 |
6 |
Runtime error |
178 ms |
65536 KB |
Execution killed with signal 9 |
7 |
Runtime error |
180 ms |
65536 KB |
Execution killed with signal 9 |