牛客OI周赛7-提高组 B小睿睿的询问(ST打表)
链接:https://ac.nowcoder.com/acm/contest/371/B
来源:牛客网
void generate_array(int n,int seed)
{
unsigned x = seed;
for (int i=1;i<=n;++i)
{
x ^= x << 13;
x ^= x >> 17;
x ^= x << 5;
val[i]=x%100;
}
}
void generate_ask(int n,int m,int seedx,int seedy)
{
unsigned x=seedx,y=seedy;
for (int i=1;i<=m;++i)
{
x ^= x << 13;
x ^= x >> 17;
x ^= x << 5;
y ^= y << 13;
y ^= y >> 17;
y ^= y << 5;
L=(x^lastans)%n+1,R=(y^lastans)%n+1;
if (L>R)swap(L,R);
//解决询问
}
}
输入描述:
第1行2个整数n,m,分别表示序列长度和询问次数 第2行3个整数seed,seedx,seedy,意义如题所示
输出描述:
一行一个整数,表示所有询问的答案的异或和
输入
10 5
3 5 7
输出
2 思路:裸的ST
#include <cstdio>
#include <map>
#include <iostream>
#include<cstring>
#include<bits/stdc++.h>
#define ll long long int
#define M 6
using namespace std;
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
int moth[]={,,,,,,,,,,,,};
int dir[][]={, ,, ,-, ,,-};
int dirs[][]={, ,, ,-, ,,-, -,- ,-, ,,- ,,};
const int inf=0x3f3f3f3f;
const ll mod=1e9+;
int val[];
int f[][];
int L,R,lastans,ans;
void generate_array(int n,int seed)
{
unsigned x = seed;
for (int i=;i<=n;++i)
{
x ^= x << ;
x ^= x >> ;
x ^= x << ;
val[i]=x%;
}
}
int maxn(int i,int j){
if(val[i]>val[j]) return i;
else if(val[i]<val[j]) return j;
else return i>j?j:i;
}
void preST(int len){
for(int i=;i<=len;i++) f[i][]=i;
int k=log(len)/log()+;
for(int j=;j<k;j++)
for(int i=;i<=(len-(<<j)+);i++)
f[i][j]=maxn(f[i][j-],f[i+(<<(j-))][j-]);
}
int queryST(int l,int r){
int k=log(r-l+)/log();
return maxn(f[l][k],f[r-(<<k)+][k]);
}
void generate_ask(int n,int m,int seedx,int seedy)
{
unsigned x=seedx,y=seedy;
for (int i=;i<=m;++i)
{
x ^= x << ;
x ^= x >> ;
x ^= x << ;
y ^= y << ;
y ^= y >> ;
y ^= y << ;
L=(x^lastans)%n+,R=(y^lastans)%n+;
if (L>R)swap(L,R);
// cout<<L<<" "<<R<<endl;
lastans=queryST(L,R);
// cout<<lastans<<endl;
ans^=lastans;
}
cout<<ans<<endl;
}
int main(){
ios::sync_with_stdio(false);
int seed,seedx,seedy;
int n,m;
while(cin>>n>>m){
cin>>seed>>seedx>>seedy;
generate_array(n,seed);
lastans=;
int tt=m;
ans=;
preST(n);
generate_ask(n,tt,seedx,seedy);
}
}
牛客OI周赛7-提高组 B小睿睿的询问(ST打表)的更多相关文章
- 牛客OI周赛7-提高组 A 小睿睿的等式
链接:https://ac.nowcoder.com/acm/contest/371/A来源:牛客网 小睿睿在游戏开始时有n根火柴棒,他想知道能摆成形如“A+B=n”的等式且使用的火柴棒数也恰好等于n ...
- 牛客OI周赛9-提高组题目记录
牛客OI周赛9-提高组题目记录 昨天晚上做了这一套比赛,觉得题目质量挺高,而且有一些非常有趣而且非常清奇的脑回路在里边,于是记录在此. T1: 扫雷 题目链接 设 \(f_i\) 表示扫到第 \(i\ ...
- 牛客OI周赛8-提高组A-用水填坑
牛客OI周赛8-提高组A-用水填坑 题目 链接: https://ac.nowcoder.com/acm/contest/403/A 来源:牛客网 时间限制:C/C++ 2秒,其他语言4秒 空间限制: ...
- 牛客OI周赛2-提高组
A.游戏 链接:https://www.nowcoder.com/acm/contest/210/A来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 131072K,其他语 ...
- 牛客OI周赛11-普及组 B Game with numbers (数学,预处理真因子)
链接:https://ac.nowcoder.com/acm/contest/942/B 来源:牛客网 Game with numbers 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C+ ...
- 牛客OI周赛7-普及组 解题报告
出题人好评. 评测机差评. A 救救喵咪 二位偏序.如果数据范围大的话直接树状数组,不过才1000就\(O(n^2)\)暴力就ok了. #include <bits/stdc++.h> s ...
- 牛客OI周赛10-普及组-A眼花缭乱的街市-(加速+二分)
https://ac.nowcoder.com/acm/contest/901/A 很简单的一道题,全场只有20+AC,卡时间.新学了cin加速语法和数组二分查找的函数调用. 知道有个读写挂,可以加速 ...
- 牛客OI周赛8-普及组
https://ac.nowcoder.com/acm/contest/543#question A. 代码: #include <bits/stdc++.h> using namespa ...
- 牛客OI周赛7-提高组
https://ac.nowcoder.com/acm/contest/371#question A.小睿睿的等式 #include <bits/stdc++.h> using names ...
随机推荐
- js判断一个对象{}是否为空对象,没有任何属性
// js如何判断一个对象{}是否为空对象,没有任何属性 if (typeof model.rows === "object" && !(model.rows in ...
- 将form数据转换成json对象自定义插件实现思路
- Linux基础学习(11)--Shell编程
第十一章——Shell编程 一.基础正则表达式 1.正则表达式与通配符(*,?,[ ]): 2.基础正则表达式: 二.字符截取命令 1.cut字段提取命令: 空格分割时,不知道空格有多少个,无法分割行 ...
- table index & delete array item
table index & delete array item https://www.iviewui.com/components/table#ZDYLMB 编辑 row = { " ...
- 《Tensorflow从入门到精通》
第一 开发环境搭建 1. tensorflow的环境搭建 windows下安装cpu版tensorflow: pip install tensorflow 在ubuntu上安装gpu版tensorfl ...
- BugFree 安装
BugFree基于PHP和MySQL开发,是免费且开发源代码的缺陷管理系统.服务器端在Linux和Windows平台上都可以运行:客户端无需安装任何软件,通过IE,FireFox等浏览器就可以自由使用 ...
- memcach 命令行
1. cmd上登录memcache # telnet 127.0.0.1 11211 2. 列出所有items stats items 3. 通过itemid获取key 接下来基于列出的i ...
- python工具使用笔记
1.pip pip是Python官方推荐的包管理工具,在doc界面直接使用pip或者pip3命令即可,例如安装gensim: C:\Users\kayan.sjc>pip3 install -- ...
- PHP超级全局变量、魔术变量和魔术函数
PHP超级全局变量(9个) $GLOBALS 储存全局作用域中的变量 $_SERVER 获取服务器相关信息 $_REQUEST 获取POST和GET请求的参数 $_POST 获取表单的POST请求参数 ...
- Spring Boot 构建电商基础秒杀项目 (十一) 秒杀
SpringBoot构建电商基础秒杀项目 学习笔记 新建表 create table if not exists promo ( id int not null auto_increment, pro ...