链接:https://ac.nowcoder.com/acm/contest/371/B
来源:牛客网

小睿睿的n个妹纸排成一排,每个妹纸有一个颜值val[i]。有m个询问,对于每一个询问,小睿睿想知道区间[L,R]颜值最高而编号最小的妹纸是哪一个
对于妹纸们的颜值val[i],其生成函数为:
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;
    }
}
对于每一组询问,区间[L,R]的生成函数为:
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);
//解决询问
    }
}

其中lastans为上个询问的答案,对于第一个询问,lastans为0

输入描述:

第1行2个整数n,m,分别表示序列长度和询问次数

第2行3个整数seed,seedx,seedy,意义如题所示

输出描述:

一行一个整数,表示所有询问的答案的异或和
示例1

输入

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打表)的更多相关文章

  1. 牛客OI周赛7-提高组 A 小睿睿的等式

    链接:https://ac.nowcoder.com/acm/contest/371/A来源:牛客网 小睿睿在游戏开始时有n根火柴棒,他想知道能摆成形如“A+B=n”的等式且使用的火柴棒数也恰好等于n ...

  2. 牛客OI周赛9-提高组题目记录

    牛客OI周赛9-提高组题目记录 昨天晚上做了这一套比赛,觉得题目质量挺高,而且有一些非常有趣而且非常清奇的脑回路在里边,于是记录在此. T1: 扫雷 题目链接 设 \(f_i\) 表示扫到第 \(i\ ...

  3. 牛客OI周赛8-提高组A-用水填坑

    牛客OI周赛8-提高组A-用水填坑 题目 链接: https://ac.nowcoder.com/acm/contest/403/A 来源:牛客网 时间限制:C/C++ 2秒,其他语言4秒 空间限制: ...

  4. 牛客OI周赛2-提高组

    A.游戏 链接:https://www.nowcoder.com/acm/contest/210/A来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 131072K,其他语 ...

  5. 牛客OI周赛11-普及组 B Game with numbers (数学,预处理真因子)

    链接:https://ac.nowcoder.com/acm/contest/942/B 来源:牛客网 Game with numbers 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C+ ...

  6. 牛客OI周赛7-普及组 解题报告

    出题人好评. 评测机差评. A 救救喵咪 二位偏序.如果数据范围大的话直接树状数组,不过才1000就\(O(n^2)\)暴力就ok了. #include <bits/stdc++.h> s ...

  7. 牛客OI周赛10-普及组-A眼花缭乱的街市-(加速+二分)

    https://ac.nowcoder.com/acm/contest/901/A 很简单的一道题,全场只有20+AC,卡时间.新学了cin加速语法和数组二分查找的函数调用. 知道有个读写挂,可以加速 ...

  8. 牛客OI周赛8-普及组

    https://ac.nowcoder.com/acm/contest/543#question A. 代码: #include <bits/stdc++.h> using namespa ...

  9. 牛客OI周赛7-提高组

    https://ac.nowcoder.com/acm/contest/371#question A.小睿睿的等式 #include <bits/stdc++.h> using names ...

随机推荐

  1. js 正则进阶regexp

    一.匹配中文,英文字母和数字及_: const reg = /^[\u4e00-\u9fa5\w]+$/; const str1 = 'shangyy'; const str2 = '尚悦悦ww123 ...

  2. 六、es6 map

    一.map的特点 JavaScript 的对象(Object),本质上是键值对的集合(Hash 结构),但是传统上只能用字符串当作键.这给它的使用带来了很大的限制. 为了解决这个问题,ES6 提供了 ...

  3. 1 CHM 中文都是乱码

    CHM格式是Windows系统里常见的帮助文档格式,但有时一些CHM格式的文档会局部显示乱码,特别是一些外文文档在中文版Windows里.这是因为,CHM格式文档在Windows下默认是使用IE浏览器 ...

  4. iperf网络测试

    iperf网络测试文档 地址: https://www.jianshu.com/p/942a9d9bc704

  5. wget 下载网页

    如有转载,不胜荣幸.http://www.cnblogs.com/aaron-agu/ wget --http-user=username --http-passwd=password http:/w ...

  6. Python——Message控件

    一.messagebox的方法: showerror   : 错误提示对话框 showinfo  :  信息提示对话框 showwarning   : 警告对话框 askokcansel   :确认或 ...

  7. Spring4 MVC Hibernate4 maven集成

    http://www.cnblogs.com/leiOOlei/p/3727859.html

  8. NPOI 上传Excel功能(三)

    4.验证Excel并上传 using DC.BE.Business.SAS; using DC.BE.Business.SYS; using DC.BE.Entity.SAS; using DC.BE ...

  9. [oracle] to_date() 与 to_char() 日期和字符串转换

    to_date("要转换的字符串","转换的格式")   两个参数的格式必须匹配,否则会报错. 即按照第二个参数的格式解释第一个参数. to_char(日期,& ...

  10. python绘制图形

      python能快速解决日常工作中的小任务,比如数据展示. python做数据展示,主要用到matplotlib库,使用简单的代码,就可以很方便的绘制折线图.柱状图等.使用Java等,可能还需要配合 ...