結果
問題 | No.97 最大の値を求めるくえり |
ユーザー |
|
提出日時 | 2019-12-28 16:47:40 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 500 ms / 5,000 ms |
コード長 | 1,334 bytes |
コンパイル時間 | 688 ms |
コンパイル使用メモリ | 66,908 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-12 04:26:41 |
合計ジャッジ時間 | 6,376 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 19 |
ソースコード
#include<iostream>using namespace std;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));}void generateA(int N, int A[]) {for(int i = 0; i < N; ++ i)A[i] = xor128() % 100003;}typedef long long ll;ll modpow(ll a, ll b, ll p = 1e9+7){if(b == 0) return 1;if(b % 2 == 0){ll d = modpow(a, b/2, p);return (d*d) % p;}else{return (a%p * modpow(a, b-1, p)) % p;}}const int mod = 100003;int main(){int n, q;cin >> n >> q;int a[n];generateA(n, a);bool b[100004] = {};for(int i = 0; i < n; i++) b[a[i]] = true;bool f = (ll)n*q < 5e7;while(q--){ll x;cin >> x;if(x == 0){cout << 0 << endl;continue;}int ans = 0;if(f){for(int i = 0; i < n; i++) ans = max(ans, (int)(x*a[i]%mod));}else{int inv = modpow(x, mod-2, mod);for(ans = 100002;;ans--){if(b[(ll)ans*inv%mod]) break;}}cout << ans << endl;}return 0;}