博弈,$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. JS函数实现金额小写转大写

    ///<summery>小写金额转化大写金额</summery> function AmountLtoU(amount) { if (isNaN(amount) || amou ...

  2. win32多线程-异步过程调用(asynchronous Procedure Calls, APCs)

    使用overlapped I/O并搭配event对象-----win32多线程-异步(asynchronous) I/O事例,会产生两个基础性问题. 第一个问题是,使用WaitForMultipleO ...

  3. 发挥jQuery的威力

    发挥jQuery的威力 由于当前jQuery如此的如雷贯耳,相信不用介绍什么是jQuery了,公司代码中广泛应用了jQuery,但我在看一些小朋友的代码时发现一个问题,小朋友们使用的仅仅是jQuery ...

  4. Cocos2d学习之路五(Box2d使用CCPhysicsSprite时编译不通过解决方法)

    cocos2d使用box2d引擎,在使用CCPhysicsSprite添加精灵的时候会出现编译不通过错误. 需要注意以下几点: 1.sprite.position=ccp(p.x,p.y);这行代码一 ...

  5. sql 通过存储过程和自定义类型批量新增数据

    1,建立存储过程 create PROCEDURE [dbo].[p_Company_Insert] @CompanyCollection [CompanyTableType] READONLY AS ...

  6. Win32_Battery class

    wmi的Win32_Battery类实现 其中EstimatedChargeRemaining属性返回剩余电量的百分比,EstimatedRunTime属性返回剩余时间(分钟) 其他属性参考http: ...

  7. VS2003与Win7的兼容性问题

    VS2003并不官方支持Win7,目前大家遇到的主要是两个问题: 1. 在debug的时候,*.pdb文件在会被devenv.exe给lock住,当调适过一次之后,再进行编译的时候会有lnk1201的 ...

  8. cubieboard 配置WIFI

    1.先装好驱动程序 2.ifconfig查看无线网卡的名称,比如 3.修改/etc/networking/interfaces,配置 wpa-essid填写WIFI名称 wpa-psk填写密码 4. ...

  9. Lucene学习-深入Lucene分词器,TokenStream获取分词详细信息

    Lucene学习-深入Lucene分词器,TokenStream获取分词详细信息 在此回复牛妞的关于程序中分词器的问题,其实可以直接很简单的在词库中配置就好了,Lucene中分词的所有信息我们都可以从 ...

  10. .NET程序集1

    谈谈.NET程序集(一) 谈谈.NET程序集(一) The Assembly in .NET by 唐小崇 http://www.cnblogs.com/tangchong 在.NET出现之前, Wi ...