Glad You Came

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 1489    Accepted Submission(s): 629

Problem Description
Steve has an integer array a of length n (1-based). He assigned all the elements as zero at the beginning. After that, he made m operations, each of which is to update an interval of a with some value. You need to figure out ⨁ni=1(i⋅ai) after all his operations are finished, where ⨁ means the bitwise exclusive-OR operator.
In order to avoid huge input data, these operations are encrypted through some particular approach.
There are three unsigned 32-bit integers X,Y and Z which have initial values given by the input. A random number generator function is described as following, where ∧ means the bitwise exclusive-OR operator, << means the bitwise left shift operator and >> means the bitwise right shift operator. Note that function would change the values of X,Y and Z after calling.

Let the i-th result value of calling the above function as fi (i=1,2,⋯,3m). The i-th operation of Steve is to update aj as vi if aj<vi (j=li,li+1,⋯,ri), where

⎧⎩⎨⎪⎪lirivi=min((f3i−2modn)+1,(f3i−1modn)+1)=max((f3i−2modn)+1,(f3i−1modn)+1)=f3imod230(i=1,2,⋯,m).
 
Input
The first line contains one integer T, indicating the number of test cases.
Each of the following T lines describes a test case and contains five space-separated integers n,m,X,Y and Z.
1≤T≤100, 1≤n≤105, 1≤m≤5⋅106, 0≤X,Y,Z<230.
It is guaranteed that the sum of n in all the test cases does not exceed 106 and the sum of m in all the test cases does not exceed 5⋅107.
 
Output
For each test case, output the answer in one line.
 
Sample Input
4
1 10 100 1000 10000
10 100 1000 10000 100000
100 1000 10000 100000 1000000
1000 10000 100000 1000000 10000000
 
Sample Output
1031463378
1446334207
351511856
47320301347

Hint

In the first sample, a = [1031463378] after all the operations.
In the second sample, a = [1036205629, 1064909195, 1044643689, 1062944339, 1062944339, 1062944339, 1062944339, 1057472915, 1057472915, 1030626924] after all the operations.

 
Source
 
 
首先用ST表维护区间最大值,st[i][j]维护的是i以后2^j个数的最大值
然后反向求一遍ST表可以求出每个数的最大值,此时st[i][0]就是每个数的最大值
再按照题目意思求每个值与其位置的乘积再异或一遍
贴一份讲解RMQ-ST表的博客:https://www.cnblogs.com/l609929321/p/9439145.html
AC代码:
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
#define ls (r<<1)
#define rs (r<<1|1)
#define debug(a) cout << #a << " " << a << endl
using namespace std;
typedef long long ll;
const ll maxn = 1e5+10;
const ll mod = 998244353;
const double pi = acos(-1.0);
const double eps = 1e-8;
unsigned x, y, z;
unsigned rng() {
x ^= x << 11;
x ^= x >> 4;
x ^= x << 5;
x ^= x >> 14;
unsigned w = x^(y^z);
x = y;
y = z;
z = w;
return z;
}
ll n, m, a[maxn], st[maxn][20], Log[maxn];
void update( ll le, ll ri, ll z ) { //维护(le,ri)区间最大值
ll k = Log[ri-le+1];
st[le][k] = max(st[le][k],z);
st[ri-(1<<k)+1][k] = max(st[ri-(1<<k)+1][k],z);
} int main() {
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
Log[2] = 1;
for( ll i = 3; i < maxn; i ++ ) { //预处理区间所有log2()的值,节省时间
Log[i] = Log[i>>1]+1;
}
ll T;
cin >> T;
while( T -- ) {
cin >> n >> m >> x >> y >> z;
for( ll i = 1; i <= n; i ++ ) { //n最大的情况下,log2(maxn) = 16
for( ll j = 0; j < 18; j ++ ) {
st[i][j] = 0;
}
}
for( ll i = 1; i <= m; i ++ ) {
ll x = rng()%n+1, y = rng()%n+1, z = rng()%(1<<30);
update(min(x,y),max(x,y),z);
}
for( ll j = 17; j; j -- ) { //反向一遍st求出每一个数的最大值
for( ll i = 1; i+(1<<j)-1 <= n; i ++ ) {
st[i][j-1] = max(st[i][j-1],st[i][j]);
st[i+(1<<(j-1))][j-1] = max(st[i+(1<<(j-1))][j-1],st[i][j]);
}
}
ll ans = 0;
for( ll i = 1; i <= n; i ++ ) {
ans = ans^(i*st[i][0]);
}
cout << ans << endl;
}
return 0;
}

  

  

 

