結果

問題 No.97 最大の値を求めるくえり
ユーザー beet
提出日時 2019-03-23 13:50:17
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 1,493 bytes
コンパイル時間 1,854 ms
コンパイル使用メモリ 195,824 KB
最終ジャッジ日時 2025-01-07 00:12:06
ジャッジサーバーID
(参考情報)
judge1 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 10 WA * 1 TLE * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;

//INSERT ABOVE HERE

unsigned xor128_x = 123456789, xor128_y = 362436069, xor128_z = 521288629, xor128_w = 88675123;
unsigned xor128() {
	unsigned t = xor128_x ^ (xor128_x << 11);
	xor128_x = xor128_y; xor128_y = xor128_z; xor128_z = xor128_w;
	return xor128_w = xor128_w ^ (xor128_w >> 19) ^ (t ^ (t >> 8));
}
vector<int> generateA(int N) {
  vector<int> A(N);
  for(int i = 0; i < N; ++ i)
    A[i] = xor128() % 100003;
  return A;
}

signed main(){
  int n,q;
  cin>>n>>q;
  auto a=generateA(n);
  using ll = long long;
  const ll BS = 500;
  const ll MOD = 100003;
  if(n<BS){
    while(q--){
      ll x;
      cin>>x;
      ll res=0;
      for(int y:a) chmax(res,x*y%MOD);
      cout<<res<<"\n";
    }
    cout<<flush;
    return 0;
  }
  
  auto inv=[MOD](ll x)->ll{
             ll n=MOD-2,res=1;             
             while(n){
               if(n&1) res=res*x%MOD;
               x=x*x%MOD;
               n>>=1;
             }
             return res;
           };
  vector<int> exist(MOD,0);
  for(int y:a) exist[y]=1;
  
  while(q--){
    ll x;
    cin>>x;
    ll z=inv(x);
    ll res=MOD-1;
    while(!exist[res*z%MOD]) res--;
    cout<<res<<"\n";
  }
  cout<<flush;
  return 0;
}
0