結果

問題 No.97 最大の値を求めるくえり
ユーザー 沙耶花沙耶花
提出日時 2021-10-26 00:05:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 136 ms / 5,000 ms
コード長 1,411 bytes
コンパイル時間 4,408 ms
コンパイル使用メモリ 255,784 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-14 20:46:29
合計ジャッジ時間 7,685 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
6,812 KB
testcase_01 AC 22 ms
6,812 KB
testcase_02 AC 86 ms
6,944 KB
testcase_03 AC 41 ms
6,944 KB
testcase_04 AC 41 ms
6,940 KB
testcase_05 AC 42 ms
6,940 KB
testcase_06 AC 43 ms
6,944 KB
testcase_07 AC 52 ms
6,940 KB
testcase_08 AC 64 ms
6,944 KB
testcase_09 AC 88 ms
6,944 KB
testcase_10 AC 136 ms
6,940 KB
testcase_11 AC 99 ms
6,940 KB
testcase_12 AC 86 ms
6,944 KB
testcase_13 AC 78 ms
6,940 KB
testcase_14 AC 61 ms
6,944 KB
testcase_15 AC 51 ms
6,944 KB
testcase_16 AC 48 ms
6,944 KB
testcase_17 AC 46 ms
6,940 KB
testcase_18 AC 46 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 100000000000

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, vector<int> &A) {
    for(int i = 0; i < N; ++ i)
        A[i] = xor128() % 100003;
}

int main(){
	int N,Q;
	cin>>N>>Q;
	
	vector<int> A(N);
	generateA(N,A);
	//cout<<A[0]<<endl;
	vector<bool> f(100003,false);
	rep(i,N){
		//cout<<A[i]<<endl;
		f[A[i]] = true;
	}
	
	int Cnt =0;
	rep(i,f.size()){
		if(f[i])Cnt++;
	}
	
	vector<int> ans(100003,-1);
	vector<int> Inv(100003,0);
	rep(i,100003){
		if(i==0)continue;
		Inv[i] = inv_mod(i,100003);
	}
	
	if(Cnt<=400){
		rep(i,f.size()){
			if(!f[i])continue;
			if(i==0)continue;
			rep(j,100003){
				long long temp = j;
				temp *= Inv[i];
				temp %= 100003;
				ans[temp] = max(ans[temp],j);
			}
		}
	}
	
	ans[0] = 0;
	rep(i,Q){
		int q;
		scanf("%d",&q);
		if(ans[q]==-1){
			for(int j=100002;j>=1;j--){
				long long t = j;
				t *= Inv[q];
				t %= 100003;
				if(f[t]){
					ans[q] = j;
					break;
				}
			}
		}
		printf("%d\n",ans[q]);
	}
		
	
	return 0;
}
0