# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
515859 |
2022-01-20T02:29:56 Z |
Joo |
RMQ (NOI17_rmq) |
C++17 |
|
71 ms |
11648 KB |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+10;
int n, Q, Li[N], Lu[N], Ri[N], Ru[N], ans[N];
set<int> rem_pos, rem_val;
void ex(){
for(int i = 0; i < n; i++) cout << "-1 ";
exit(0);
}
int main(void){
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> Q;
for(int i = 0; i < n; i++){
Li[i] = Ru[i] = -1e9;
Lu[i] = Ri[i] = 1e9;
rem_pos.insert(i);
rem_val.insert(i);
}
for(int i = 0; i < Q; i++){
int l, r, x; cin >> l >> r >> x;
Li[x] = max(Li[x], l), Ri[x] = min(Ri[x], r);
Lu[x] = min(Lu[x], l), Ru[x] = max(Ru[x], r);
}
for(int i = n-1; i >= 0; i--){
if(Li[i] == -1e9) continue;
if(Li[i] > Ri[i]) ex();
auto itp = rem_pos.lower_bound(Li[i]);
if(itp == rem_pos.end() or *itp > Ri[i]) ex();
ans[*itp] = i;
rem_pos.erase(itp), rem_val.erase(i);
while(!rem_pos.empty()){
itp = rem_pos.lower_bound(Lu[i]);
if(itp == rem_pos.end() or *itp > Ru[i]) break;
int v = *(rem_val.rbegin());
if(v < i) ex();
ans[*itp] = v;
rem_pos.erase(itp), rem_val.erase(v);
}
}
while(!rem_pos.empty()){
ans[*(rem_pos.begin())] = *rem_val.begin();
rem_pos.erase(rem_pos.begin()), rem_val.erase(rem_val.begin());
}
for(int i = 0; i < n; i++) cout << ans[i] << " ";
cout << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
328 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
324 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
324 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
328 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
324 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
324 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
460 KB |
Output is correct |
16 |
Correct |
1 ms |
460 KB |
Output is correct |
17 |
Correct |
1 ms |
460 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
0 ms |
332 KB |
Output is correct |
26 |
Correct |
0 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
328 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
324 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
324 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
460 KB |
Output is correct |
16 |
Correct |
1 ms |
460 KB |
Output is correct |
17 |
Correct |
1 ms |
460 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
0 ms |
332 KB |
Output is correct |
26 |
Correct |
0 ms |
332 KB |
Output is correct |
27 |
Correct |
62 ms |
9836 KB |
Output is correct |
28 |
Correct |
66 ms |
10820 KB |
Output is correct |
29 |
Correct |
61 ms |
10308 KB |
Output is correct |
30 |
Correct |
71 ms |
11384 KB |
Output is correct |
31 |
Correct |
55 ms |
8688 KB |
Output is correct |
32 |
Correct |
52 ms |
8512 KB |
Output is correct |
33 |
Correct |
53 ms |
9936 KB |
Output is correct |
34 |
Correct |
34 ms |
6868 KB |
Output is correct |
35 |
Correct |
62 ms |
11448 KB |
Output is correct |
36 |
Correct |
59 ms |
11648 KB |
Output is correct |
37 |
Correct |
55 ms |
11444 KB |
Output is correct |
38 |
Correct |
28 ms |
7748 KB |
Output is correct |
39 |
Correct |
57 ms |
10644 KB |
Output is correct |
40 |
Correct |
0 ms |
316 KB |
Output is correct |
41 |
Correct |
0 ms |
332 KB |
Output is correct |