题目链接: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. +(new Date())

    +(new Date()) 等于 new Date().getTime();展示 1561003191879 毫秒时间戳

  2. [vue学习] 卡片展示分行功能简单实现

    如图所示,实现简单的卡片展示分行功能. 分行功能较多地用于展示商品.相册等,本人在学习的过程中也是常常需要用到这个功能:虽然说现在有很多插件都能实现这个功能,但是自己写出来,能够理解原理,相信能够进步 ...

  3. Mysql主从复制,双主热备

    Mysql主从复制: 主从复制: 主机准备工作: 开启bin.Log 注意:server-id  是唯一的值 重启mysql:service mysql restart 查看是否开启成功: 查看当前状 ...

  4. Plastic Sprayers Manufacturer -Plastic Spray Bottle Product Features, Nozzle Properties

    Nowadays, plastic spray bottles are widely used in the plastic packaging industry. What are the char ...

  5. 使用jps查看JVM进程信息

    VM进程状态工具 - 列出目标系统上已检测的HotSpot Java虚拟机进程信息.可直接在装有java运行环境的Windows 或者 Linux机器上使用命令行执行jps命令.一个典型的应用场景,例 ...

  6. 【代码学习】PYTHON 线程

    一.使用threading模块多线程执行 可以明显看出使用了多线程并发的操作,花费时间要短很多 创建好的线程,需要调用start()方法来启动 #coding=utf-8 import threadi ...

  7. 脚本中的random几率问题详解

    random解释: 没有固定数值,随即给的意思,数值越大就几率越低,跟爆率也不多,如下脚本,所有都抽不到的话,就会执行最后面没有检测条件的那个.   [@main] #if random 10 #ac ...

  8. EF Expression 扩展

    using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; na ...

  9. 计算机二级-C语言-对二维数组数据进行处理。对文件进行数据输入。形参与实参。

    //函数fun的功能为:计算x所指数组中N个数的平均值(规定所有数都为正数),平均值通过形参返回给主函数,将小于平均值且最接近平均值的数作为函数值返回,并输出. //重难点:形参与实参之间,是否进行了 ...

  10. 03-Docker-Engine详解

    目录 03-Docker-Engine详解 摆脱 LXC 摒弃大而全的 Docker daemon 开放容器计划(OCI)的影响 runc containerd 启动一个新的容器 该模型的显著优势 s ...