提交时间:2024-10-09 18:24:36
运行 ID: 33486
#include<bits/stdc++.h> #define up(i,l,r) for(int i=(l);i<=(r);++i) #define down(i,l,r) for(int i=(l);i>=(r);--i) #define pi pair<int,int> #define p1 first #define p2 second #define m_p make_pair #define p_b push_back using namespace std; typedef long long ll; const int maxn=2e6+10,mod=1e9+7; const double eps=1e-7; inline ll read(){ ll x=0;short t=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')t=-1;ch=getchar();} while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar(); return x*t; } int n,m,C; struct nd { int p,a,id; }d[maxn],T[maxn]; bool cmp(nd a,nd b){ if(a.p==b.p)return a.a>b.a; return a.p>b.p; } int qp(int a,int b){ int res=1; while(b){ if(b&1)res=res*1ll*a%mod; a=a*1ll*a%mod,b>>=1; }return res; } double qp2(double a,int b){ double res=1; while(b){ if(b&1)res=res*a; a=a*a;b>>=1; }return res; } struct info { double p;int val; info(){} info(int x){ p=x,val=(x%mod+mod)%mod; } info(double x,int y){ p=x,val=y; } }; info operator+(info a,info b){ return info(a.p+b.p,(a.val+b.val)%mod); } info operator-(info a,info b){ return info(a.p-b.p,(a.val+mod-b.val)%mod); } info operator*(info a,info b){ return info(a.p*b.p,a.val*1ll*b.val%mod); } info operator/(info a,info b){ return info(a.p/b.p,a.val*1ll*qp(b.val,mod-2)%mod); } info qpow(info a,int b){ info res(1); while(b){ if(b&1)res=res*a; a=a*a,b>>=1; }return res; } info calc_equal(info p,ll a,info q,ll b){ info res(1); res=res*(info(1)-p);res=res*(info(1)-q); res=res*qpow(p,b-1);res=res*qpow(q,a-1); info w(1);w=w*qpow(p,b);w=w*qpow(q,a); w=info(1)-w; res=res/w;return res; } info calc(info p,ll a,info q,ll b){ double ret=qp2(q.p,b/a); if(a==1){ info w=q*qpow(p,b); info res=w*info(-1)/(w-info(1)); res=res*(info(1)-q)/q;return res; }if(b>=a){ q=q*qpow(p,b/a);b%=a; return calc(p,a,q,b); }auto it=info(1)-calc_equal(p,a,q,b)-calc(q,b,p,a); if(p.p<eps)it.p=ret; return it; } ll gcd(ll x,ll y){return ((!y)?x:gcd(y,x%y));} info get(ll a,info p,ll b,info q){ ll g=gcd(a,b);a/=g,b/=g; return calc(p,a,q,b); } void slv(){ n=read(),m=read(),C=read(); up(i,1,n)d[i].p=read(),d[i].a=read(),d[i].id=i; sort(d+1,d+n+1,cmp); T[1]=d[1];int c=1;up(i,2,n){ if(d[i].a<T[c].a)continue; T[++c]=d[i]; }n=c;up(i,1,n)d[i]=T[i]; //cout<<"? "<<n<<endl; //up(i,1,n)cout<<"? "<<d[i].id<<endl; while(m--){ int x=read(),y=read(); int mx=0;info res(-1); up(i,1,n){ info w=get(d[i].a,info(d[i].p)/info(C),y,info(x)/info(C)); //cout<<"! "<<w.p<<" "<<w.val<<endl; if(w.p>res.p)res=w,mx=d[i].id; }printf("%d %.8lf %d\n",mx,res.p,res.val); } }int main(){ //freopen("sword.in","r",stdin); //freopen("sword.out","w",stdout); int t=read();while(t--)slv(); fclose(stdin); fclose(stdout); //cerr<<clock()*1.0/CLOCKS_PER_SEC<<"s\n"; return 0; }