题目描述
小睿睿的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=(xlastans)%n+1,R=(ylastans)%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
说明
生成序列:
7 11 47 53 3 7 63 36 55 55
各组询问及答案:
询问:4 6
该询问答案:4
询问:2 6
该询问答案:4
询问:2 2
该询问答案:2
询问:4 8
该询问答案:7
询问:1 9
该询问答案:7
所有询问的答案的异或和:2
示例2
输入
100000 10000000
1 2 3
输出
5042
备注:
对于30%的数据,n,m<=1000
对于50%的数据,m<=1000000
对于100%的数据,n<=100000,m<=10000000,seedx,seedy,seed<=1000
#include<iostream>
using namespace std;
int val[100005],s[102][100005],s1[102]={0},ans=0;
void swap(int *a,int *b)
{
int temp;
temp=*a;
*a=*b;
*b=temp;
}
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;
s[val[i]][s1[val[i]]]=i;
s1[val[i]]++;
}
}
void generate_ask(int n,int m,int seedx,int seedy)
{
unsigned x=seedx,y=seedy;
int L,R,lastans=0,j,l,r,cnt=0,cnt1,h;
ans=lastans;
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);
cnt=0;
for(j=99;j>=0;j--)
{
if(s1[j]!=0)
{
l=0,r=s1[j]-1;
while(l<=r)
{
h=(l+r)/2;
if(s[j][h]>R)
{
r=h-1;
}
else
{
if(s[j][h]<L)
{
l=h+1;
}
else
{
if((s[j][h]>=L)&&(s[j][h]<=R))
{
cnt1=s[j][h];
r=h-1;
cnt=1;
}
}
}
}
if(cnt==1)
{
break;
}
}
}
lastans=cnt1;
ans=ans^lastans;
}
cout<<ans<<endl;
}
int main()
{
int n,m,seed,seedx,seedy,i;
cin>>n>>m;
cin>>seed>>seedx>>seedy;
generate_array(n,seed);
generate_ask(n,m,seedx,seedy);
return 0;
}