# Say some nonsense

## Although our team narrowly won the qualification of CCPC in the second half of the year with the last 10 minutes of the replay, it made us have great doubts about the moisture of CCPC anyway..

### However, the test data given by the topic is large, and the query times of 1e5*1e5 will be tle if you do it violently. Therefore, consider hash or dichotomy.

First consider hashing, using the map in stl

The code is as follows:

```//Dichotomy
#include<iostream>
#include<map>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const int mx=100005;
int t,n,m,cnt;
struct node
{
ll sm,id;
int ip;
}po[mx];
{
ll x=0,f=1;char ch=getchar();
while(ch>'9'||ch<'0')
{
if(ch=='-')
f=-1;ch=getchar();
}
while(ch>='0'&&ch<='9')
{
x=(x<<3)+(x<<1)+ch-48;
ch=getchar();
}
return x*f;
}

inline bool cmp(node a,node b)
{
if(a.id==b.id)
{
if(a.sm==b.sm)
return a.ip<b.ip;
return a.sm<b.sm;
}
return a.id<b.id;
}
int main()
{
for(int op=1;op<=t;++op)
{
ll sm=0,p,rp;
bool flag=false;
po.sm=0;po.ip=0;
for(int i=1;i<n;++i)
{
po[i].ip=i;
}
if(sm<0){
flag=true;sm=-sm;
for(int i=0;i<n;++i) po[i].sm=-po[i].sm;
}
for(int i=0;i<n;++i) po[i].id=sm!=0?(po[i].sm%sm+sm)%sm:0;
sort(po,po+n,cmp);cnt=0;
for(int i=1;i<n;++i) if(po[i].id!=po[i].id||po[i].sm!=po[i-1].sm) po[++cnt]=po[i];
if(sm==0){
for(int i=1;i<=m;++i)
{
int l=0,r=cnt,mid;
while(l<r)
{
mid=(l+r)>>1;
if(po[mid].sm<p)
l=mid+1;
else
r=mid;
}
if(po[l].sm!=p) printf("-1\n");
else printf("%d\n",po[l].ip);
}
}
else
for(int i=1;i<=m;++i){
rp=(p%sm+sm)%sm;
int l=0,r=cnt,mid;
while(l<r){
mid=(l+r+1)>>1;
if(po[mid].id<rp) l=mid;
else if(po[mid].id>rp) r=mid-1;
else if(po[mid].sm>p) r=mid-1;
else l=mid;
}
if(po[l].id!=rp) printf("-1\n");
else if(sm>0&&po[l].sm>p) printf("-1\n");
else if(sm<0&&po[l].sm<p) printf("-1\n");
else printf("%lld\n",po[l].ip+n*(p-po[l].sm)/sm);
}

}
return 0;
}
```

Posted on Sun, 17 Oct 2021 19:07:13 -0400 by Muddy_Funster