牛客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 ...
随机推荐
- [转帖]K8H3D 病毒 腾讯御剑的解析
https://weibo.com/ttarticle/p/show?id=2309404344350225132710 永恒之蓝下载器木马又双叒叕升级了新的攻击方式 背景 腾讯安全御见威胁情报中 ...
- Angular ngRepea
<!DOCTYPE html><html ng-app><head lang="en"> <meta charset="UTF- ...
- 死锁问题分析(个人认为重点讲到了gap间隙锁,解决了我一些不明报死锁的问题)
线上某服务时不时报出如下异常(大约一天二十多次):“Deadlock found when trying to get lock;”. Oh, My God! 是死锁问题.尽管报错不多,对性能目前看来 ...
- java静态工厂
本文摘自:https://www.jianshu.com/p/ceb5ec8f1174 本文略长,所以先来个内容提要 序:什么是静态工厂方法 Effective Java 2.1 静态工厂方法与构造器 ...
- js 持续访问保持session对象不消失
$(function(){ publicBusi(); }) //实时刷新登录用户信息 function publicBusi(){ setTimeout(publicBusi,1000*60*10) ...
- idea -> Error during artifact deployment. See server log for details.
用idea导入eclipse工程,运行时,报Error during artifact deployment. See server log for details. 谷歌,最后发现是最新 tomc ...
- Lodop打印设计里的 打印项对齐
打印设计界面里,有四个对齐的图标:(1)第一个图标是左右对齐方式,该图标下有四种左右对齐方式.(2)第二个图标是上下对齐方式,该图标下有四种上下对齐方式.(3)第三个图标是等宽对齐,该图标下有三种等宽 ...
- endnote中文格式“,等”的修改
https://www.howsci.com/endnote-eng-cn-refer-etal.html
- micro-fusion & macro-fusion
micro-fusion 随着技术的发展,CPU内部指令处理单元(execution unit)以及端口(port)增多,在Pentium 4的时候,发出到Execution Unit的μops的th ...
- Nginx 如何增大nginx使用cpu有效时长
L:121 我们使用 这个命令查看nginx的cpu时间片切换 pidstat - 首先要知道问题: NICE 表示友好 也就是会让出时间切片 所以我们会将静态优先级设置比较低 让他很不友好 Prio ...