include iostream include vector include map int main long long std cin

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <iostream>
#include <vector>
#include <map>
int main() {
long long m = 0, n = 0, l = 0, r = 0, v=0;
std::cin>>n>>m;
std::vector<long long> seq(n);
std::vector<long long> nums(n);
std::map<long long, std::vector<std::pair<long long, long long> > > cons;
std::vector<long long> res(n);
for(int i = 0; i<n; i++) {
seq[i]=0;
nums[i] = 0;
res[i] = 0;
}
for(int i = 0; i<m; i++) {
std::cin>>l>>r>>v;
l--; r--; v--;
cons[v].push_back( std::pair<long long, long long>(l,r) );
if(nums[v] == n)
nums[v] = l;
else
nums[v] = std::max(nums[v], l);
for(int j = l;j<=r; j++) {
seq[j] = std::max(seq[j], v);
}
}
for(int i = 0; i<n; i++) {
for(int j = seq[i]; j<n; j++) {
if(nums[j]>=0 && i>=nums[j] && j>=seq[i]) {
bool passed = true;
for(int k = 0; k<cons[j].size(); k++)
if(i<cons[j][k].first || i> cons[j][k].second) {
passed = false;
break;
}
if(passed) {
res[i] = j;
nums[j] = -1;
break;
}
}
}
}
for(int i = 0; i<n; i++) {
std::cout<<res[i]+1<<" ";
}
return 0;
}