。。
圈圈
http://www.nowcoder.com/questionTerminal/f4729457b9a9446990efe61a62aee480
include<stdio.h>
include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1000000007;
const ll base=313;
int n,m,k;
int s[100005];
ll jc[100005],hs[100005];
vector<int> vec[50005];
int pdhash(int x,int y,int len){
ll hx=(hs[x+len-1]-hs[x-1]jc[len]%mod+mod)%mod;
ll hy=(hs[y+len-1]-hs[y-1]jc[len]%mod+mod)%mod;
// cout<<"hash="<<hx<<" "<<hy<<" --"<<hs[y+len-1]<<" jc:"<<jc[len]<<" len:"<<len<<endl;
if(hx==hy) return 1;
return 0;
}
int pd(int x,int y ,int k){
int l=0,r=n;
while(l<r){
int mid=(l+r+1)/2;
if(pdhash(x,y,mid)){
l=mid;
}else{
r=mid-1;
}
}
if(l==n) return 1;
x=(s[x+l]+k)%m;
y=(s[y+l]+k)%m;
//cout<<x<<" -- "<<y<<" len="<<l<<endl;
return y<x;
}
int main()
{
jc[0]=1;
for(int i=1;i<=500002;i++) jc[i]=jc[i-1]base%mod;
//cout<<jc[1]<<endl;
cin>>n>>m>>k;
for(int i=1;i<=n;i++){
cin>>s[i];
s[i+n]=s[i];
vec[s[i]%m].push_back(i);
}
for(int i=1;i<=n2;i++) hs[i]=(hs[i-1]base+s[i])%mod;
int dex=1;
for(int i=2;i<=n;i++){
if(pd(dex,i,0))dex=i;
}
cout<<s[dex+k-1]<<endl;
for(int i=m-1;i>=1;i--){
if(vec[i].size()){
int d=vec[i][0];
for(int j=1;j<vec[i].size();j++){
int v=vec[i][j];
if(pd(d,v,m-i))d=v;
}
dex=d;
}
//cout<<(s[dex+k-1]+m-i)<<"--"<<m-i<<endl;</int>
cout<<(s[dex+k-1]+m-i)%m<<endl; } return 0;
}