# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
218193 |
2020-04-01T12:05:33 Z |
quocnguyen1012 |
RMQ (NOI17_rmq) |
C++14 |
|
67 ms |
10104 KB |
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
const int maxn = 1e5 + 5;
vector<ii> vec[maxn];
int N, a[maxn], used[maxn], last, Q;
set<int> se;
void no_sol(void)
{
for(int i = 1; i <= N; ++i)
cout << -1 << ' ';
exit(0);
}
void add(int val, int l, int r, int L, int R)
{
auto it = se.lower_bound(l);
bool add = false;
while(it != se.end() && *it <= r){
if(L <= *it && *it <= R && !add){
used[val] = 1;
a[*it] = val;
add = 1;
}
else{
while(last >= 1 && used[last]) --last;
if(last <= val){
no_sol();
}
used[last] = 1;
a[*it] = last;
}
++it;
se.erase(prev(it));
}
if(!add) no_sol();
}
signed main(void)
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifdef LOCAL
freopen("A.INP", "r", stdin);
freopen("A.OUT", "w", stdout);
#endif // LOCAL
cin >> N >> Q; last = N;
while(Q--){
int l, r, v; cin >> l >> r >> v;
++l; ++r; ++v;
vec[v].eb(l, r);
}
for(int i = 1; i <= N; ++i)
se.insert(i);
for(int i = N; i >= 1; --i) if(vec[i].size()){
used[i] = true;
int lmax = 0, rmin = N, lmin = N, rmax = 0;
for(auto & it : vec[i]){
lmax = max(lmax, it.fi);
rmin = min(rmin, it.se);
lmin = min(lmin, it.fi);
rmax = max(rmax, it.se);
}
if(lmax > rmin){
no_sol();
}
add(i, lmin, rmax, lmax, rmin);
}
for(auto it : se){
while(last >= 1 && used[last]) --last;
if(last < 1) no_sol();
a[it] = last;
used[last] = 1;
}
for(int i = 1; i <= N; ++i)
cout << a[i] - 1 << ' ';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2688 KB |
Output is correct |
2 |
Correct |
6 ms |
2688 KB |
Output is correct |
3 |
Correct |
6 ms |
2688 KB |
Output is correct |
4 |
Correct |
6 ms |
2688 KB |
Output is correct |
5 |
Correct |
6 ms |
2688 KB |
Output is correct |
6 |
Correct |
6 ms |
2688 KB |
Output is correct |
7 |
Correct |
6 ms |
2688 KB |
Output is correct |
8 |
Correct |
6 ms |
2688 KB |
Output is correct |
9 |
Correct |
6 ms |
2688 KB |
Output is correct |
10 |
Correct |
6 ms |
2688 KB |
Output is correct |
11 |
Correct |
6 ms |
2688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2688 KB |
Output is correct |
2 |
Correct |
6 ms |
2688 KB |
Output is correct |
3 |
Correct |
6 ms |
2688 KB |
Output is correct |
4 |
Correct |
6 ms |
2688 KB |
Output is correct |
5 |
Correct |
6 ms |
2688 KB |
Output is correct |
6 |
Correct |
6 ms |
2688 KB |
Output is correct |
7 |
Correct |
6 ms |
2688 KB |
Output is correct |
8 |
Correct |
6 ms |
2688 KB |
Output is correct |
9 |
Correct |
6 ms |
2688 KB |
Output is correct |
10 |
Correct |
6 ms |
2688 KB |
Output is correct |
11 |
Correct |
6 ms |
2688 KB |
Output is correct |
12 |
Correct |
7 ms |
2816 KB |
Output is correct |
13 |
Correct |
6 ms |
2816 KB |
Output is correct |
14 |
Correct |
6 ms |
2688 KB |
Output is correct |
15 |
Correct |
6 ms |
2816 KB |
Output is correct |
16 |
Correct |
6 ms |
2816 KB |
Output is correct |
17 |
Correct |
6 ms |
2816 KB |
Output is correct |
18 |
Correct |
6 ms |
2688 KB |
Output is correct |
19 |
Correct |
6 ms |
2688 KB |
Output is correct |
20 |
Correct |
6 ms |
2688 KB |
Output is correct |
21 |
Correct |
6 ms |
2688 KB |
Output is correct |
22 |
Correct |
6 ms |
2688 KB |
Output is correct |
23 |
Correct |
6 ms |
2816 KB |
Output is correct |
24 |
Correct |
6 ms |
2816 KB |
Output is correct |
25 |
Correct |
6 ms |
2688 KB |
Output is correct |
26 |
Correct |
6 ms |
2688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2688 KB |
Output is correct |
2 |
Correct |
6 ms |
2688 KB |
Output is correct |
3 |
Correct |
6 ms |
2688 KB |
Output is correct |
4 |
Correct |
6 ms |
2688 KB |
Output is correct |
5 |
Correct |
6 ms |
2688 KB |
Output is correct |
6 |
Correct |
6 ms |
2688 KB |
Output is correct |
7 |
Correct |
6 ms |
2688 KB |
Output is correct |
8 |
Correct |
6 ms |
2688 KB |
Output is correct |
9 |
Correct |
6 ms |
2688 KB |
Output is correct |
10 |
Correct |
6 ms |
2688 KB |
Output is correct |
11 |
Correct |
6 ms |
2688 KB |
Output is correct |
12 |
Correct |
7 ms |
2816 KB |
Output is correct |
13 |
Correct |
6 ms |
2816 KB |
Output is correct |
14 |
Correct |
6 ms |
2688 KB |
Output is correct |
15 |
Correct |
6 ms |
2816 KB |
Output is correct |
16 |
Correct |
6 ms |
2816 KB |
Output is correct |
17 |
Correct |
6 ms |
2816 KB |
Output is correct |
18 |
Correct |
6 ms |
2688 KB |
Output is correct |
19 |
Correct |
6 ms |
2688 KB |
Output is correct |
20 |
Correct |
6 ms |
2688 KB |
Output is correct |
21 |
Correct |
6 ms |
2688 KB |
Output is correct |
22 |
Correct |
6 ms |
2688 KB |
Output is correct |
23 |
Correct |
6 ms |
2816 KB |
Output is correct |
24 |
Correct |
6 ms |
2816 KB |
Output is correct |
25 |
Correct |
6 ms |
2688 KB |
Output is correct |
26 |
Correct |
6 ms |
2688 KB |
Output is correct |
27 |
Correct |
60 ms |
9012 KB |
Output is correct |
28 |
Correct |
59 ms |
9360 KB |
Output is correct |
29 |
Correct |
53 ms |
8824 KB |
Output is correct |
30 |
Correct |
63 ms |
9836 KB |
Output is correct |
31 |
Correct |
51 ms |
8172 KB |
Output is correct |
32 |
Correct |
53 ms |
8176 KB |
Output is correct |
33 |
Correct |
35 ms |
7544 KB |
Output is correct |
34 |
Correct |
26 ms |
6016 KB |
Output is correct |
35 |
Correct |
42 ms |
8568 KB |
Output is correct |
36 |
Correct |
54 ms |
9464 KB |
Output is correct |
37 |
Correct |
67 ms |
10104 KB |
Output is correct |
38 |
Correct |
23 ms |
6016 KB |
Output is correct |
39 |
Correct |
58 ms |
8668 KB |
Output is correct |
40 |
Correct |
6 ms |
2688 KB |
Output is correct |
41 |
Correct |
7 ms |
2688 KB |
Output is correct |