题目描述

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. 项目案例之Pipeline流水线及流水线发布PHP项目(二)

    项目案例之Pipeline流水线及流水线发布PHP项目(二) 链接:https://pan.baidu.com/s/1NZZbocZuNwtQS0eGkkglXQ 提取码:z7gj 复制这段内容后打开 ...

  2. 使用eclipse开发java web网页

    前面说了手动配置一个应用,手动配置可以更深入的理解web应用的分布,但是一般的编辑器没有语法错误提示,所以开发起来对于错误的寻找不太容易,效率相对较低,所以在理解清楚web项目的结构之后,我们使用ec ...

  3. elasticsearch依赖的jackson-jar包与jboss依赖的jackson-jar包“版本”冲突

    elasticsearch依赖的jackson-jar包与jboss依赖的jackson-jar包“版本”冲突,导致elasticsearch相关功能在本地tomcat服务器正常,但是部署到jboss ...

  4. mac MAMP安装redis扩展

    一般情况下目录大概是一样的,只是php的版本不同,所以选择好自己对应的php版本目录即可 git clone https://github.com/nicolasff/phpredis.git cd ...

  5. leetcode-160周赛-5241-铺瓷砖

    题目描述: 方法一:动态规划 class Solution: def f(self, n, m): if n < m: n, m = m, n if (n, m) in self.mem: re ...

  6. delphi 设备函数GetDeviceCaps函数

    {说明:以下内容来源于网络,修改多处错误所得 2019.10.04 } GetDeviceCaps 函数功能:该函数检索指定设备的设备指定信息.该函数经常用在操作打印机等设备中.函数原型:int Ge ...

  7. (微服务架构)Security + Oauth2 + Jwt + Zuul解决微服务系统的安全问题

    前言 之前零零散散的学习过一点鉴权这方面的玩意儿,但自我感觉净他妈整些没用的,看代码还是看不懂,这次我们再统一对其进行学习一下,希望自己掌握这个技能,也希望屏幕面前的你能有点收获 此次的学习周期可能有 ...

  8. 批量更新数据(BatchUpdate)

    批量更新数据(BatchUpdate) /// <summary> /// 批量更新数据,注意:如果有timestamp列,要移除 /// </summary> /// < ...

  9. Android中对TextView中的部分内容的字体样式的设置方法

    Android中的TextView中内容,有时候需要对其部分内容添加下划线和颜色操作: String str = "回复 " + uname + " 的评论: " ...

  10. renren-fast-vue-动态路由-添加路由-方式一(直接在原有结构上添加)

    在原有文件夹夹下新建自己的组件 在 mock/modules/sys-menu.js 中引入 实现路由的添加