题目链接: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(打表+线段树)的更多相关文章

  1. 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 ...

  2. 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) ,每项的系数不知道, ...

  3. The Preliminary Contest for ICPC China Nanchang National Invitational and International Silk-Road Programming Contest

    打网络赛 比赛前的准备工作要做好 确保 c++/java/python的编译器能用 打好模板,放在桌面 A. PERFECT NUMBER PROBLEM #include <cstdio> ...

  4. 2019The Preliminary Contest for ICPC China Nanchang National Invitational

    The Preliminary Contest for ICPC China Nanchang National Invitational 题目一览表 考察知识点 I. Max answer 单调栈+ ...

  5. 计蒜客 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 ...

  6. 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 ...

  7. ICPC China Nanchang National Invitational -- D. Match Stick Game(dp)

    题目链接:https://nanti.jisuanke.com/t/38223 题意:有一堆火柴构成了一个加减法式子,你可以把火柴重新组合,要求数字个数和原来一样多,每个数字的位数和对应原数字位数一样 ...

  8. The Preliminary Contest for ICPC China Nanchang National Invitational I. Max answer (单调栈+线段树)

    题目链接:https://nanti.jisuanke.com/t/38228 题目大意:一个区间的值等于该区间的和乘以区间的最小值.给出一个含有n个数的序列(序列的值有正有负),找到该序列的区间最大 ...

  9. 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 ...

随机推荐

  1. Google 开源的依赖注入库,比 Spring 更小更快!

    Google开源的一个依赖注入类库Guice,相比于Spring IoC来说更小更快.Elasticsearch大量使用了Guice,本文简单的介绍下Guice的基本概念和使用方式. 学习目标 概述: ...

  2. SpringBoot启动后自动打开浏览器访问项目

    之前我们用SSM或者SSH进行JAVA WEB开发的时候,IDEA 需要配置Tomcat然后把项目放到tomcat运行,tomcat启动的时候会自动打开浏览器去访问项目,但是SpringBoot是内嵌 ...

  3. springBoot日志快速上手简单配置

    默认配置 日志级别从低到高分为: TRACE < DEBUG < INFO < WARN < ERROR < FATAL. 如果设置为 INFO ,则低于 INFO 的信 ...

  4. PP Bottle Have High Cycle Times

    This year, the participation of 0.1% -0.4% sorbitol nucleating agent in general PP can produce high- ...

  5. 2019年小结&2020年展望

    每篇一句 If you want love, then this is it. This is real life. It's not perfect but it's real. --Before ...

  6. dockerfile的编写参数

    注意细节 “#”号开头是注释 ,指令不区分大小写,顺序执行 FROM 指定基础镜像:注意必须是文件里第一个非注释行 ENV name 值 设置变量,注意没有=号 变量引用 ${name:-chenxi ...

  7. 【PAT甲级】1092 To Buy or Not to Buy (20 分)

    题意: 输入两行字符串,如果第二行字符串包含于第一行字符串,输出"Yes"以及第一行字符串减去第二行字符串剩余的字符个数,否则输出"No"以及第二行字符串中不在 ...

  8. 反编译 java

    1.winrar https://www.rarlab.com/ 2.github  jd-gui http://java-decompiler.github.io/ SignNatureTest.j ...

  9. redhat7.6 配置主从DNS

    主DNS配置include指向的配置文件 /etc/named.rfc1912.zone 下面图片配置内容/etc/named.rfc1912.zones 从DNS配置 /etc/named.conf ...

  10. 顾家办公两不误,容智ibot帮你实现高效居家办公

    春节假期结束,大部分企业已陆续开始复工.经调查显示,受新型冠状病毒疫情影响,不少企业开放了员工“在家办公“模式,就此,员工被动“SOHO”,在家办公火了. 2020 在家办公靠谱吗?会不会成为未来的趋 ...