The Preliminary Contest for ICPC China Nanchang National Invitational K题 MORE XOR

简介: The Preliminary Contest for ICPC China Nanchang National Invitational K题 MORE XOR

Given a sequence of nn numbers a1 ,a2,⋯,an and three functions.

Define a function f(l,r)f(l,r) which returns \oplus a[x]⊕a[x] (l \le x \le rl≤x≤r). The \oplus⊕ represents exclusive OR.

Define a function g(l,r)g(l,r) which returns \oplus f(x,y)(l \le x \le y \le r)⊕f(x,y)(l≤x≤y≤r).

Define a function w(l,r)w(l,r) which returns \oplus g(x,y)(l \le x \le y \le r)⊕g(x,y)(l≤x≤y≤r).

You are also given a number of xor-queries. A xor-query is a pair (i, j) (1≤i≤j≤n). For each xor-query (i, j)(i,j), you have to answer the result of function w(l,r).

Input

Line 1: t(1≤t≤20).


For each test case:


Line 1: n(1≤n≤100000).


Line 2: n numbers a1, a2 ,⋯,an(1≤ai≤10^9).


Line 33: q(1≤q≤100000), the number of xor-queries.


In the next q lines, each line contains 22 numbers i,j representing a xor-query(1≤i≤j≤n).


It is guaranteed that sum of nn and q≤10^6.


Output

For each xor-query (i, j)(i,j), print the result of function w(i,j)w(i,j) in a single line.

暴力打表找规律,维护前缀异或
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int a[maxn];
int b[4][maxn], c[4][maxn];
int dp1[4][maxn], dp2[4][maxn];
int main() {
  int T, n, m, l, r;
  scanf("%d", &T);
  while (T--) {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
    }
    for (int i = 0; i < 4; i++) {
      for (int j = 1; j <= n; j++) {
        if(j%4==i)b[i][j] = 1;
        if(j%4==i) {
          c[i][j]=1;c[i][j + 1] = 1;
        }
      }
      for (int j = 1; j <= n; j++) {
        dp1[i][j] = dp1[i][j - 1] ^ (b[i][j] * a[j]);
        dp2[i][j] = dp2[i][j - 1] ^ (c[i][j] * a[j]);
      }
    }
    scanf("%d", &m);
    while (m--) {
      scanf("%d%d", &l, &r);
      int k = (r - l + 1) % 4;
      if (k == 0) {
        printf("0\n");
      } else if (k == 1) {
        for (int i = 0; i < 4; i++) {
          if(b[i][l]) {
            printf("%d\n", (dp1[i][l - 1] ^ dp1[i][r]));
            break;
          }
        }
      } else if (k == 3) {
        for (int i = 0; i < 4; i++) {
          if (b[i][l]==0 && b[i][l+1] == 1) {
            printf("%d\n", (dp1[i][l - 1] ^ dp1[i][r]));
            break;
          }
        }
      } else if (k == 2) {
        for (int i = 0; i < 4; i++) {
          if (c[i][l] == 1 && c[i][l + 1] == 1) {
            printf("%d\n", (dp2[i][l - 1] ^ dp2[i][r]));
            break;
          }
        }
      }
    }
  }
  return 0;
}
/*
11001100
01100110
00110011
10011001
1000  1000 1000
0100  0100 0100
0010  0010 0010
0001  0001 0001
*/
相关文章
|
应用服务中间件 Android开发 nginx
|
机器学习/深度学习 搜索推荐 数据可视化
机器学习中7种常用的线性降维技术总结
上篇文章中我们主要总结了非线性的降维技术,本文我们来总结一下常见的线性降维技术。
1351 6
Vue3 使用动态组件 component
Vue3 使用动态组件 component
934 0
|
Java Maven
实战:第十四章:Springboot集成jsp页面报404四种解决方案
实战:第十四章:Springboot集成jsp页面报404四种解决方案
1034 0
实战:第十四章:Springboot集成jsp页面报404四种解决方案
|
域名解析 监控 网络协议
企业实战(17)记录一次使用DDNS动态域名解析服务外网通过域名访问内网服务器服务的过程
企业实战(17)记录一次使用DDNS动态域名解析服务外网通过域名访问内网服务器服务的过程
2782 0
|
敏捷开发 持续交付 UED
什么是真正的敏捷开发?敏捷开发与瀑布开发有何不同
什么是真正的敏捷开发?敏捷开发与瀑布开发有何不同。从本质上讲敏捷开发的一个重要目标是建立持续价值交付的能力。这种能力最终必须服务于业务的创新,促进业务的成功。
1666 0
什么是真正的敏捷开发?敏捷开发与瀑布开发有何不同
|
Kubernetes 容器
Kubernetes 问题排查全景图
Kubernetes 问题排查全景图
Kubernetes 问题排查全景图
|
算法
基于farrow结构的时间同步算法matlab仿真
基于farrow结构的时间同步算法matlab仿真
712 0
基于farrow结构的时间同步算法matlab仿真
|
机器学习/深度学习 SQL 人工智能
19岁华裔天才辍学MIT,创办AI独角兽,5年市值73亿美元!
19岁辍学麻省理工(MIT),华裔天才少年 Alexandr Wang 创办硅谷AI独角兽,成为Scale AI的掌门人。近日,这家总部位于旧金山的公司在最新一轮融资中的估值约为73亿美元。
1007 0
19岁华裔天才辍学MIT,创办AI独角兽,5年市值73亿美元!
Core Animation -图层与视图
Core Animation -图层与视图
290 0