码迷,mamicode.com
首页 > 其他好文 > 详细

BZOJ - 3578: GTY的人类基因组计划2

时间:2018-01-08 18:35:15      阅读:161      评论:0      收藏:0      [点我收藏+]

标签:include   异或   str   targe   col   else   一个   space   bzoj   

3578: GTY的人类基因组计划2

第一次居然hash被卡了。改了改rd()就A了。

题解:咱给每个人都随机一个数,几个人就是把他们的数异或起来,用set判重。再开一个set记录合法的房间。

 1 #include<set>
 2 #include<cstdio>
 3 #include<bitset>
 4 #include<cstdlib>
 5 #include<iostream>
 6 using namespace std;
 7 inline char nc() {
 8     static char b[1<<16],*s=b,*t=b;
 9     return s==t&&(t=(s=b)+fread(b,1,1<<16,stdin),s==t)?-1:*s++;
10 }
11 inline void read(int &x) {
12     char b = nc(); x = 0;
13     for (; !isdigit(b); b = nc());
14     for (; isdigit(b); b = nc()) x = x * 10 + b - 0;
15 }
16 inline int op() {
17     char b = nc(); for (; b != C && b != W; b = nc()); return b == C;
18 }
19 typedef unsigned long long ull;
20 typedef ull bt;
21 int n, m, q, p[100005], c[100005];
22 const ull ULL_MAX = -1;
23 bt a[100005], b[100005];
24 inline ull rd() {
25     return ull(rand()) * rand() * rand();
26 }
27 set < bt > h;
28 set < int > s;
29 int main() {
30     read(n); read(m); read(q); srand(89513255); s.insert(1);
31     for (int i = 1; i <= n; ++i) a[i] = rd(), p[i] = 1;
32     for (int i = 1; i <= n; ++i) b[1] ^= a[i]; c[1] = n;
33     for (int l, r, o, i = 0; i < q; ++i) {
34         o = op(); read(l); read(r);
35         if (o) {
36             if (p[l] == r) continue;
37             s.erase(p[l]); s.erase(r);
38             b[p[l]] ^= a[l]; --c[p[l]];
39             if (!h.count(b[p[l]])) s.insert(p[l]);
40             b[r] ^= a[l]; ++c[r]; p[l] = r;
41             if (!h.count(b[r])) s.insert(r);
42         } else {
43             int ans = 0; static set < int > :: iterator it; it = s.lower_bound(l);
44             for (; it != s.end() && *it <= r; it = s.lower_bound(l)) {
45                 h.insert(b[*it]); ans += c[*it]; s.erase(it);
46             } printf("%d\n", ans);
47         }
48     }
49     return 0;    
50 }

 

BZOJ - 3578: GTY的人类基因组计划2

标签:include   异或   str   targe   col   else   一个   space   bzoj   

原文地址:https://www.cnblogs.com/p0ny/p/8243714.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!