BZOJ3261【可持久化Tire】
来源:互联网 发布:博盈软件 编辑:程序博客网 时间:2024/06/07 00:44
可以运用前缀异或和的思想.将问题转化成在包含一个区间的Tire上贪心求解.
/* I will wait for you */ #include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<ctime>#include<algorithm>#include<iostream>#include<fstream>#include<vector>#include<queue>#include<deque>#include<set>#include<map>#include<string>#define make make_pair#define fi first#define se second using namespace std; typedef long long LL;typedef unsigned long long ULL;typedef pair<int,int> PII; const int maxn=1000010;const int maxm=1010;const int maxs=23;const int INF=1<<29;const int P=1000000007;const double error=1e-9; struct node{ node* son[2];int sum; }*su[maxn]; node* insert(node*o,int val,int c){ node* p=new node(); p->sum=o?o->sum+1:1; if(c>=0) { int t=(val&(1<<c))>>c; p->son[t]=insert(o?o->son[t]:0,val,c-1); p->son[t^1]=o?o->son[t^1]:0; } return p;} int query(node* l,node* r,int val,int c){ int t=(val&(1<<c))>>c; int ls=l&&l->son[t^1]?l->son[t^1]->sum:0; int rs=r&&r->son[t^1]?r->son[t^1]->sum:0; int ans=(rs>ls)*(1<<c); if(c) { if(rs>ls) ans+=query(l?l->son[t^1]:0,r?r->son[t^1]:0,val,c-1); else ans+=query(l?l->son[t]:0,r?r->son[t]:0,val,c-1); } return ans;} int main(){ int n,q,last=0;scanf("%d%d",&n,&q); n++;su[1]=insert(su[0],0,maxs); for(int i=2,c;i<=n;i++) scanf("%d",&c),su[i]=insert(su[i-1],last=last^c,maxs); for(int i=1;i<=q;i++) { char s[10];int c,x,y;scanf("%s",s); if(s[0]=='A') scanf("%d",&c),n++,su[n]=insert(su[n-1],last=last^c,maxs); if(s[0]=='Q') scanf("%d%d%d",&x,&y,&c),printf("%d\n",query(su[x-1],su[y],last^c,maxs)); } return 0;}
0 0
- BZOJ3261【可持久化Tire】
- [BZOJ3261]-可持久化trie
- BZOJ4103【可持久化Tire】
- BZOJ3166 && BZOJ3261 可持久化字典树
- bzoj 3166 可持久化Tire
- 【BZOJ3261】最大异或和【可持久化Trie树】
- bzoj3261 最大异或和(可持久化字典树)
- [BZOJ3261][最大异或和][可持久化Trie]
- [可持久化Trie] BZOJ3261: 最大异或和
- BZOJ3261最大异或和(可持久化字典树)
- bzoj3261 最大异或和(可持久化Trie)
- bzoj3261 最大异或和【可持久化trie树】
- [BZOJ3166][Heoi2013]Alo(可持久化线段树+可持久化tire树)
- [BZOJ3261]最大异或和(可持久化trie树)
- 【bzoj3261】【最大异或和】可持久化trie树+贪心
- bzoj3261最大异或和&&可持久化Trie树详解
- BZOJ 3261: 最大异或和|可持久化Tire树
- 可持久化数据结构
- 在去哪儿网订了机票现在找不到订单了怎么办?
- 遗传算法解决常见多元表达式
- 去哪儿网机票订单怎么取消_百度知道
- 黑马程序员——Date类、Calender类、Math类
- jfinal框架教程-学习笔记(二)
- BZOJ3261【可持久化Tire】
- Create Wifi Hotspot in Ubuntu 14.04
- 辛星浅析Linux中的anacron
- Ubuntu摆脱QQ版本过旧问题!安装 wine-international版 qq
- [LeetCode/LinkedIn] Integer to Roman and roman number to Integer
- 黑马程序员——Java面向对象编程学习总结
- [LinkedIn, LeetCode] given a log file, parse the valid ip addresses, no duplicate
- 2-14
- gdjfdsofods附近的说了句分离式的经费落实