「LibreOJ β Round #2」计算几何瞎暴力
题解
首先我们如果没有排序这个骚操作的话,可以直接记一下各个数位的前缀和,然后异或标记给全局打,查询的时候先把区间信息提取出来然后整体异或就好了。
对于排序,我们考虑对所有排好序的节点建\(trie\)树,这样即使有全局异或标记,我们也可以在\(trie\)树上完成前缀信息的查询。
然后就做完了。
代码
#include<bits/stdc++.h>
#define N 200009
#define ls ch[cnt][0]
#define rs ch[cnt][1]
using namespace std;
typedef long long ll;
const int maxn=30;
int a[N],n,q;
int ch[N*maxn][2],ct[N*maxn][maxn],size[N*maxn],sm[N][maxn];
int tot,rot;
int tag,nowtag;
ll ton[32],nw;
inline ll rd(){
ll x=0;char c=getchar();bool f=0;
while(!isdigit(c)){if(c=='-')f=1;c=getchar();}
while(isdigit(c)){x=(x<<1)+(x<<3)+(c^48);c=getchar();}
return f?-x:x;
}
void ins(int &cnt,int x,int p){
if(!cnt)cnt=++tot;
size[cnt]++;
for(int i=0;i<=29;++i)if((1<<i)&x)ct[cnt][i]++;
if(p<0)return;
int o=(x&(1<<p))!=0;
if(o)ins(rs,x,p-1);
else ins(ls,x,p-1);
}
inline ll getsum(int now){
memset(ton,0,sizeof(ton));
if(now>=nw){
for(int i=0;i<=29;++i)ton[i]+=sm[now][i];
}
else{
int cnt=rot,siz=now;
for(int i=29;i>=0;--i){
int lson=ls,rson=rs;
if(nowtag&(1<<i))swap(lson,rson);
if(size[lson]>=siz)cnt=lson;
else{
for(int j=0;j<=29;++j)ton[j]+=ct[lson][j];
siz-=size[lson];
cnt=rson;
}
}
if(siz){
for(int i=0;i<=29;++i)ton[i]+=(ct[cnt][i]!=0)*siz;
}
}
ll ans=0;
for(int i=0;i<=29;++i){
ll ss;
if(tag&(1<<i))ss=now-ton[i];else ss=ton[i];
// cout<<ss<<" ";
ans+=ss*(1ll<<i);
}
//cout<<"??\n";
return ans;
}
int main(){
// freopen("1.txt","r",stdin);
// freopen("out","w",stdout);
n=rd();
nw=1;
for(int i=1;i<=n;++i){
a[i]=rd();
for(int j=0;j<=29;++j)sm[i][j]=sm[i-1][j]+((a[i]&(1<<j))!=0);
}
q=rd();
int opt,x,l,r;
while(q--){
opt=rd();
if(opt==1){
x=rd();x^=tag;
++n;a[n]=x;
for(int j=0;j<=29;++j)sm[n][j]=sm[n-1][j]+((a[n]&(1<<j))!=0);
}
else if(opt==2){
l=rd();r=rd();
printf("%lld\n",getsum(r)-getsum(l-1));
}
else if(opt==3)tag^=rd();
else if(opt==4){
nowtag=tag;
while(nw<=n)ins(rot,a[nw],29),nw++;
}
}
return 0;
}
「LibreOJ β Round #2」计算几何瞎暴力的更多相关文章
- LibreOJ #517. 「LibreOJ β Round #2」计算几何瞎暴力
二次联通门 : LibreOJ #517. 「LibreOJ β Round #2」计算几何瞎暴力 /* LibreOJ #517. 「LibreOJ β Round #2」计算几何瞎暴力 叫做计算几 ...
- [LOJ#517]. 「LibreOJ β Round #2」计算几何瞎暴力[trie]
题意 题目链接 分析 记操作异或和为 \(tx\) ,最后一次排序时的异或和为 \(ax\) ,每个数插入时的 \(tx\) 记为 \(b\). 我们发现,一旦数列排序,就会变得容易操作. 对于新加入 ...
- [LOJ#522]「LibreOJ β Round #3」绯色 IOI(危机)
[LOJ#522]「LibreOJ β Round #3」绯色 IOI(危机) 试题描述 IOI 的比赛开始了.Jsp 和 Rlc 坐在一个角落,这时他们听到了一个异样的声音 …… 接着他们发现自己收 ...
- LibreOJ #516. 「LibreOJ β Round #2」DP 一般看规律
二次联通门 : LibreOJ #516. 「LibreOJ β Round #2」DP 一般看规律 /* LibreOJ #516. 「LibreOJ β Round #2」DP 一般看规律 set ...
- loj #547. 「LibreOJ β Round #7」匹配字符串
#547. 「LibreOJ β Round #7」匹配字符串 题目描述 对于一个 01 串(即由字符 0 和 1 组成的字符串)sss,我们称 sss 合法,当且仅当串 sss 的任意一个长度为 ...
- [LOJ#531]「LibreOJ β Round #5」游戏
[LOJ#531]「LibreOJ β Round #5」游戏 试题描述 LCR 三分钟就解决了问题,她自信地输入了结果-- > -- 正在检查程序 -- > -- 检查通过,正在评估智商 ...
- [LOJ#530]「LibreOJ β Round #5」最小倍数
[LOJ#530]「LibreOJ β Round #5」最小倍数 试题描述 第二天,LCR 终于启动了备份存储器,准备上传数据时,却没有找到熟悉的文件资源,取而代之的是而屏幕上显示的一段话: 您的文 ...
- [LOJ#516]「LibreOJ β Round #2」DP 一般看规律
[LOJ#516]「LibreOJ β Round #2」DP 一般看规律 试题描述 给定一个长度为 \(n\) 的序列 \(a\),一共有 \(m\) 个操作. 每次操作的内容为:给定 \(x,y\ ...
- [LOJ#515]「LibreOJ β Round #2」贪心只能过样例
[LOJ#515]「LibreOJ β Round #2」贪心只能过样例 试题描述 一共有 \(n\) 个数,第 \(i\) 个数 \(x_i\) 可以取 \([a_i , b_i]\) 中任意值. ...
随机推荐
- idea把java web项目打成war包
1.新建artifacts 2.设置你的目录内容路径 3.找到项目web或webapp的路径 4.可以直接添加已经跑通的项目 5.配置完成点OK 6.编译打成war包 7.点击编译结束打完收工 8.找 ...
- offsetof与container_of宏分析
offsetof宏:结构体成员相对结构体的偏移位置 container_of:根据结构体成员的地址来获取结构体的地址 offsetof 宏 原型: #define offsetof(TYPE, MEM ...
- C语言第十二周作业
这个作业属于那个课程 C语言程序设计II 这个作业要求在哪 https://edu.cnblogs.com/campus/zswxy/computer-scienceclass3-2018/h ...
- 第八周zuoye
这个作业属于那个课程 C语言程序设计II 这个作业要求在哪 https://edu.cnblogs.com/campus/zswxy/computer-scienceclass3-2018/homew ...
- GCC 编译参数
-s 这个参数会把符号表从最终的可执行文件中删除.没有符号表,你就不能用gdb调试了,但是程序会更小 -O0 不做任何优化,这是默认的编译选项 -c 只编译不链接,产生.o文件,就是obj文件,不产生 ...
- 秒懂Vuejs、Angular、React原理和前端发展历史
「前端程序发展的历史」 「 不学自知,不问自晓,古今行事,未之有也 」 我们都知道现在流行的框架:Vue.Js.AngularJs.ReactJs,已经逐渐应用到各个项目和实际应用中,它们都是MVVM ...
- [LeetCode] 52. N皇后 II
题目链接 : https://leetcode-cn.com/problems/n-queens-ii/ 题目描述: n 皇后问题研究的是如何将 n 个皇后放置在 n×n 的棋盘上,并且使皇后彼此之间 ...
- C#选择文件返回缩略图
传入文件路径,返回临时文件中缩略图的路径,jpg,pdf,office,rar都行 string path = ThumbnailHelper.GetInstance().GetJPGThumbnai ...
- gorpeln的个人博客 - gorpeln
2019-10-18 App Store 审核指南 2019-10-03 锚点跳转距离顶部指定距离 2019-09-23 Jekyll 简单加密 (pwd=123456) 2019- ...
- python数据结构:pandas(2)数据操作
一.Pandas的数据操作 0.DataFrame的数据结构 1.Series索引操作 (0)Series class Series(base.IndexOpsMixin, generic.NDFra ...