BZOJ4546: codechef XRQRS
Description
Input
Output
Sample Input
1 8
5 1 1 1
1 2
2 2 2 7
2 2 2 7
1 1
4 2 2 2
2 1 2 3
4 1 3 5
1 6
Sample Output
2
2
1
8
2
HINT
#include<cstdio>
#include<cctype>
#include<queue>
#include<cstring>
#include<algorithm>
#define rep(i,s,t) for(int i=s;i<=t;i++)
#define dwn(i,s,t) for(int i=s;i>=t;i--)
#define ren for(int i=first[x];i;i=next[i])
using namespace std;
const int BufferSize=1<<16;
char buffer[BufferSize],*head,*tail;
inline char Getchar() {
if(head==tail) {
int l=fread(buffer,1,BufferSize,stdin);
tail=(head=buffer)+l;
}
return *head++;
}
inline int read() {
int x=0,f=1;char c=getchar();
for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
for(;isdigit(c);c=getchar()) x=x*10+c-'0';
return x*f;
}
const int maxn=500010;
const int maxnode=10000010;
int ch[maxnode][2],s[maxnode],ToT;
void insert(int& ny,int x,int val) {
ny=++ToT;int y=ny;s[y]=s[x]+1;
dwn(i,18,0) {
int c=val>>i&1;
ch[y][0]=ch[x][0];ch[y][1]=ch[x][1];
s[ch[y][c]=++ToT]=s[ch[x][c]]+1;
y=ch[y][c];x=ch[x][c];
}
}
int querymx(int y,int x,int val) {
int ans=0;
dwn(i,18,0) {
int c=val>>i&1;
if(s[ch[y][c^1]]-s[ch[x][c^1]]) ans|=(1<<i),c^=1;
x=ch[x][c];y=ch[y][c];
}
return ans;
}
int query(int y,int x,int val) {
int ans=0;
dwn(i,18,0) {
int c=val>>i&1;
if(c) ans+=s[ch[y][0]]-s[ch[x][0]];
x=ch[x][c];y=ch[y][c];
}
return ans;
}
int kth(int y,int x,int k) {
int ans=0;
dwn(i,18,0) {
int k2=s[ch[y][0]]-s[ch[x][0]];
if(k<=k2) x=ch[x][0],y=ch[y][0];
else ans|=(1<<i),k-=k2,x=ch[x][1],y=ch[y][1];
}
return ans;
}
int n,top,fa[maxn],root[maxn],S[maxn];
int main() {
int p=0;
dwn(T,read(),1) {
int tp=read();
if(tp==1) insert(root[++n],root[p],read()),fa[n]=p,S[++top]=p=n;
else if(tp==3) dwn(i,read(),1) p=fa[p],top--;
else {
int l=read(),r=read(),x=read();
if(tp==2) printf("%d\n",x^querymx(root[S[r]],root[S[l-1]],x));
if(tp==4) printf("%d\n",query(root[S[r]],root[S[l-1]],x+1));
if(tp==5) printf("%d\n",kth(root[S[r]],root[S[l-1]],x));
}
}
return 0;
}
BZOJ4546: codechef XRQRS的更多相关文章
- bzoj 4546: codechef XRQRS [可持久化Trie]
4546: codechef XRQRS 可持久化Trie codechef上过了,bzoj上蜜汁re,看别人说要开5.2e5才行. #include <iostream> #includ ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- Involuting Bunny! (2021.9)
文化课就很掉头发,文科都能学好我还怕竞赛?( 大概从"刷的题的题解"推广为"所有做的题的题解"吧,兔子比较懒,这样写题解轻松一些. Gym10305 ...
- 【BZOJ-3514】Codechef MARCH14 GERALD07加强版 LinkCutTree + 主席树
3514: Codechef MARCH14 GERALD07加强版 Time Limit: 60 Sec Memory Limit: 256 MBSubmit: 1288 Solved: 490 ...
- 【BZOJ4260】 Codechef REBXOR 可持久化Trie
看到异或就去想前缀和(⊙o⊙) 这个就是正反做一遍最大异或和更新答案 最大异或就是很经典的可持久化Trie,从高到低贪心 WA: val&(1<<(base-1))得到的并不直接是 ...
- codechef 两题
前面做了这场比赛,感觉题目不错,放上来. A题目:对于数组A[],求A[U]&A[V]的最大值,因为数据弱,很多人直接排序再俩俩比较就过了. 其实这道题类似百度之星资格赛第三题XOR SUM, ...
- codechef January Challenge 2014 Sereja and Graph
题目链接:http://www.codechef.com/JAN14/problems/SEAGRP [题意] 给n个点,m条边的无向图,判断是否有一种删边方案使得每个点的度恰好为1. [分析] 从结 ...
- BZOJ3509: [CodeChef] COUNTARI
3509: [CodeChef] COUNTARI Time Limit: 40 Sec Memory Limit: 128 MBSubmit: 339 Solved: 85[Submit][St ...
- CodeChef CBAL
题面: https://www.codechef.com/problems/CBAL 题解: 可以发现,我们关心的仅仅是每个字符出现次数的奇偶性,而且字符集大小仅有 26, 所以我们状态压缩,记 a[ ...
随机推荐
- js正则表达式:验证邮箱格式、密码复杂度、手机号码、QQ号码
直接上代码 Java 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 ...
- [LeetCode] Remove Duplicates from Sorted Array
Given a sorted array, remove the duplicates in place such that each element appear only once and ret ...
- 数据结构之图 Part2 - 1
邻接矩阵 网上很少有C# 写图的数据结构的例子,实际的项目中也从来没用过Array 这坨东西,随手写个,勿喷. namespace LH.GraphConsole { public struct Gr ...
- PowerDesigner连接Oracle数据库生成数据模型【本地连接方式】
步骤1:选择数据库 步骤2:选择要连接的数据库的版本 步骤3:新建数据库连接 步骤4:提供3种连接数据库方式(在此选择第3种),并且点击配置按钮,进行下一步 步骤5:点击此按钮,填 ...
- PMP 第五章 项目范围管理
1.范围管理主要是干什么?什么是产品范围?什么是项目范围? 项目范围管理包括确保项目做而且只做成功完成项目所需的全部工作的各过程.管理项目范围主要是在定义和控制哪些工作应该包括在项目内,哪些不应 ...
- 应用程序调试工具gdb,王明学learn
应用程序调试工具gdb学习使用 一.GDB简介 GDB 是 GNU 发布的一款功能强大的程序调试工具.GDB 主要完成下面三个方面的功能: 1.启动被调试程序. 2.让被调试的程序在指定的位置停住. ...
- Java利用Preferences设置个人偏好
Java利用Preferences设置个人偏好 Preferences的中文意思即偏好或喜好的意思,也就是说同一个程序在每次运行完后,可以通过Preferences来记录用户的偏好,下次启动时,程序会 ...
- LoadRunner 场景运行error的几种情况
一. Error -27727: Step download timeout (120 seconds)has expired when downloading resource(s). Set th ...
- DSP using MATLAB 示例 Example3.19
代码: % Analog Signal Dt = 0.00005; t = -0.005:Dt:0.005; xa = exp(-1000*abs(t)); % Discrete-time Signa ...
- DSP using MATLAB 示例Example3.8
代码: x = rand(1,11); n = 0:10; k = 0:500; w = (pi/500)*k; % [0,pi] axis divided into 501 points. X = ...