**题意:**给出一串序列,求区间连续异或值的最大和最小。
**思路:**如果不是出在专题里,想不到可以用字典树做。先求前缀异或值,转为二进制,加入Trie树中,如果要求最大,就是尽可能走和当前位数字相反的,这样异或值才能保持最大,最小,就尽可能走和当前位数字相同的,走到尽头异或前缀值。

/** @Date    : 2016-11-10-16.34

* @Author : Lweleth (SoungEarlf@gmail.com)

* @Link : https://github.com/

* @Version :

*/

#include <stdio.h>

#include <iostream>

#include <string.h>

#include <algorithm>

#include <utility>

#include <vector>

#include <map>

#include <set>

#include <string>

#include <stack>

#include <queue>

#define LL long long

#define MMF(x) memset((x),0,sizeof(x))

#define MMI(x) memset((x), INF, sizeof(x))

using namespace std;



const int INF = 0x3f3f3f3f;

const int N = 5e4+20;



struct yuu

{

int cnt;

int val[35*N];//前缀和值

int nxp[35*N][2];



int init()

{

MMF(nxp[0]);

MMF(val);

cnt = 1;

}



int idx(char c)

{

return c - '0';

}



int insert(char *s, int v)//

{

int u = 0;

int x = strlen(s);

for(int i = 0; i < x; i++)

{

int c = idx(s[i]);

if(nxp[u][c] == 0)

{

MMF(nxp[cnt]);

nxp[u][c] = cnt;

cnt++;

}

u = nxp[u][c];

}

val[u] = v;

}



int find(char *s, int a, int ma)//ma 代表 是否找相反的

{

int u = 0;

int x = strlen(s);



for(int i = 0; i < x; i++)

{

int c = idx(s[i]);

int v = c ^ ma;

if(nxp[u][v] == 0)

{

v ^= 1;

}

u = nxp[u][v];

}

return val[u] ^ a;//尽头赋值

}

}tt;



void atoi_(char *s, int x)

{

for(int i = 31; i >= 0; i--)

{

s[i] = ((x >> i) & 1) + '0';

}

s[32] = '\0';

reverse(s, s + 32);

// for(int i = 0; i <= 32; i++)

// cout << s[i] ;

// cout << endl;

}



int a[N];

int sum[N];

char t[35];



int main()

{

int T;

int cnt = 0;

cin >> T;

while(T--)

{

int n;

scanf("%d", &n);

sum[0] = 0;

for(int i = 1; i <= n; i++)

{

scanf("%d", a + i);

sum[i] = sum[i-1] ^ a[i];

}

tt.init();

atoi_(t, 0);

tt.insert(t, 0);



int ma = -INF;

int mi = INF;

for(int i = 1; i <= n; i++)

{

atoi_(t, sum[i]);

ma = max(ma, tt.find(t, sum[i], 1));

mi = min(mi, tt.find(t, sum[i], 0));

tt.insert(t, sum[i]);

}

printf("Case %d: %d %d\n", ++cnt, ma, mi);

}

return 0;

}

LightOJ 1269 - Consecutive Sum Trie树的更多相关文章

  1. LightOJ 1269 Consecutive Sum (Trie树)

    Jan's LightOJ :: Problem 1269 - Consecutive Sum 题意是,求给定序列的中,子序列最大最小的抑或和. 做法就是用一棵Trie树,记录数的每一位是0还是1.查 ...

  2. 1269 - Consecutive Sum

    1269 - Consecutive Sum    PDF (English) Statistics Forum Time Limit: 3 second(s) Memory Limit: 64 MB ...

  3. LightOJ 1129 - Consistency Checker Trie树模板

    题意:给出n条串判断是否存在一个串为另一个串的前缀. 思路:套Trie树的模板,先全部插入,再查找每个字串,如果查找字串完毕,但还存在下一个节点,说明存在前缀. /** @Date : 2016-11 ...

  4. hdu 4825 Xor Sum trie树

    Xor Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 132768/132768 K (Java/Others) Proble ...

  5. HDU4825 Xor Sum —— Trie树

    题目链接:https://vjudge.net/problem/HDU-4825 Xor Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Li ...

  6. Consecutive Sum LightOJ - 1269(区间异或和)

    Consecutive Sum 又来水一发blog... 本来是昨天补codechef的题,最后一道题是可持久化字典树,然后去黄学长博客看了看 觉得字典树写法有点不太一样,就想着用黄学长的板子写码几道 ...

  7. HDU 4825 Xor Sum (trie树处理异或)

    Xor Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 132768/132768 K (Java/Others)Total S ...

  8. CodeForces979D:Kuro and GCD and XOR and SUM(Trie树&指针&Xor)

    Kuro is currently playing an educational game about numbers. The game focuses on the greatest common ...

  9. HDU4825 Xor Sum(贪心+Trie树)

    Problem Description Zeus 和 Prometheus 做了一个游戏,Prometheus 给 Zeus 一个集合,集合中包含了N个正整数,随后 Prometheus 将向 Zeu ...

随机推荐

  1. vue移动音乐app开发学习(三):轮播图组件的开发

    本系列文章是为了记录学习中的知识点,便于后期自己观看.如果有需要的同学请登录慕课网,找到Vue 2.0 高级实战-开发移动端音乐WebApp进行观看,传送门. 完成后的页面状态以及项目结构如下: 一: ...

  2. Alpha发布——Thunder团队

    视频展示 视频链接: 爱奇艺: http://www.iqiyi.com/w_19ruzwru25.html      (画质清晰,但可能需多次刷新或重新打开页面,此问题因电脑型号和网络而异) 优酷: ...

  3. # ML学习小笔记—Classification

    关于本课程的相关资料http://speech.ee.ntu.edu.tw/~tlkagk/courses_ML17.html 通过模型可以分类输入,此时根据分类结果的正确与否会有一个Loss函数.找 ...

  4. android入门 — ListView点击事件

    listView中提供了两种点击事件的处理方法,分别是OnItemClick和OnItemLongClick. OnItemClick提供的是点击操作的处理,OnItemLongClick提供的是长按 ...

  5. C#窗口文件双击打开时出错

    出错原因: 1. 修改了该窗口文件的.Designer.cs文件中:#region Windows 窗体设计器生成的代码这里面的代码,导致运行不正常. 为了传递数据,我在构造函数中增加了传递的值. 需 ...

  6. 苹果ATS特性服务器配置指南 HTTPS 安卓可以用 IOS 报错。

    解决方案:https://www.qcloud.com/document/product/400/6973 ATS检测:https://www.qcloud.com/product/ssl#userD ...

  7. [OS] CPU调度

    调度准则 为了比较CPU调度算法,分析员提供了许多准则,用于比较的特征对确定最佳算法有很大影响.这些准则包括: ·CPU使用率:需要使CPU尽可能忙. ·吞吐量:一个时间单元内完成进程的数量. ·周转 ...

  8. echarts 画 canvas 如果在IE8下不显示图标

    网上说法很多,可能版本问题,也有说script标签位置问题(放在body中) 不过先试已下,清除option对象中多余的逗号(,) 对象的最后一个属性后不要有逗号结尾

  9. 第63天:json的两种声明方式

    一. json 两种声明方式 1. 对象声明   var  json = {width:100,height:100} 2. 数组声明   var  man = [        //  数组的 js ...

  10. Oracle触发器实现监控某表的CRUD操作

    前提:请用sys用户dba权限登录 1.创建一个表来存储操作日志 create table trig_sql( LT DATE not null primary key, SID NUMBER, SE ...