题目描述

Again Alice and Bob is playing a game with stones. There are N piles of stones labelled from 1 to N, the i th pile has ai stones.

First Alice will choose piles of stones with consecutive labels, whose leftmost is labelled with L and the rightmost one is R. After, Bob will choose another consecutive piles labelled from l to r (L≤l≤r≤R). Then they're going to play game within these piles.

Here's the rules of the game: Alice takes first and the two will take turn to make a move: choose one pile with nonegetive stones and take at least one stone and at most all away. One who cant make a move will lose.

Bob thinks this game is not so intersting because Alice always take first. So they add a new rule, which is that Bob can swap the number of two adjacent piles' stones whenever he want before a new round. That is to say, if the i th and i+1 pile have ai and ai+1 stones respectively, after this swapping there will be ai+1 and ai.

Before today's game with Bob, Alice wants to know, if both they play game optimally when she choose the piles from L to R, there are how many pairs (l, r) chosed by Bob that will make Alice *win*.

输入

Input contains several test cases.

For each case:

The fisrt line contains N, M. N is mentioned aboved ans M is the number of the sum of game rounds and the times of Bob's swapping.

The second line contains N integars a1,a2,...an, indicating the number of each piles' stones.

The next M lines will have an integar opt (1≤opt≤2), indicating the type of operation.

If opt equals 1, then L and R follow. Alice and Bob start a new round and Alice choose L and R as mentioned.

If opt equals 2, then POS follows. Bob will swap the piles labelled POS and POS+1.

0≤ai≤1,000,000

1≤N,M≤100,000,∑N,∑M<600,000

1≤L≤R≤N

1≤POS<N

输出

For each case:

For each opt which equals 1, you shall output one line with an integar indicating the number of pairs (l,r) that will make Alice win the round.