hdu6356 Glad You Came 杭电多校第五场 RMQ ST表(模板)的更多相关文章

  1. 2018杭电多校第五场1002(暴力DFS【数位】,剪枝)

    //never use translation#include<bits/stdc++.h>using namespace std;int k;char a[20];//储存每个数的数值i ...

  2. 2017杭电多校第五场11Rikka with Competition

    Rikka with Competition Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/O ...

  3. 2017杭电多校第五场Rikka with Subset

    Rikka with Subset Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others ...

  4. [2019杭电多校第五场][hdu6630]permutation 2

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6630 题意为求出1-n,n个数的全排列中有多少种方案满足第一位为x,第n位为y,且相邻数字绝对值之差不 ...

  5. [2019杭电多校第五场][hdu6624]fraction

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6624 题意为求最小的b满足$a*b^{-1}\equiv x(modp)$. 把式子化简一下: $a\ ...

  6. [2019杭电多校第五场][hdu6629]string matching(扩展kmp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6629 题意求字符串的每个后缀与原串的最长公共前缀之和. 比赛时搞东搞西的,还搞了个后缀数组...队友一 ...

  7. [2019杭电多校第五场][hdu6628]permutation 1

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6628 题意为求字典序第k小的差异数组,差异数组p满足p[i]=a[i+1]-a[i]. 头铁的爆搜,因 ...

  8. [2019杭电多校第五场][hdu6625]three arrays(01字典树)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6625 大意为给你两个数组a和b,对应位置异或得到c数组,现在可以将a,b数组从新排序求c数组,使得字典 ...

  9. 2019杭电多校第五场 discrete logarithm problem

    https://vjudge.net/contest/317493#problem/I

随机推荐

  1. WebGL简易教程(一):第一个简单示例

    目录 1. 概述 2. 示例:绘制一个点 1) HelloPoint1.html 2) HelloPoint1.js (1) 准备工作 (2) 着色器 (3) 顶点着色器 (4) 片元着色器 (5) ...

  2. 章节十五、6-log4 2-用默认的配置

    一.实例演示 package log4jtutorial; import org.apache.logging.log4j.LogManager; import org.apache.logging. ...

  3. Codeforces Round #527 (Div. 3) 总结 A B C D1 D2 F

    传送门 A 贪心的取 每个字母n/k次 令r=n%k 让前r个字母各取一次 #include <bits/stdc++.h> using namespace std; typedef lo ...

  4. 【Java笔记】【Java核心技术卷1】chapter3 D1JavaStandard

    package chapter3;/*有包名,命令行编译javac -d . 名字.java(注意空格)运行时用java chapter3.JavaStandard*/ public/*访问修饰符*/ ...

  5. Spring Boot 整合 JPA 使用多个数据源

    介绍 JPA(Java Persistence API)Java 持久化 API,是 Java 持久化的标准规范,Hibernate 是持久化规范的技术实现,而 Spring Data JPA 是在 ...

  6. Unity学习--捕鱼达人笔记

    1.2D模式和3D模式的区别,2D模式默认的摄像机的模式是Orthographic(正交摄像机),3D模式默认的摄像机的模式是Perspective(透视摄像机).3D会额外给你一个平衡光.3D模式修 ...

  7. HTML发展历程

    HTML是超文本标记语言的缩写,不同于C或JAVA等编程语言,HTML由标签组成.通过标签可以在网页中插入文字.图片.链接.音频.视频等元素,进而描述网页.和Windows一样,随着技术的发展,HTM ...

  8. Json串与实体的相互转换 (不依赖于jar包 只需Eclipse环境即可)

    Json串与实体的相互转换 (不依赖于jar包 只需Eclipse环境即可) 最近学习了javaWeb开发,用的是ssh框架里面自己整合了hibernate 和Struts2 和spring框架,其中 ...

  9. redis高可用之DNS篇

    1.  背景 例如,存在一套redis主从(主从节点在不同的主机上),应用程序通过主库的ip进行读写操作. 但是,主库一旦出现故障,虽然有从库,且从库提升为主库,但是应用程序如果想使用从库则必须修改配 ...

  10. postman-使用教程

    postman postman是一款非常方便的API测试工具,可以帮我们快速的发起HTTP请求,下面记录一下postman的基本使用. postman安装 postman下载地址 下载安装打开之后就是 ...