Codeforces 356A

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

 1 #include <iostream>
 2 
 3 #include <cstring>
 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 }

 

posted on 2013-10-16 22:28  Stomach_ache  阅读(177)  评论(0编辑  收藏  举报

导航