题目描述

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. call和apply实现的继承

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  2. tooltip(提示框)组件

    一.class加载方式 <span id="pos" class="easyui-tooltip" title="这是提示内容"> ...

  3. php 时间转化为刚刚、几秒前、几分前、几天前等等,友好时间提示

    / * 友好时间显示 */ function date_friend_tips($time){ if (!$time) return false; if(!is_numeric($time)){ $t ...

  4. 【转载】vue install报错run `npm audit fix` to fix them, or `npm audit` for details html

    原链接https://www.jianshu.com/p/60591cfc6952 执行npm install 出现如下提醒 added 253 packages from 162 contribut ...

  5. KiCAD的一些快捷操作(类比于AD)

    一.原理图快捷操作 二.PCB快捷操作 Q: 在布线过程中,用来编辑线宽,和AD中布线时“Tab”的作用相似 W: 选择设定好的线宽,线宽减小 Shift+W: 选择设定好的线宽,线宽变大 /: 改变 ...

  6. 神奇的Android Studio Template(转)

    转自:http://blog.csdn.net/lmj623565791/article/details/51592043 本文已授权微信公众号:鸿洋(hongyangAndroid)在微信公众号平台 ...

  7. mutable and immutable

    employees = ['Corey', 'John', 'Rick', 'Steve', 'Carl', 'Adam'] output = '<ul>\n' for employee ...

  8. 【在线工具】java开发常用在线工具

    转自:常用工具页面 Java源代码搜索 Grepcode是一个面向于Java开发人员的网站,在这里你可以通过Java的projects.classes等各种关键字在线查看它对应的源码,知道对应的pro ...

  9. 数学思维——cf351A

    把每个值的各种贡献算一下即可 /* ai的小数部分为xi,向下取整对答案贡献为xi 向上取整对答案的贡献是xi-1,如果这个数是0,那么对答案的贡献是xi,即如果0向上取整就可以免去-1 然后sum{ ...

  10. shiro入门笔记之第一个demo创建

    前言 看到这篇文章之前,可能很多小伙伴都没听过shiro,那么shiro是什么呢?shiro是Apache基金会下一个非常有名的开源项目(项目官网: http://shiro.apache.org/ ...