# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
798545 |
2023-07-30T20:15:26 Z |
HunterXD |
RMQ (NOI17_rmq) |
C++17 |
|
1 ms |
340 KB |
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
typedef vector<int> vl;
typedef vector<vl> vvl;
#define all(x) x.begin(), x.end()
#define pb push_back
#define f first
#define s second
const char nd = '\n';
const int infi = 1e9;
struct queries {
ll l, r, mini;
};
struct nodo {
ll l, r;
ll mini;
nodo *left, *right;
};
nodo *st;
void start(nodo *yo, vl &a) {
if (yo->l == yo->r) {
yo->mini = a[yo->l];
return;
}
ll mid = (yo->l + yo->r) / 2;
yo->left = new nodo({yo->l, mid, 0, NULL, NULL});
yo->right = new nodo({mid + 1, yo->r, 0, NULL, NULL});
start(yo->left, a);
start(yo->right, a);
yo->mini = min(yo->left->mini, yo->right->mini);
}
ll query(nodo *c, ll l, ll r) {
if (r < c->l || c->r < l) return infi;
if (l <= c->l && c->r <= r) return c->mini;
return min(query(c->left, l, r), query(c->right, l, r));
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, q;
cin >> n >> q;
vector<queries> que;
vector<pair<int, int> > state(n, make_pair(-1, -1));
vl res(n, -1);
ll l, r, mini;
while (q--) {
cin >> l >> r >> mini;
que.pb({l, r, mini});
if (state[mini].f == -1) {
state[mini] = make_pair(l, r);
} else {
state[mini].f = max(state[mini].f, l);
state[mini].s = min(state[mini].s, r);
}
}
set<ll> s;
for (ll i = 0; i < n; i++) s.insert(i);
set<ll>::iterator it;
for (ll i = n - 1; i >= 0; i--) {
if (state[i].f == -1) continue;
it = s.lower_bound(state[i].f);
if (state[i].f > state[i].s || it == s.end() || *it > state[i].s) {
for (auto v : res) cout << -1 << " ";
cout << nd;
return 0;
}
res[*it] = i;
do {
if (*it > state[i].s) break;
s.erase(it);
it = s.lower_bound(state[i].f);
} while (it != s.end());
}
for (ll i = 0; i < n; i++) s.insert(i);
for (auto v : res) {
if (v != -1) s.erase(v);
}
for (auto &v : res) {
if (v == -1) {
v = n - 1;
}
}
nodo *st = new nodo({0, n - 1, 0, NULL, NULL});
start(st, res);
for (auto v : que) {
if (query(st, v.l, v.r) != v.mini) {
for (auto v : res) cout << -1 << " ";
cout << nd;
return 0;
}
}
for (auto v : res) cout << v << " ";
cout << nd;
}
Compilation message
rmq.cpp: In function 'int main()':
rmq.cpp:85:17: warning: unused variable 'v' [-Wunused-variable]
85 | for (auto v : res) cout << -1 << " ";
| ^
rmq.cpp:116:17: warning: unused variable 'v' [-Wunused-variable]
116 | for (auto v : res) cout << -1 << " ";
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
1 ms |
212 KB |
Output is partially correct |
2 |
Partially correct |
1 ms |
320 KB |
Output is partially correct |
3 |
Partially correct |
1 ms |
212 KB |
Output is partially correct |
4 |
Partially correct |
1 ms |
212 KB |
Output is partially correct |
5 |
Partially correct |
0 ms |
212 KB |
Output is partially correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Partially correct |
1 ms |
212 KB |
Output is partially correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
1 ms |
212 KB |
Output is partially correct |
2 |
Partially correct |
1 ms |
320 KB |
Output is partially correct |
3 |
Partially correct |
1 ms |
212 KB |
Output is partially correct |
4 |
Partially correct |
1 ms |
212 KB |
Output is partially correct |
5 |
Partially correct |
0 ms |
212 KB |
Output is partially correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Partially correct |
1 ms |
212 KB |
Output is partially correct |
12 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
1 ms |
212 KB |
Output is partially correct |
2 |
Partially correct |
1 ms |
320 KB |
Output is partially correct |
3 |
Partially correct |
1 ms |
212 KB |
Output is partially correct |
4 |
Partially correct |
1 ms |
212 KB |
Output is partially correct |
5 |
Partially correct |
0 ms |
212 KB |
Output is partially correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Partially correct |
1 ms |
212 KB |
Output is partially correct |
12 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |