# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
426737 |
2021-06-14T09:28:49 Z |
snasibov05 |
RMQ (NOI17_rmq) |
C++14 |
|
1000 ms |
515872 KB |
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define oo 1000000000
#define pb push_back
struct range{
int l, r;
int val;
bool operator<(range r1) const{
return val < r1.val;
}
};
int main() {
int n, q; cin >> n >> q;
vector<range> v(q);
for (int i = 0; i < q; ++i) {
cin >> v[i].l >> v[i].r >> v[i].val;
}
sort(v.rbegin(), v.rend());
vector<int> ans(n, -1);
vector<int> mn(n, -1);
vector<vector<int>> possible(n);
int k = 0;
bool flag = true;
for (int i = n-1; i >= 0; --i) {
int l = 0, r = n-1;
int x = n-1, y = 0;
while (k < q && v[k].val == i){
l = max(v[k].l, l); x = min(x, v[k].l);
r = min(v[k].r, r); y = max(y, v[k].r);
k++;
}
for (int j = x; j <= y; ++j) {
if (mn[j] == -1) mn[j] = i;
}
for (int j = l; j <= r; ++j){
if (mn[j] == i || mn[j] == -1) possible[i].pb(j);
}
if (possible[i].empty()) flag = false;
}
for (int i = 0; i < n && flag; ++i) {
int pos = -1;
for (int j = 0; j < possible[i].size(); ++j) {
if (ans[possible[i][j]] == -1) pos = possible[i][j];
}
ans[pos] = i;
}
for (auto x : ans) cout << x << " ";
return 0;
}
Compilation message
rmq.cpp: In function 'int main()':
rmq.cpp:57:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
57 | for (int j = 0; j < possible[i].size(); ++j) {
| ~~^~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
6 ms |
3148 KB |
Output is correct |
13 |
Correct |
7 ms |
3556 KB |
Output is correct |
14 |
Correct |
5 ms |
2636 KB |
Output is correct |
15 |
Correct |
8 ms |
3996 KB |
Output is correct |
16 |
Correct |
8 ms |
4072 KB |
Output is correct |
17 |
Correct |
10 ms |
4172 KB |
Output is correct |
18 |
Correct |
7 ms |
3788 KB |
Output is correct |
19 |
Correct |
8 ms |
3656 KB |
Output is correct |
20 |
Correct |
4 ms |
2508 KB |
Output is correct |
21 |
Correct |
2 ms |
332 KB |
Output is correct |
22 |
Correct |
3 ms |
332 KB |
Output is correct |
23 |
Correct |
6 ms |
3020 KB |
Output is correct |
24 |
Correct |
6 ms |
3020 KB |
Output is correct |
25 |
Correct |
1 ms |
204 KB |
Output is correct |
26 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
6 ms |
3148 KB |
Output is correct |
13 |
Correct |
7 ms |
3556 KB |
Output is correct |
14 |
Correct |
5 ms |
2636 KB |
Output is correct |
15 |
Correct |
8 ms |
3996 KB |
Output is correct |
16 |
Correct |
8 ms |
4072 KB |
Output is correct |
17 |
Correct |
10 ms |
4172 KB |
Output is correct |
18 |
Correct |
7 ms |
3788 KB |
Output is correct |
19 |
Correct |
8 ms |
3656 KB |
Output is correct |
20 |
Correct |
4 ms |
2508 KB |
Output is correct |
21 |
Correct |
2 ms |
332 KB |
Output is correct |
22 |
Correct |
3 ms |
332 KB |
Output is correct |
23 |
Correct |
6 ms |
3020 KB |
Output is correct |
24 |
Correct |
6 ms |
3020 KB |
Output is correct |
25 |
Correct |
1 ms |
204 KB |
Output is correct |
26 |
Correct |
1 ms |
204 KB |
Output is correct |
27 |
Execution timed out |
1119 ms |
515872 KB |
Time limit exceeded |
28 |
Halted |
0 ms |
0 KB |
- |