杭电多校第三场-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}^ ...
随机推荐
- java虚拟机规范(se8)——java虚拟机结构(六)
2.11 指令集简介 java虚拟机指令由一个字节的操作码,接着时0个或多个操作数组成,操作码描述了执行的操作,操作数提供了操作所需的参数或者数据.许多指令没有操作数只包含一个操作码. 如果忽略异常处 ...
- vue-cli3使用cdn引入
1. index.html引入: <script src="https://cdn.bootcss.com/moment.js/2.20.1/moment.min.js"&g ...
- Java面试宝典(1)Java基础部分
Java面试宝典 题目,日积月累,等到出去面试时,一切都水到渠成,面试时就自然会游刃有余了. 答题时,先答是什么,再答有什么作用和要注意什么(这部分最重要,展现自己的心得) 答案的段落分别,层次分明, ...
- 《node.js开发指南》partial is not defined的解决方案
由于ejs的升级,<node.js开发指南>中使用的 partial 函数已经摒弃,使用foreach,include代替 原来的代码是: <%- partial('listitem ...
- String转list
String l = "63, 47, 51, 35, 36, 52, 37, 53, 38, 54, 39, 55, 40, 56, 41, 57, 42";List<In ...
- grpc协议--客户端构造
由于服务端不在构造,已经构造完成不做构造 gRPC 接口名字为service,proto文件内有定义 1.本目录生成grpc文件 python -m grpc_tools.protoc -I. --p ...
- vue全家桶(vue2.x+vue-router+axios+webpack)项目搭建
参考博客文章 博主FungLeo的Vue2+VueRouter2+Webpack+Axios 构建项目实战2017重制版 注:原博主写的非常详细 本文章为根据原博主教程总结的自己的搭建流程 一.安装n ...
- 转载 如何理解API,API 是如何工作的
本文转载于https://blog.csdn.net/cumtdeyurenjie/article/details/80211896 感谢作者 仁杰兄 大家可能最近经常听到 API 这个概念,那什么是 ...
- asp.net core Mvc 增删改查
1.创建项目 创建Data文件夹 创建实体类Students/cs public class Students { public Guid Id { get; set; } public string ...
- SQL复制数据表及表结构
select * into 目标表名 from 源表名 insert into 目标表名(fld1, fld2) select fld1, 5 from 源表名 以上两句都是将'源表'的数据插入到'目 ...