题意:
看起来是个博弈,但是分析下来发现题意就是让你找[L,R]区间内有多少个[l,r]满足al^a(l+)^...^ar!=,那不就是莫队吗
然后发现还要支持修改,每次选择一个位置pos,将a[pos]和a[pos+]交换
那不就不会了吗 三维莫队,即带修改的莫队
在普通的莫队上增加一维版本号,对询问排序时,先按块排,再按版本号排
更新的时候,先更新版本,再更新区间
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1e6+;
int T,n,m;
int block;
ll tot;
struct orz{
int l,r,t,id;
bool operator < (const orz &x) const
{
if (l/block==x.l/block)
{
if (r/block==x.r/block) return t<x.t;
return r<x.r;
}
return l/block<x.l/block;
}
}p[N];
int a[N],val[N],c[N],sum[N*];
ll ans[N];
inline int read()
{
int x=;char ch=getchar();
while(ch<''||ch>''){ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x;
}
void Go(int l,int r,int i)
{
int pos=c[i]; //cout<<pos<<endl;
if (pos>=l&&pos<=r)
{
sum[val[pos]]--;
tot-=sum[val[pos]];
}
val[pos]^=a[pos]; val[pos]^=a[pos+];
if (pos>=l&&pos<=r)
{
tot+=sum[val[pos]];
sum[val[pos]]++;
}
swap(a[pos],a[pos+]);
//for (int i=1;i<=n;i++) cout<<val[i]<<' '; cout<<endl;
} void add(int x)
{
tot+=sum[x];sum[x]++;
}
void del(int x)
{
sum[x]--;tot-=sum[x];
}
int main()
{
// freopen("00.in","r",stdin);
// freopen("1.out","w",stdout);
while (scanf("%d%d",&n,&m)!=EOF)
{
int ti=,cnt=;
for (int i=;i<=n;i++) a[i]=read(),val[i]=val[i-]^a[i];
//for (int i=1;i<=n;i++) cout<<val[i]<<' '; cout<<endl;
int op,x,y;
for (int i=;i<=m;i++)
{
op=read();
if (op==)
{
x=read(); y=read();
p[++cnt].l=x-; p[cnt].r=y; p[cnt].t=ti; p[cnt].id=cnt;
}
else
{
c[++ti]=read();
}
} block=pow(n,2.0/3.0);
sort(p+,p++cnt); // sum[0]++;
int l=,r=,t=; tot=;
for(int i=;i<=cnt;i++)
{
while (t<p[i].t) Go(l,r,++t);
while (t>p[i].t) Go(l,r,t--); //cout<<t<<endl;
while (l>p[i].l) add(val[--l]);
while (l<p[i].l) del(val[l++]);
while (r<p[i].r) add(val[++r]);
while (r>p[i].r) del(val[r--]);
ll len=p[i].r-p[i].l; //cout<<len<<' '<<tot<<endl;
ans[p[i].id]=len*(len-)/+len-tot;
} for (int i=;i<=cnt;i++) printf("%lld\n",ans[i]);
for (int i=;i<=n;i++) sum[val[i]]=;
}
// fclose(stdin);
// fclose(stdout);
return ;
}

杭电多校第三场-H-Game的更多相关文章

  1. 2018 Multi-University Training Contest 3 杭电多校第三场

    躺了几天 终于记得来填坑了 1001 Ascending Rating   (hdoj 6319) 链接:http://acm.hdu.edu.cn/showproblem.php?pid=6319 ...

  2. 2018杭电多校第三场1003(状态压缩DP)

    #include<bits/stdc++.h>using namespace std;const int mod =1e9+7;int dp[1<<10];int cnt[1& ...

  3. 2019年杭电多校第三场 1011题Squrirrel(HDU6613+树DP)

    题目链接 传送门 题意 给你一棵无根树,要你寻找一个根节点使得在将一条边权变为\(0\)后,离树根最远的点到根节点的距离最小. 思路 本题和求树的直径很像,不过要记得的东西有点多,且状态也很多. \( ...

  4. 2019杭电多校第三场hdu6608 Fansblog(威尔逊定理)

    Fansblog 题目传送门 解题思路 Q! % P = (P-1)!/(P-1)...(Q-1) % P. 因为P是质数,根据威尔逊定理,(P-1)!%P=P-1.所以答案就是(P-1)((P-1) ...

  5. 2019杭电多校第三场hdu6609 Find the answer(线段树)

    Find the answer 题目传送门 解题思路 要想变0的个数最少,显然是优先把大的变成0.所以离散化,建立一颗权值线段树,维护区间和与区间元素数量,假设至少减去k才能满足条件,查询大于等于k的 ...

  6. 2019杭电多校第三场hdu6606 Distribution of books(二分答案+dp+权值线段树)

    Distribution of books 题目传送门 解题思路 求最大值的最小值,可以想到用二分答案. 对于二分出的每个mid,要找到是否存在前缀可以份为小于等于mid的k份.先求出这n个数的前缀和 ...

  7. 杭电多校第三场 A Ascending Rating

    Problem Description Before the start of contest, there are n ICPC contestants waiting in a long queu ...

  8. 2019年杭电多校第三场 1008题Game(HDU6610+带修改莫队+Nim博弈)

    题目链接 传送门 题意 给你\(n\)堆石子,每堆有\(a_i\)堆石子,\(q\)次操作: 在\([L,R]\)内有多少个子区间使得\(Alice\)(先手)在\(Nim\)博弈中获胜: 交换\(a ...

  9. [2019杭电多校第三场][hdu6609]Find the answer(线段树)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6609 大致题意是求出每个位置i最小需要将几个位置j变为0(j<i),使得$\sum_{j=1}^ ...

随机推荐

  1. 【足迹C++primer】47、Moving Objects(2)

    版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/cutter_point/article/details/37954805 Moving Object ...

  2. 视频专家之路【三】:Vs开发环境的搭建

    本文是听了雷宵骅大神的课之后的总结,部分内容借用了其PPT的内容,如有侵权请告知删除. 雷宵骅大神的博客为:https://blog.csdn.net/leixiaohua1020 这里提及一点,原来 ...

  3. 解决mybatisplus saveBatch 或者save 无法插入主键问题

    解决mybatisplus saveBatch 或者save 无法插入主键问题 通过跟踪源码后得出结论,由于插入的表的主键不是自增的,而是手动赋值的,所以在调用saveBatch 执行的sql语句是没 ...

  4. list集合获取相同以及不同的对象

    List<StyleMenuModule> list1 = new ArrayList<>(); StyleMenuModule s1 = new StyleMenuModul ...

  5. 启动AutoCAD时自动加载.NET开发的DLL

    程序组织,建立名为*.bundle的文件夹,创建Contents子文件夹,并将dll,ico等文件放进Contents中,在*.bundle中创建PackageContents.xml文件,内容如下: ...

  6. window.navigator.userAgent

    只读属性 Window.navigator 会返回一个 Navigator 对象的引用,可以用于请求运行当前代码的应用程序的相关信息.window可以省略.来自navigator对象的信息具有误导性, ...

  7. Vue学习笔记【9】——Vue指令之v-for和key属性

    迭代数组(普通数组.对象数组) <ul> <li v-for="(item, i) in list">索引:{{i}} --- 姓名:{{item.name ...

  8. 【转】java即时消息推送

    整个例子的源码下载:http://pan.baidu.com/s/1gfFYSbp 下载服务端jar文件 Comet4J目前仅支持Tomcat6.7版本,根据您所使用的Tomcat版本下载[comet ...

  9. 搭建基于Linux6.3+Nginx1.2+PHP5+MySQL5.5的Web服务器全过程

    http://blog.chinaunix.net/uid-20639775-id-154497.html

  10. Repeatable Read

    在Repeatable Read隔离级别下,一个事务可能会遇到幻读(Phantom Read)的问题. 幻读是指,在一个事务中,第一次查询某条记录,发现没有,但是,当试图更新这条不存在的记录时,竟然能 ...