QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#827893 | #4495. Shinobu loves trip | eastcloud | AC ✓ | 962ms | 56960kb | C++23 | 1.9kb | 2024-12-23 11:05:45 | 2024-12-23 11:05:48 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define pi pair<int,int>
#define vi vector<int>
#define cpy(x,y,s) memcpy(x,y,sizeof(x[0])*(s))
#define mset(x,v,s) memset(x,v,sizeof(x[0])*(s))
#define all(x) begin(x),end(x)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ary array
#define eb emplace_back
#define IL inline
#define For(i,j,k) for(int i=(j);i<=(k);i++)
#define Fol(i,k,j) for(int i=(k);i>=(j);i--)
using namespace std;
#define N 300005
int read(){
int x=0,f=1;char ch=getchar();
while(ch<'0' || ch>'9')f=(ch=='-'?-1:f),ch=getchar();
while(ch>='0' && ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
return x*f;
}
void write(int x){
if(x<0)x=-x,putchar('-');
if(x/10)write(x/10);
putchar(x%10+'0');
}
void debug(auto &&...x){
((cerr<<x<<' '),...);
cerr<<'\n';
}
int mod;
unordered_map<int,int> t;
IL int pls(int x,int y){return (x+y>=mod?x+y-mod:x+y);}
IL int sub(int x,int y){return (x-y<0?x-y+mod:x-y);}
IL void Add(int &x,int y){x=pls(x,y);}
IL void Dec(int &x,int y){x=sub(x,y);}
IL int mul(int x,int y){return x*1ll*y%mod;}
IL int qp(int x,int y=mod-2){int ans=1;while(y){if(y&1)ans=mul(ans,x);x=mul(x,x);y>>=1;}return ans;}
int s[N],d[N],inv[N];
void solve(){
mod=read();int a=read(),n=read(),q=read();t.clear();
for(int i=0,w=1;i<N;i++,w=mul(w,a))t[w]=(t[w]?min(t[w],i+1):i+1);
For(i,1,n)d[i]=read(),s[i]=read(),inv[i]=(d[i]==0?0:qp(d[i]));
For(i,1,q){
int x=read(),res=0;
For(j,1,n){
if(x==0 && inv[j]==0)res++;
else if(x==0 || inv[j]==0)continue;
int tmp=mul(x,inv[j]);
if(t[tmp] && t[tmp]-1<=s[j])res++;
}
write(res);putchar('\n');
}
}
int main(){
#ifdef EAST_CLOUD
freopen("a.in","r",stdin);
//freopen("a.out","w",stdout);
#endif
int T=read();
while(T--)solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 962ms
memory: 56960kb
input:
5 999999937 4628 1000 1000 162585517 24584 407438671 108585 46973547 132178 142179754 23710 198067620 130706 829852550 190969 676555968 2127 717426372 80994 332054419 1078 471194333 66473 105470508 154839 939339406 89663 73289403 90982 529133484 198011 526081635 28219 405427868 174742 120011816 6408...
output:
167 166 168 168 174 169 2 167 169 22 153 169 150 163 7 152 149 166 166 176 63 178 125 170 94 167 155 173 56 147 163 169 167 183 78 165 179 173 182 170 166 150 152 166 169 169 169 173 162 52 180 182 170 163 173 173 175 150 171 166 170 148 170 166 63 168 172 151 150 72 129 14 61 167 167 169 174 133 17...
result:
ok 5000 lines