题目链接: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. 线上BUG定位神器(阿尔萨斯)-Arthas2019-0801

    1.下载这个jar 2.运行这个jar 3.选取你需要定位的问题应用进程 然后各种trace -j xx.xxx.xx.className methodName top -n 3 这个后面要补充去看, ...

  2. Python - 运行流程图, call graph, 调用图

    解决方案 pycallgraph(感觉直接用pycallgraph grahviz命令生成的图并不是我想要的) 如何去阅读并学习一些优秀的开源框架的源码? - mailto1587的回答 - 知乎 h ...

  3. 1018 Public Bike Management (30分) (迪杰斯特拉+dfs)

    思路就是dijkstra找出最短路,dfs比较每一个最短路. dijkstra可以找出每个点的前一个点, 所以dfs搜索比较的时候怎么处理携带和带走的数量就是关键,考虑到这个携带和带走和路径顺序有关, ...

  4. cc攻击怎么防御,如何防止cc攻击?

    当我们访问一个网站时,如果网站页面越简单,访问速度越快,页面越漂亮,加载速度就越慢,因为要加载更多东西,服务器压力也会比较大.cc攻击就是利用这种弱点,使用大量代理服务器,对网站进行攻击,消耗网站服务 ...

  5. easyapi用法

    https://www.easyapi.com/api/?documentId=1773&themeId=

  6. php7 Memcached

    PHP7 Memcached 扩展 wget https://codeload.github.com/websupport-sk/pecl-memcache/zip/php7/pecl-memcach ...

  7. Java入门笔记 09-集合

    一.Collection接口方法:Collection 接口是 List.Set 和 Queue 接口的父接口,该接口里定义的方法既可用于操作 Set 集合,也可用于操作 List 和 Queue 集 ...

  8. byte的取值范围

    byte b = Byte.MAX_VALUE;        b+=1;        System.out.println(b); //输出为-128 取值范围为[-128 -  127] 解析: ...

  9. stm32CubeMx lwip + freeRTOS

    MCU: STM32F429IGT6 工具:STM32CubeMx  版本号 5.0.0 Keil uVersion5 目的:使用LWIP 实现简单的网络连通 一  简介 LWIP(Light Wei ...

  10. [经验] 如何在虚拟机上安装 CentOS

    环境配置 虚拟机 vmware 15.5 Pro 操作系统 CentOS-7-x86_64-DVD-1908.iso 第一步: 在虚拟机上打开操作系统的镜像文件并配置硬件信息 这里的操作就是一本道  ...