博弈,$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. String和StringBuilder的使用

    如果有理解错误的地方希望有朋友能指出,谢谢!   String是特殊的引用类型的,更像值类型,StringBuilder的是规规矩矩引用类型的.   首先看这样的对比图,Equals()方法是判断两个 ...

  2. 自定义ModelValidatorProvider

    MVC数据验证原理及自定义ModelValidatorProvider实现无编译修改验证规则和错误信息 Asp.net MVC中的提供非常简单易用的数据验证解决方案. 通过System.Compone ...

  3. 关于在Java EE 下开发web,出现项目中的外部包没有tomcat的包的原因

    在新建的项目的时候,要设置目标服务器运行环境,把那个设置成tomcat,这样,项目中就会有tomca的api

  4. MDX示例:求解众数(mode)

    在统计学中,众数(Mode)是样本观测值在频数分布表中频数最多的那一组的组中值,主要应用于大面积普查研究之中,众数在一组数据中可能会有好几个.简单的说,众数就是一组数据中占比例最多的一个或几个数.MD ...

  5. NotePad++安装和配置C/C++开发插件

    NotePad++ - 安装和配置C/C++开发插件 | NotePad++ - Install and Configure plugins for develop C/C++ http://aofe ...

  6. 转--htaccess语法教程 apache服务器伪静态规则教程

    转自:http://blog.csdn.net/qingli518/article/details/9118361 htaccess语法教程apache服务器伪静态规则教程 注:如果你是为了找Disc ...

  7. 图像资源Images Assets

    图像资源Images Assets 开始之前,首先回顾一下iOS7初体验(1)——第一个应用程序HelloWorld中的一张图,如下所示: 本文便分享一下Images.xcassets的体验~_~ 1 ...

  8. php 数组合并方法

    $new = array(); if ($relateddepartmentsnew) { foreach ($relateddepartmentsnew as $relatK=>$relatV ...

  9. Shell 获取当前执行脚本的路径

    filepath=$(cd "$(dirname "$0")"; pwd) 脚本文件的绝对路径存在了环境变量filepath中,可以用 echo $filepa ...

  10. win32多线程-重写消息循环

    最近正在学习<win32多线程程序设计>,这是其中一段重写消息循环的代码事例,以后可能用的上. while (!quit || gNumPrinting > 0) { // Wait ...