Codeforces 356A

这题有个注意的地方,就是对集合边读边删除的时候,应该尤为注意。。   my_set.erase(it++)

 1 #include 
 2 
 3 #include 
 4 #include <set>
 5 
 6 using namespace std;
 7 
 8 int color[300005];
 9 
10 int main(){
11     int n, m;
12     while (cin >> n >> m) {
13         set<int> my_set;
14         for (int i = 1; i <= n; i++) {
15             my_set.insert(i);
16         }
17         memset(color, 0, sizeof(color));
18 
19         for (int i = 0; i < m; i++) {
20             int l, r, x;
21             cin >> l >> r >> x;
22             set<int>::iterator it;
23             it = my_set.lower_bound(l);
24             while (it != my_set.end()) {
25                 if ((*it) > r) {
26                     break;
27                 }
28                 if ((*it) == x) {
29                     it++;
30                     continue;
31                 }
32                 color[(*it)] = x;
33                 my_set.erase(it++);
34                 /* it++; */
35             }
36         }
37         for (int i = 1; i <= n; i++) {
38             cout << color[i] << (i==n ? '\n' : ' ');
39         }
40     }
41 
42     return 0;
43 }

 

转载于:https://www.cnblogs.com/Stomach-ache/p/3703185.html

你可能感兴趣的:(Codeforces 356A)