博弈,$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的更多相关文章

  1. 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 ...

  2. FZU 8月有奖月赛A Daxia & Wzc's problem (Lucas)

    Problem A Daxia & Wzc's problem Accept: 42    Submit: 228Time Limit: 1000 mSec    Memory Limit : ...

  3. FZU Problem 2238 Daxia & Wzc's problem

    Daxia在2016年5月期间去瑞士度蜜月,顺便拜访了Wzc,Wzc给他出了一个问题: Wzc给Daxia等差数列A(0),告诉Daxia首项a和公差d; 首先让Daxia求出数列A(0)前n项和,得 ...

  4. 【数论】FOJ 2238 Daxia & Wzc's problem

    题目链接: http://acm.fzu.edu.cn/problem.php?pid=2238 题目大意: 已知等差数列A(0)的首项a和公差d,求出数列A(0)前n项和,得到新数列A(1);以此类 ...

  5. FZU 2224 An exciting GCD problem(GCD种类预处理+树状数组维护)同hdu5869

    题目链接:http://acm.fzu.edu.cn/problem.php?pid=2224 同hdu5869 //#pragma comment(linker, "/STACK:1024 ...

  6. Problem 2238 Daxia & Wzc's problem 1627 瞬间移动

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1627 http://acm.fzu.edu.cn/problem.php ...

  7. 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 ...

  8. FZU 2243 Daxia like uber

    枚举,最短路. 求出5个点出发的最短路,然后枚举一下这些点之间走的顺序. #pragma comment(linker, "/STACK:1024000000,1024000000" ...

  9. Suneast & Daxia (规律)

    Suneast & Daxia Time Limit: 1000MS   Memory Limit: 32768KB   64bit IO Format: %I64d & %I64u ...

随机推荐

  1. 算法打基础——HashTable

    这一节主要讲很多方面非常重要的hash table等问题. 由于平时很少用到这些,基本都忘了... 怎样快速的在内存中插入.删除.和搜索呢? 这就需要哈希表了 这一节主要知识点是:1 简单的映射表和处 ...

  2. [原]Escape From the iOS Sanbox on Jailbreak Device

    just my thinking, 3 ways to escape from sandbox on jailbreak device, to do file copying or execute s ...

  3. start running 开始跑步减肥

    begin 两个月前,逛超市的时候站在体重秤上称了称,一直以为自己体重很正常(BMI<25,虽然也不轻~~~),结果直接迈过超重,奔着肥胖跑去了(BMI>30,BMI计算器 http:// ...

  4. 如何使用ssh

    如何使用ssh自己的笔记本做不了我的运算,只能依靠办公室的工作站,有时很不方便.所以做了一次远程监控.本想用vnc的,发现怎么都连不上,算了.还是SSH好用.工作站和笔记本都是fedora系统,所以默 ...

  5. boost xpressive 例子

    1.效果图: 我有一个wordpress博客,每次在csdn上写完博客,都需要复制到wordpress中,还需要手动修改<pre>和图片地址,比较麻烦,所以做了这个工具. 功能: 1.把C ...

  6. [Android笔记1]Activity+Layout+Button

    线性布局(LinearLayout)是指view对象在父view中可按水平或垂直方向线性排列. 相对布局(RelativeLayout)是指view对象的排列依赖于各对象之间的相对位置. 下面是展示两 ...

  7. hadoop-1.1.0 rpm + centos 6.3 64虚拟机 + JDK7 搭建分布式集群

    第一步 ,环境准备.  宿主机为CentOS6.3 64位,3个虚拟机为CentOS6.3 64位. (注意:有个技巧,可以先创建一台虚拟机,在其上安装好JDK.hadoop后再克隆两台,这样省时又省 ...

  8. PRJ: Split a nodes-map into some triangles

    PRJ: Split a nodes-map into some triangles Share the source codes of this algorithm to your guys... ...

  9. Magnum Kuernetes源码分析(二)

    Kubernetes Master Stack kubernetes master的stack的resources主要分为三个部分. master wait handle wait handle主要用 ...

  10. redis 学习笔记——redis集群

    redis-cluster 简介 redis-cluster是一个分布式.容错的redis实现,redis-cluster通过将各个单独的redis实例通过特定的协议连接到一起实现了分布式.集群化的目 ...