BZOJ:4333: JSOI2012 智者的考验
4333: JSOI2012 智者的考验
Time Limit: 10 Sec Memory Limit: 256 MB
Submit: 68 Solved: 18
[Submit][Status][Discuss]
Description
Input
Output
Sample Input
0 0 1
1 1 0
7 4
1 1 7
0 2 3
0 3 4
1 1 7
Sample Output
3
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MN 1000001
using namespace std; int read_p,read_ca;
inline int read(){
read_p=;read_ca=getchar();
while(read_ca<''||read_ca>'') read_ca=getchar();
while(read_ca>=''&&read_ca<='') read_p=read_p*+read_ca-,read_ca=getchar();
return read_p;
}
struct na{int c[],sum,l,r,y,a,Q,V;}t[MN<<];
int n,m,q,rx,ry,o[],s[],to[][],num=,bo,ro=,x,N[];
void build(int &p,int l,int r){
if (p==) p=++num,t[p].l=t[p].r=t[p].sum=t[p].y=,t[p].a=-;
t[p].c[N[]]=((r-l)>>)+(!(l&)||!(r&));
t[p].c[N[o[]]]=((r-l)>>)+((l&)||(r&));t[p].sum=((((r-l)>>)+((l&)||(r&)))&)*o[];
if (l==r) return;
int mid=l+r>>;
build(t[p].l,l,mid);build(t[p].r,mid+,r);
}
void pd(int p,int l,int r){
if (t[p].a!=-){
if (t[p].l) t[t[p].l].a=t[p].a,t[t[p].l].V=t[p].V,t[t[p].l].Q=t[p].Q,t[t[p].l].y=;
if (t[p].r) t[t[p].r].a=t[p].a,t[t[p].r].V=t[p].V,t[t[p].r].Q=t[p].Q,t[t[p].r].y=;
memset(t[p].c,,sizeof(t[p].c));
t[p].c[N[t[p].V]]=((r-l)>>)+(!(l-t[p].Q&)||!(r-t[p].Q&));
t[p].c[N[t[p].a^t[p].V]]=((r-l)>>)+((l-t[p].Q&)||(r-t[p].Q&));t[p].sum=((((r-l)>>)+((l-t[p].Q&)||(r-t[p].Q&)))&)*t[p].a^((r-l+&)*t[p].V);
t[p].a=-;
}
}
void up(int p,int l,int r){
int mid=l+r>>;
pd(t[p].l,l,mid);pd(t[p].r,mid+,r);
t[p].sum=t[t[p].l].sum^t[t[p].r].sum^(((mid-l+)&)*t[t[p].l].y)^(((r-mid)&)*t[t[p].r].y);
for (int i=;i<;i++) t[p].c[i]=t[t[p].l].c[N[s[i]^t[t[p].l].y]]+t[t[p].r].c[N[s[i]^t[t[p].r].y]];
}
void cg(int p,int l,int r,int po,int v){
if (po<=l) t[p].y^=v;else{
pd(p,l,r);
int mid=l+r>>;
cg(t[p].r,mid+,r,po,v);
if (mid>=po) cg(t[p].l,l,mid,po,v);
up(p,l,r);
}
}
int ask(int p,int l,int r,int po){
if (t[p].a!=-) return (t[p].a*(po-t[p].Q&))^t[p].V^t[p].y;
if (l==r) return t[p].sum^t[p].y;
int mid=l+r>>;
if (po<=mid) return ask(t[p].l,l,mid,po)^t[p].y;else return ask(t[p].r,mid+,r,po)^t[p].y;
}
int que(int p,int l,int r,int L,int R,int v){
pd(p,l,r);
v^=t[p].y;
if (L==l&&R==r) return t[p].c[N[v]];
int mid=l+r>>;
if (R<=mid) return que(t[p].l,l,mid,L,R,v);else
if (L>mid) return que(t[p].r,mid+,r,L,R,v);else
return que(t[p].l,l,mid,L,mid,v)+que(t[p].r,mid+,r,mid+,R,v);
}
void ca(int p,int l,int r,int L,int R,int v,int V,int Q){
if (L==l&&R==r){
t[p].a=v;t[p].V=V;t[p].y=;t[p].Q=Q;
t[p].c[N[V]]=((r-l)>>)+(!(l-Q&)||!(r-Q&));
t[p].c[N[v^V]]=((r-l)>>)+((l-Q&)||(r-Q&));t[p].sum=(((((r-l)>>)+((l-Q&)||(r-Q&)))&)*v)^((r-l+&)*V);
}else{
pd(p,l,r);V^=t[p].y;
int mid=l+r>>;
if (R<=mid) ca(t[p].l,l,mid,L,R,v,V,Q);else
if (L>mid) ca(t[p].r,mid+,r,L,R,v,V,Q);else
ca(t[p].l,l,mid,L,mid,v,V,Q),ca(t[p].r,mid+,r,mid+,R,v,V,Q);
up(p,l,r);
}
}
int main(){
register int i,j;
rx=read();ry=read();n=;
for (i=;i<rx;i++)
for (j=;j<ry;j++) o[i]^=<<(i*ry+j),o[j+rx]^=<<(i*ry+j),q^=read()<<(i*ry+j);
n=read();m=read();
s[bo=num=]=;
for(;bo<=num;){
for (i=;i<rx+ry;i++){
for (j=;j<=num;j++)
if (s[j]==(s[bo]^o[i])) break;
if (j>num) s[++num]=s[bo]^o[i];
to[bo][i]=j;
}
bo++;
}
for (i=;i<;i++) N[i]=-;
for (i=;i<=num;i++) N[s[i]]=i;
num=;
build(ro,,n);
while (m--){
bo=read();
if (bo==) bo=read(),cg(ro,,n,bo,o[read()-]^ask(ro,,n,bo)^(bo==?:ask(ro,,n,bo-)));else
if (bo==) if (bo=read(),x=read(),N[q]==-) puts("");else printf("%d\n",que(ro,,n,bo,x,q));else
if (rx=read(),ry=read(),x=o[read()-],cg(ro,,n,ry+,ask(ro,,n,ry)^(((ry-rx+)&)*x)),ca(ro,,n,rx,ry,x,,rx-),rx-) cg(ro,,n,rx,ask(ro,,n,rx-));
}
}
BZOJ:4333: JSOI2012 智者的考验的更多相关文章
- [BZOJ 4332] [JSOI2012]分零食(DP+FFT)
[BZOJ 4332] [JSOI2012]分零食(DP+FFT) 题面 同学们依次排成了一列,其中有A位小朋友,有三个共同的欢乐系数O,S和U.如果有一位小朋友得到了x个糖果,那么她的欢乐程度就是\ ...
- bzoj 4327: JSOI2012 玄武密码
听说这题不公开.. 那就不贴题意了 一眼看上去还以为是exkmp的裸题.. 看了数据范围,呵呵.. 多串匹配嘛.. 就用AC自动机咯,而且每个点最多也就只有$4$个孩子 用原串在AC自动机上走,碰到的 ...
- bzoj 4330: JSOI2012 爱之项链
听说这题不公开.. 那就不贴题意了 首先要用burnside引理求出戒指的种数,那么对于一个顺时针旋转$k$个位置的置换就相当于连上一条$(i,(i+k)%R)$的边,每个环颜色必须相同 环的个数为$ ...
- 【题解】bzoj 4327 JSOI2012 玄武密码
原题传送门 我们先对所有询问串建立AC自动机(今天洛咕上有人分不清AC自动机和自动AC机) 然后将母串在AC自动机上跑,每走到一个点x,从x点出发沿着fail指针所能到的所有前缀都是匹配成功的,暴力向 ...
- bzoj 4332: JSOI2012 分零食 快速傅立叶变换
题目: Description 同学们依次排成了一列,其中有A位小朋友,有三个共同的欢乐系数O,S和U.如果有一位小朋友得到了x个糖果,那么她的欢乐程度就是\(f(x)=O*x^2+S*x+U\) 现 ...
- BZOJ 4327 JSOI2012 玄武密码(后缀自动机)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=4327 [题目大意] 求每个子串在母串中的最长匹配 [题解] 对母串建立后缀自动机,用每 ...
- BZOJ 4327 [JSOI2012]玄武密码 (AC自动机)
题目链接: https://www.lydsy.com/JudgeOnline/problem.php?id=4327 题解: 做法挺显然,建出AC自动机之后在上面跑,标记所有走过的点,然后再进行递推 ...
- BZOJ 4327: JSOI2012 玄武密码 后缀自动机
Code: #include<bits/stdc++.h> #define setIO(s) freopen(s".in","r",stdin) # ...
- BZOJ 4332: JSOI2012 分零食 FFT+分治
好题好题~ #include <bits/stdc++.h> #define N 50020 #define ll long long #define setIO(s) freopen(s ...
随机推荐
- 解决model 里 NSInteger类型
#import "CJGWCListModel.h" @implementation CJGWCListModel - (NSInteger)goods_number{ if (_ ...
- JavaScript--AJAX页面传值
1.首先 闲话不说 直接代码走起,都是我工作闲事的积累干货 //重要 js 运行 $(function (){ 代码 }); 2.ajax 传值 //第一种 输入框 <input type=&q ...
- 【python】BIF及查看函数帮助
Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 07:18:10) [MSC v.1900 32 bit (Intel)] on win32 Type ...
- Python 爬虫实战(一):使用 requests 和 BeautifulSoup
Python 基础 我之前写的<Python 3 极简教程.pdf>,适合有点编程基础的快速入门,通过该系列文章学习,能够独立完成接口的编写,写写小东西没问题. requests requ ...
- iOS Block的简单使用以及__block 和static修饰变量
简单的代码总结,不足之处多多指教. //简单的使用 -(void)blockOne{ ; int(^BlockOne)(int) = ^(int num2) { return number*num2; ...
- Mybatis-----优化配置文件,基于注解CR
这篇主要写配置文件的优化,例如 jdbc.properties 配置文件 ,引入数据库的文件,例如driver,url,username,password 等,然后在 SqlMapConfig.x ...
- nginx取结构体地址
linux内核提供了一个container_of()宏,可以根据结构体某个成员的地址找到父结构的地址. #define container_of(ptr, type, member) ({ \ con ...
- 转:IT巨头纷纷“卡位” 智能语音成人机交互入口必争之地
http://www.cs.com.cn/xwzx/hwxx/201707/t20170712_5368595.html 随着物联网的迅速发展,作为重要接口的智能语音技术已成为国内外IT巨头的必争之地 ...
- HHVM源码剖析
一.前言 hhvm源码中充满了很多C++11的新特性,并且使用了各种设计模式如工厂,模板方法等,利用智能指针包裹指针,让delete没有肆意的出现 模板,继承,explicit,纯虚函数的出现令代码中 ...
- ExpandableListView的完美实现,JSON数据源,右边自定义图片
转载请标明出处: http://www.cnblogs.com/dingxiansen/p/8194669.html 本文出自:丁先森-博客园 最近在项目中要使用ExpandableListView来 ...