HDU 4399 Query multiset 解法

网上看到的multiset解法。就是把每个不同的位置放到multiset里面,然后查询的时候找到比他大的第一个数 即lower_bound(); 更新的是在集合里面插入和删除就行了 。

不知道为什么用的multiset ,位置是没有重复的啊 然后换成 set后也可以AC。

 1 #include <cstdio>
 2 #include <vector>
 3 #include <algorithm>
 4 #include <cstring>
 5 #include <map>
 6 #include <queue>
 7 #include <set>
 8 
 9 using namespace std;
10 
11 #define SI(a) scanf("%d", &(a))
12 #define SS(a) scanf("%s", (a))
13 #define SC(a) scanf("%c", &(a));
14 #define Max(a, b) (a > b ? a : b)
15 #define Min(a, b) (a < b ? a : b)
16 
17 const int maxn = 1000000 + 50;
18 
19 set<int> S;
20 set<int>::iterator it;
21 char s[3][maxn];
22 int n;
23 
24 int hx[maxn], hy[maxn];
25 
26 
27 int main() {
28    int T;
29 
30    SI(T);
31    for(int kase=1; kase<=T; kase++) {
32       S.clear();
33       SS(s[1]);
34       SS(s[2]);
35 
36       printf("Case %d:\n", kase);
37       n = Min(strlen(s[1]), strlen(s[2]));
38       for(int i=0; i<n; i++) if(s[1][i] != s[2][i])
39          S.insert(i);
40       S.insert(n);
41 
42       int q;
43       SI(q);
44       while(q--) {
45          int type, a, i;
46          char c;
47          SI(type);
48          if(type == 1) {
49             SI(a);   SI(i);
50             getchar();  SC(c);
51 
52             if(s[a][i] != s[3-a][i] && c == s[3-a][i])
53                S.erase(i);
54             if(s[a][i] == s[3-a][i] && c != s[3-a][i])
55                S.insert(i);
56             s[a][i] = c;
57 
58          } else {
59             SI(i);
60             it = S.lower_bound(i);
61             printf("%d\n", *it - i);
62          }
63 
64       }
65    }
66 
67     return 0;
68 }

 

posted on 2013-08-09 15:01  zhaosdfa  阅读(181)  评论(0编辑  收藏  举报

导航