FZU 2240 Daxia & Suneast's problem
博弈,$SG$函数,规律,线段树。
这个问题套路很明显,先找求出$SG$函数值是多少,然后异或起来,如果是$0$就后手赢,否则先手赢。修改操作和区间查询的话可以用线段树维护一下区间异或和。
数据那么大,一看就知道$SG$有规律......
先写个小数据的$SG$找规律:
bool f[];
int sg[]; int SG(int x)
{
memset(f,,sizeof f);
for(int i=x-;i>=x/;i--)
{
if(x-i>i) break;
f[sg[i]]=;
}
for(int i=;i<=;i++)
{
if(f[i]==) continue;
return i;
}
}
会发现是这样的东西:
LL SG(LL x)
{
if(x%==) return x/;
return SG(x/);
}
注意:$FZU$上$\% lld$会出问题,我用Visual C++交才过的。
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-;
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
}
template <class T>
inline void read(T &x)
{
char c = getchar(); x = ;while(!isdigit(c)) c = getchar();
while(isdigit(c)) { x = x * + c - ''; c = getchar(); }
} LL SG(LL x)
{
if(x%==) return x/;
return SG(x/);
} const int maxn=;
int n,m;
LL s[*maxn]; void build(int l,int r,int rt)
{
s[rt]=;
if(l==r)
{
scanf("%lld",&s[rt]);
s[rt]=SG(s[rt]);
return;
}
int m=(l+r)/;
build(l,m,*rt);
build(m+,r,*rt+);
s[rt]=s[*rt]^s[*rt+];
} void update(int p,LL v,int l,int r,int rt)
{
if(l==r) { s[rt]=v; return;} int m=(l+r)/;
if(p<=m) update(p,v,l,m,*rt);
else update(p,v,m+,r,*rt+); s[rt]=s[*rt]^s[*rt+];
} LL get(int L,int R,int l,int r,int rt)
{
if(L<=l&&r<=R) return s[rt];
int m=(l+r)/; LL x1=,x2=;
if(L<=m) x1=get(L,R,l,m,*rt);
if(R>m) x2=get(L,R,m+,r,*rt+); return x1^x2;
} int main()
{
while(~scanf("%d%d",&n,&m))
{
build(,n,);
for(int i=;i<=m;i++)
{
int p,L,R; LL x;
scanf("%d%lld%d%d",&p,&x,&L,&R);
x=SG(x); update(p,x,,n,);
LL y=get(L,R,,n,);
if(y) printf("daxia\n");
else printf("suneast\n");
}
}
return ;
}
FZU 2240 Daxia & Suneast's problem的更多相关文章
- FZU 2238 Daxia & Wzc's problem
公式. $a×C_{m + i - 1}^m + d×C_{m + i - 1}^{m + 1}$. 推导过程可以看http://blog.csdn.net/queuelovestack/articl ...
- FZU 8月有奖月赛A Daxia & Wzc's problem (Lucas)
Problem A Daxia & Wzc's problem Accept: 42 Submit: 228Time Limit: 1000 mSec Memory Limit : ...
- FZU Problem 2238 Daxia & Wzc's problem
Daxia在2016年5月期间去瑞士度蜜月,顺便拜访了Wzc,Wzc给他出了一个问题: Wzc给Daxia等差数列A(0),告诉Daxia首项a和公差d; 首先让Daxia求出数列A(0)前n项和,得 ...
- 【数论】FOJ 2238 Daxia & Wzc's problem
题目链接: http://acm.fzu.edu.cn/problem.php?pid=2238 题目大意: 已知等差数列A(0)的首项a和公差d,求出数列A(0)前n项和,得到新数列A(1);以此类 ...
- FZU 2224 An exciting GCD problem(GCD种类预处理+树状数组维护)同hdu5869
题目链接:http://acm.fzu.edu.cn/problem.php?pid=2224 同hdu5869 //#pragma comment(linker, "/STACK:1024 ...
- Problem 2238 Daxia & Wzc's problem 1627 瞬间移动
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1627 http://acm.fzu.edu.cn/problem.php ...
- FZU - 2038 -E - Another Postman Problem (思维+递归+回溯)
Chinese Postman Problem is a very famous hard problem in graph theory. The problem is to find a shor ...
- FZU 2243 Daxia like uber
枚举,最短路. 求出5个点出发的最短路,然后枚举一下这些点之间走的顺序. #pragma comment(linker, "/STACK:1024000000,1024000000" ...
- Suneast & Daxia (规律)
Suneast & Daxia Time Limit: 1000MS Memory Limit: 32768KB 64bit IO Format: %I64d & %I64u ...
随机推荐
- SHELL编程笔记(二)之shell流程控制
Shell控制流程结构 本章内容有: 退出状态 While.for和until loops循环 If then else语句 脚本中动作 菜单 条件控制语句 If then els ...
- CSS盒模型和定位的类型
此文根据Steven Bradley的<How Well Do You Understand CSS Positioning?>所译,整个译文带有我自己的理解与思想,如果译得不好或不对之处 ...
- mac os 上安装mysqldb血泪史
昨天下午在mac上安装mysql-python一直未遂今天查了很多资料终于成功了 最后还是在stackoverflow点击打开链接(好网站啊,一般有什么技术问题在这都能找到)上找到了答案,废话少数: ...
- 揭开redis神秘面纱
一直听别人说NoSQL,以前一直不明白,这到底是什么东西,今天听过我们涛哥的讲解,略有小感,特此小记. NoSQL(NoSQL = Not Only SQL),意为反SQL运动,是一项全新的数据库革命 ...
- AOP的成员介绍
AOP(Aspect Oriented Programming)面向切面编程,AOP的作用不过多介绍,本文是主要是介绍AOP的成员,是我在复习的时候记录的一些笔记,方便以后查阅方便一些. JointP ...
- 总结C++中取成员函数地址的几种方法
这里, 我整理了4种C++中取成员函数地址的方法, 第1,2,4种整理于网上的方法, 第3种cdecl_cast是我自己想到的. 其中, 第4种(汇编)的方法不能在VC6上编译通过. 推荐使用第1,2 ...
- WCF 学习笔记之异常处理
WCF 学习笔记之异常处理 1:WCF异常在配置文件 <configuration> <system.serviceModel> <behaviors> <s ...
- 40w会议投票系统优化方案
40w会议投票系统优化方案 最近2天谈了一个项目,根据提出的需求是,该系统本来是属于一个大系统的分割出来的一个很小的系统,但是由于是并发关系会耗费资源很大,所以分割出来.据了解,系统采用的mysql+ ...
- python 调用 bash (python 调用linux命令)
原文这里有显示地址:http://zhou123.blog.51cto.com/4355617/1312791 现在摘取一部分: 这里介绍一下python执行shell命令的四种方法: 1.os模块中 ...
- zoj 1610 Count the Colors(线段树延迟更新)
所谓的懒操作模板题. 学好acm,英语很重要.做题的时候看不明白题目的意思,我还拉着队友一块儿帮忙分析题意.最后确定了是线段树延迟更新果题.我就欣欣然上手敲了出来. 然后是漫长的段错误.... 第一次 ...