結果
問題 |
No.97 最大の値を求めるくえり
|
ユーザー |
![]() |
提出日時 | 2019-05-26 10:58:53 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 484 ms / 5,000 ms |
コード長 | 1,732 bytes |
コンパイル時間 | 782 ms |
コンパイル使用メモリ | 98,140 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-17 15:11:23 |
合計ジャッジ時間 | 5,805 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 19 |
ソースコード
#include <cstdio> #include <cstring> #include <iostream> #include <string> #include <cmath> #include <bitset> #include <vector> #include <map> #include <set> #include <queue> #include <deque> #include <algorithm> #include <complex> #include <unordered_map> #include <unordered_set> #include <random> #include <cassert> #include <fstream> #define popcount __builtin_popcount using namespace std; typedef long long ll; typedef pair<int, int> P; 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)); } const ll MOD=100003; ll powmod(ll a, ll k){ ll ap=a, ans=1; while(k){ if(k&1){ ans*=ap; ans%=MOD; } ap=ap*ap; ap%=MOD; k>>=1; } return ans; } ll inv(ll a){ return powmod(a, MOD-2); } int main() { int n, Q; cin>>n>>Q; ll a[100010]; bool b[100010]={}; for(int i=0; i<n; i++){ a[i]=xor128()%MOD; b[a[i]]=1; } int d=500; if(n<d){ for(int i=0; i<Q; i++){ ll q; cin>>q; ll ans=0; for(int j=0; j<n; j++){ ans=max(ans, q*a[j]%MOD); } cout<<ans<<endl; } return 0; } for(int i=0; i<Q; i++){ ll q; cin>>q; if(q==0){ cout<<0<<endl; continue; } ll qv=inv(q); for(ll j=MOD-1; j>=1; j--){ if(b[qv*j%MOD]){ cout<<j<<endl; break; } } } return 0; }