The 2019 ICPC China Nanchang National Invitational and International Silk-Road Programming Contest - F.Sequence(打表+线段树)
题目链接:Sequence
题意:给你一个长度为$n$的数组,定义函数$f(l,r)=a_{l} \oplus a_{l+1} \oplus...\oplus a_{r}$,$F(l,r)=f(l,l)\oplus f(l,l+1)\oplus ...\oplus f(l,r)\oplus f(l+1,l+1)\oplus ...f(l+1,r)\oplus ...\oplus f(r,r)$,有两种操作,第一种将数组中某个元素$a[x]$变为$y$,第二种计算$F(l,r)$的值。
思路:打表后发现只有当$l$和$r$同时为奇数或者偶数时$F(l,r)$才不为$0$,其他情况下$F(l,r)$都为$0$,并且$F(l,r)=a[l]\oplus a[l+2]\oplus ...\oplus a[r-2]\oplus a[r]$,由于涉及到修改和查询两种操作,所以用线段树来维护,每个结点维护两个值:$w$表示区间内奇数项异或的结果,$ww$表示区间内偶数项异或的结果。
初始建树时
- 当前项为奇数项,则输入$tree[k].w$的值,同时令$tree[k].ww=0$
- 当前项为偶数项,则输入$tree[k].ww$的值,同时令$tree[k].w=0$
修改操作时
- 需要修改的项为奇数项,则对$tree[k].w$进行修改
- 需要修改的项为偶数项,则对$tree[k].ww$进行修改
查询操作时
- 如果$l$为奇数,则用$ans=ans\oplus tree[k].w$来更新答案
- 如果$l$为偶数,则用$ans=ans\oplus tree[k].ww$来更新答案
#include <iostream>
#include <cstdio> using namespace std; const int N = ; struct node {
int l, r, w, ww;
}; int a, b, x, y, ans;
node tree[ * N]; void build(int k, int lef, int rig)
{
tree[k].l = lef, tree[k].r = rig;
if (tree[k].l == tree[k].r) {
if ( == tree[k].l % ) {
tree[k].w = , scanf("%d", &tree[k].ww);
}
else {
tree[k].ww = , scanf("%d", &tree[k].w);
}
return;
}
int mid = (lef + rig) / ;
build(k * , lef, mid); build(k * + , mid + , rig);
tree[k].w = tree[k * ].w ^ tree[k * + ].w;
tree[k].ww = tree[k * ].ww ^ tree[k * + ].ww;
} void change_point(int k)
{
if (tree[k].l == tree[k].r) {
if (tree[k].l % == ) tree[k].ww = y;
else tree[k].w = y;
return;
}
int mid = (tree[k].l + tree[k].r) / ;
if (x <= mid) change_point( * k);
else change_point( * k + );
tree[k].w = tree[ * k].w ^ tree[ * k + ].w;
tree[k].ww = tree[ * k].ww ^ tree[ * k + ].ww;
} void ask_interval(int k)
{
if (tree[k].l >= a && tree[k].r <= b) {
if ( == a % ) ans ^= tree[k].ww;
else ans ^= tree[k].w;
return;
}
int mid = (tree[k].l + tree[k].r) / ;
if (a <= mid) ask_interval( * k);
if (b > mid) ask_interval( * k + );
} int main()
{
int T, t, n, q, icas = ;
scanf("%d", &T);
while (T--) {
printf("Case #%d:\n", ++icas);
scanf("%d%d", &n, &q), build(, , n);
while (q--) {
scanf("%d", &t);
if ( == t) {
scanf("%d%d", &x, &y);
change_point();
}
else {
ans = , scanf("%d%d", &a, &b);
if (a % == b % ) ask_interval();
printf("%d\n", ans);
}
}
}
return ;
}
The 2019 ICPC China Nanchang National Invitational and International Silk-Road Programming Contest - F.Sequence(打表+线段树)的更多相关文章
- The 2019 ICPC China Nanchang National Invitational and International Silk-Road Programming Contest
目录 Contest Info Solutions A. Attack B. Polynomial E. Interesting Trip F. Sequence G. Winner H. Anoth ...
- The 2019 ICPC China Nanchang National Invitational and International Silk-Road Programming Contest B、H
比赛链接https://www.jisuanke.com/contest/3098?view=challenges B题 拉格朗日插值 题意 T组输入.一个n次多项式 f(x) ,每项的系数不知道, ...
- The Preliminary Contest for ICPC China Nanchang National Invitational and International Silk-Road Programming Contest
打网络赛 比赛前的准备工作要做好 确保 c++/java/python的编译器能用 打好模板,放在桌面 A. PERFECT NUMBER PROBLEM #include <cstdio> ...
- 2019The Preliminary Contest for ICPC China Nanchang National Invitational
The Preliminary Contest for ICPC China Nanchang National Invitational 题目一览表 考察知识点 I. Max answer 单调栈+ ...
- 计蒜客 38229.Distance on the tree-1.树链剖分(边权)+可持久化线段树(区间小于等于k的数的个数)+离散化+离线处理 or 2.树上第k大(主席树)+二分+离散化+在线查询 (The Preliminary Contest for ICPC China Nanchang National Invitational 南昌邀请赛网络赛)
Distance on the tree DSM(Data Structure Master) once learned about tree when he was preparing for NO ...
- 2019 The Preliminary Contest for ICPC China Nanchang National Invitational(A 、H 、I 、K 、M)
A. PERFECT NUMBER PROBLEM 题目链接:https://nanti.jisuanke.com/t/38220 题意: 输出前五个完美数 分析: 签到.直接百度完美数输出即可 #i ...
- ICPC China Nanchang National Invitational -- D. Match Stick Game(dp)
题目链接:https://nanti.jisuanke.com/t/38223 题意:有一堆火柴构成了一个加减法式子,你可以把火柴重新组合,要求数字个数和原来一样多,每个数字的位数和对应原数字位数一样 ...
- The Preliminary Contest for ICPC China Nanchang National Invitational I. Max answer (单调栈+线段树)
题目链接:https://nanti.jisuanke.com/t/38228 题目大意:一个区间的值等于该区间的和乘以区间的最小值.给出一个含有n个数的序列(序列的值有正有负),找到该序列的区间最大 ...
- The Preliminary Contest for ICPC China Nanchang National Invitational I题
Alice has a magic array. She suggests that the value of a interval is equal to the sum of the values ...
随机推荐
- Java环境配置与编译运行详解
这篇文章主要为大家详细介绍了Java环境配置与编译运行的相关资料,具有一定的参考价值,感兴趣的小伙伴们可以参考一下 一.开篇 通过对之前Java之路的了解之后,相信初学者们都对Java有了一个比较深印 ...
- C语言报错:“gets”: 找不到标识符。解决方法
C语言报错:“gets”: 找不到标识符. 把“gets”改成“gets_s”即可.
- GO学习之 安装Go语言及搭建Go语言开发环境
一.下载 1.下载地址 Go官网下载地址:https://golang.org/dl/ Go官方镜像站(推荐):https://golang.google.cn/dl/ 2.版本的选择 Windows ...
- HDU-1702-ACboy needs your help again!(Stack)
队列和栈的判空都可以用empty #include <bits/stdc++.h> using namespace std; string oper,stru; int T,M,num; ...
- Git添加和克隆远程库
首先我们得有一个GitHub账号,然后把当前电脑的SSH Key添加到GitHub上面 第1步:创建SSH Key.在用户主目录下(可用 “cd ~”进入用户主目录),看看有没有.ssh目录,如果有, ...
- Zabbix监控工具介绍及软件监控、硬件监控及报警练习
zabbix介绍 zabbix([`zæbiks])是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案. zabbix能监视各种网络参数,保证服务器系统的安全运营:并提供 ...
- Computational Complexity of Fibonacci Sequence / 斐波那契数列的时空复杂度
Fibonacci Sequence 维基百科 \(F(n) = F(n-1)+F(n-2)\),其中 \(F(0)=0, F(1)=1\),即该数列由 0 和 1 开始,之后的数字由相邻的前两项相加 ...
- 【笔记3-用户模块】从0开始 独立完成企业级Java电商网站开发(服务端)
数据表结构设计 关系设计 为什么不用外键? 分库分表有外键会非常麻烦,清洗数据也很麻烦.数据库内置触发器也不适合采用. 查业务问题的后悔药--时间戳 create_time 数据创建时间 update ...
- idea 导入svn中java WEB项目
1.打开idea 2.填写svn路径 3.指定本地路径 4.选择1.8 format 5.添加jdk 6.配置tomcat启动项目 File -- Project Structure
- django之路由分组,路由分发,FBV,CBV,ORM框架
今日的内容: a. 路由系统 1. 创建app 2. 路由的分组 3. 路由的分发 - 正则表达式匹配 b. django的orm(模型model) 1. 创建模型的步骤 2. orm基本的增删改查 ...