这题果然是原题[BZOJ 3689 异或之].看了BZOJ原题题解,发现自己sb了,直接每个位置维护一个值保存找到了以这个位置为右端点的第几大,初始全部都是1,把每个位置作为右端点能够异或出来的最大值放入优先队列,然后找最大的一个累计答案后pop掉,假设找到的右端点是r,就把r能异或出来的第二大再加入队列.找k次就行了.这样在trie上找第k大就维护一个size就行了.mdzz这么显然居然没有想出来,还是自己太菜…

签到题没做来…

CODE

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
char cb[1<<15],*cs=cb,*ct=cb;
#define getc() (cs==ct&&(ct=(cs=cb)+fread(cb,1,1<<15,stdin),cs==ct)?0:*cs++)
template<class T>inline void read(T &res) {
char ch; while(!isdigit(ch=getchar()));
for(res=ch-'0';isdigit(ch=getchar());res=res*10+ch-'0');
}
const int MAXN = 500005;
const int MAXM = MAXN*32;
struct node {
int id; LL val;
node(){}
node(int ii, LL vv):id(ii), val(vv){}
bool operator <(const node &o)const {
return val < o.val;
}
};
priority_queue<node> q;
int ch[MAXM][2], sz[MAXM], cnt[MAXM], tot; int n, k, now[MAXN];
LL s[MAXN]; inline void insert(LL x) {
int r = 0;
for(int i = 31, c; ~i; --i) {
c = (x & (1ll<<i)) ? 1 : 0;
if(!ch[r][c]) ch[r][c] = ++tot;
++sz[r = ch[r][c]];
}
++cnt[r];
} inline LL kth(LL x, int k) {
int r = 0; LL re = 0;
for(int i = 31, c; ~i; --i) {
c = (x & (1ll<<i)) ? 0 : 1;
if(sz[ch[r][c]] < k) k -= sz[ch[r][c]], r = ch[r][!c];
else re ^= 1ll<<i, r = ch[r][c];
}
return re;
} int main () {
read(n), read(k), k<<=1;
insert(0);
for(int i = 1, x; i <= n; ++i)
read(x), s[i] = s[i-1] ^ x, insert(s[i]);
for(int i = 0; i <= n; ++i)
q.push(node(i, kth(s[i], ++now[i])));
LL ans = 0;
while(k--) {
node u = q.top(); q.pop();
if(k&1) ans += u.val;
if(now[u.id] < n) q.push(node(u.id, kth(s[u.id], ++now[u.id])));
}
printf("%lld\n", ans);
}

最新文章

  1. 【UOJ #35】后缀排序 后缀数组模板
  2. tcp连接listen的backlog剖析
  3. 规则引擎集成接口(九)Java类对象
  4. Leetcode: Combination Sum IV &amp;&amp; Summary: The Key to Solve DP
  5. Resume Hook SSDT
  6. Consumer closed input channel or an error occurred. events=0x8 channel is unrecoverably broken and will be disposed(待解决)
  7. (转载)根据数据字典表定义的表结构,生成创建表的SQL语句
  8. 搭建FTP+PAM+MySQL环境
  9. (转)Android创建桌面快捷方式两种方法
  10. 一天一个类 --- StringTokenizer
  11. python 第三章 字符串-例1
  12. 一步一步学MySQL-日志文件
  13. 一个.net专业户转Spring Boot V2.0开发的体会
  14. UNIX网络编程——非阻塞connect:时间获取客户程序
  15. POJ_2104_K-th Number_主席树
  16. 微信小程序开发之搞懂flex布局5——cross axis
  17. sflow介绍与安装过程
  18. C# 一般处理程序生成验证码
  19. html select控件的jq操作
  20. ansible2.4.x RPM急速安装

热门文章

  1. linux网卡出现问题:Job for network.service failed because the control process exited with error code问题
  2. 利用Python进行数据分析_Pandas_数据清理、转换、合并、重塑
  3. web服务器/HTTP协议基础
  4. docker&amp;k8s-配置/常用命令
  5. (1+x)^n
  6. 处理bugs心法
  7. prometheus+grafana监控nginx
  8. 接口请求 URL转码
  9. mysql 2 修改表
  10. python Beautiful Soup 采集it books pdf,免费下载