結果
| 問題 |
No.97 最大の値を求めるくえり
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-10-12 23:47:53 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1,919 ms / 5,000 ms |
| コード長 | 1,214 bytes |
| コンパイル時間 | 775 ms |
| コンパイル使用メモリ | 75,908 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-29 19:33:48 |
| 合計ジャッジ時間 | 9,702 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
using namespace std;
typedef long long int ll;
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;
}
ll mod=100003;
ll n,q,a[100030];
ll has[100030];
ll Power(ll a,ll b){
a%=mod;
if(b==0)return 1;
if(b==1)return a;
ll res=Power(a,b/2);
res%=mod;
res*=res;
res%=mod;
if(b%2==1)res*=a;
res%=mod;
return res;
}
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
cin >> n >> q;
for(int i=0;i<n;i++){
a[i]=xor128()%mod;
has[a[i]]++;
}
ll ans=0;
for(int i=0;i<q;i++){
int x; cin >> x;
if(x==0){
cout << 0 << endl;
continue;
}
if(n<=100){
ans=0;
for(int i=0;i<n;i++){
ans=max(ans,(ll)a[i]*x%mod);
}
}
else{
ll rev=Power(x,mod-2);
for(ans=100002;ans>=0;ans--){
if(has[ans*rev%mod])break;
}
}
cout << ans << endl;
}
}