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 ...
随机推荐
- 红帽RHCE培训-课程1笔记内容
ssh -X root@s0 1.环境变量 env 系统变量名都为大写; 引用变量名对应的值时使用$引导: SHELL下,修改变量临时生效. # PS1=' # ' # echo $PS1 永久生效放 ...
- appium可通过SDK自带的uiautomatorviewer或monitor工具,来查看页面元素(Android)
工具一:uiautomatorviewer 1.在SDK的tools目录中找到uiautomatorviewer,双击打开若出现闪退一般是jdk版本不匹配(建议安装jdk1.8的): 2.在使用这个工 ...
- Go之Cookie和Session
文章引用自 Cookie和Session Cookie和Session是Web开发绕不开的一个环节,本文介绍了Cookie和Session的原理及在Go语言中如何操作Cookie. Cookie Co ...
- 10,html全局属性有哪些
10,html全局属性(global attribute,html属性赋予元素意义和语境,html全局属性可以用于任何的html元素)有哪些 class:为元素设置类标识 data-*:为元素增加自定 ...
- MYSQL命令练习及跳过数据库密码进行密码重新设置
2.看当前所有数据库:show databases; 3.进入mysql数据库:use mysql; 4.查看mysql数据库中所有的表:show tables; 5.查看user表中的数据: ...
- utf-8无bom格式编码
BOM——Byte Order Mark,就是字节序标记 在UCS 编码中有一个叫做"ZERO WIDTH NO-BREAK SPACE"的字符,它的编码是FEFF.而FFFE在U ...
- ECMAScript中的箭头函数 (=>) 使用注意事项
箭头函数表达式的语法比函数表达式更简洁,并且没有自己的this,arguments,super或 new.target.这些函数表达式更适用于那些本来需要匿名函数的地方,并且它们不能用作构造函数. 箭 ...
- WCF全面解析之 第四讲 使用代码 部署服务
关键代码: ServiceHost host = null; //启动 private void button1_Click(object sender, EventArgs e) { host=ne ...
- 「luogu3380」【模板】二逼平衡树(树套树)
「luogu3380」[模板]二逼平衡树(树套树) 传送门 我写的树套树--线段树套平衡树. 线段树上的每一个节点都是一棵 \(\text{FHQ Treap}\) ,然后我们就可以根据平衡树的基本操 ...
- 拓扑排序板子 hihocoder-1174
思路 不断删入度为1的点及其出边. 图解 #include <bits/stdc++.h> using namespace std; const int maxn=1e5+10; vect ...