include iostream include vector include map include set int main unsig

 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
62
63
64
65
66
67
68
69
70
#include <iostream>
#include <vector>
#include <map>
#include <set>
int main() {
unsigned long m = 0, n = 0, l = 0, r = 0, v=0;
std::cin>>n>>m;
//"минимумы"
std::vector<unsigned long> seq(n);
//использованные числа
std::set<unsigned long> nums;
//ограничения
std::map<unsigned long, std::vector<std::pair<unsigned long, unsigned long> > > cons;
//результат
std::vector<unsigned long> res(n);
//обнуляем минимумы и результат
for(int i = 0; i<n; i++) {
seq[i]=0;
res[i] = 0;
}
//вводим ограничения
for(unsigned long i = 0; i<m; i++) {
std::cin>>l>>r>>v;
l--; r--;
cons[v].push_back( std::pair<unsigned long, unsigned long>(l,r) );
for(int j = l;j<=r; j++) {
seq[j] = std::max(seq[j], v);
}
}
/*
for(int i = 0; i<n; i++) {
std::cout<<seq[i]<<" ";
}
std::cout<<std::endl;
*/
for(unsigned long i = 0; i<n; i++) {
//std::cout<<"get start j = "<<seq[i]<<std::endl;
for(unsigned long j = seq[i];; j++) {
//std::cout<<"get j = "<<j<<std::endl;
if(nums.find(j)==nums.end()) {
bool passed = true;
for(unsigned long 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.insert(j);
break;
}
}
}
}
for(unsigned long i = 0; i<n; i++) {
std::cout<<res[i]<<" ";
}
return 0;
}