杭电多校第三场-H-Game
题目描述
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*.
输入
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 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的更多相关文章
- 2018 Multi-University Training Contest 3 杭电多校第三场
躺了几天 终于记得来填坑了 1001 Ascending Rating (hdoj 6319) 链接:http://acm.hdu.edu.cn/showproblem.php?pid=6319 ...
- 2018杭电多校第三场1003(状态压缩DP)
#include<bits/stdc++.h>using namespace std;const int mod =1e9+7;int dp[1<<10];int cnt[1& ...
- 2019年杭电多校第三场 1011题Squrirrel(HDU6613+树DP)
题目链接 传送门 题意 给你一棵无根树,要你寻找一个根节点使得在将一条边权变为\(0\)后,离树根最远的点到根节点的距离最小. 思路 本题和求树的直径很像,不过要记得的东西有点多,且状态也很多. \( ...
- 2019杭电多校第三场hdu6608 Fansblog(威尔逊定理)
Fansblog 题目传送门 解题思路 Q! % P = (P-1)!/(P-1)...(Q-1) % P. 因为P是质数,根据威尔逊定理,(P-1)!%P=P-1.所以答案就是(P-1)((P-1) ...
- 2019杭电多校第三场hdu6609 Find the answer(线段树)
Find the answer 题目传送门 解题思路 要想变0的个数最少,显然是优先把大的变成0.所以离散化,建立一颗权值线段树,维护区间和与区间元素数量,假设至少减去k才能满足条件,查询大于等于k的 ...
- 2019杭电多校第三场hdu6606 Distribution of books(二分答案+dp+权值线段树)
Distribution of books 题目传送门 解题思路 求最大值的最小值,可以想到用二分答案. 对于二分出的每个mid,要找到是否存在前缀可以份为小于等于mid的k份.先求出这n个数的前缀和 ...
- 杭电多校第三场 A Ascending Rating
Problem Description Before the start of contest, there are n ICPC contestants waiting in a long queu ...
- 2019年杭电多校第三场 1008题Game(HDU6610+带修改莫队+Nim博弈)
题目链接 传送门 题意 给你\(n\)堆石子,每堆有\(a_i\)堆石子,\(q\)次操作: 在\([L,R]\)内有多少个子区间使得\(Alice\)(先手)在\(Nim\)博弈中获胜: 交换\(a ...
- [2019杭电多校第三场][hdu6609]Find the answer(线段树)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6609 大致题意是求出每个位置i最小需要将几个位置j变为0(j<i),使得$\sum_{j=1}^ ...
随机推荐
- 忘记root密码
Ubuntu密码恢复的方法如下: 1.重新启动,按ESC键进入Boot Menu,选择recovery mode(一般是第二个选项).2.在#号提示符下用cat /etc/shadow,看看用户名.3 ...
- 使用Nuget重新安装packages.config中的组件的方法
Update-Package -ProjectName 'Ko.app.web' -Reinstall 该语句作用:按照packages.config中给出的程序组件,重新下载安装一遍.
- stat - 打印信息节点(inode)内容
SYNOPSIS(总览) stat filename [filenames ... ] DESCRIPTION(描述) stat 打印出一个信息节点的内容,它们显示为对人可读的格式的stat(2). ...
- Linux主机名的修改以及配置
查询主机名: [root@localhost ~]# hostnamelocalhost.localdomain [root@localhost ~]# vim /etc/sysconfig/netw ...
- KiCAD批量修改丝印大小
KiCAD批量修改丝印大小 1.编辑->编辑文本与图片属性 2.范围 选择封装参考,活动 首选选择 “设定为指定值”,然后选择要修改的层,输入想要修改的参数 注意:文本高度与文本宽度比例要适中, ...
- 关于KiCAD
关于KiCAD 使用背景 一直以来公司都在用AD作为EDA软件,但是最近公司频繁收到律师函,所以决定找一款开源的软件来代替AD,目前市场上开源的只找到了KiCAD和Easy EDA(中文版立创EDA) ...
- python smtp发邮件报错“[Errno -2] Name or service not known”的解决
最近给ss-py-mu写了个检查用户是否到期,并在到期前的第2天邮件提醒的功能. 配置存储在ini文件中,通过configparser模块获取,但尝试发送邮件的时候发现报错[Errno -2] Nam ...
- oracle number 类型 只显示10位精度
,) show numwidth; 设置为15位 ; xa ------------------ 123456789012.12 或者 TO_CHAR(xa,'FM099999999999.09999 ...
- vue 点击切换图标
<div @click="showImg" class="showSearch"> <img class="header_img&q ...
- linux磁盘空间占用分析
df -h # 查看目前磁盘空间占用 cd / # 切换到根目录 du -sh # 查询每个目录占用的大小 lsof | grep delete # 查看当前系统打开文件 # 删除不使用的文件, 如果 ...