結果
問題 | No.97 最大の値を求めるくえり |
ユーザー |
![]() |
提出日時 | 2014-12-09 02:20:53 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 248 ms / 5,000 ms |
コード長 | 2,216 bytes |
コンパイル時間 | 793 ms |
コンパイル使用メモリ | 91,960 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-11 18:42:13 |
合計ジャッジ時間 | 3,617 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 19 |
ソースコード
#include <iostream>#include <vector>#include <algorithm>#include <string>#include <sstream>#include <cstring>#include <cstdio>#include <cstdlib>#include <cmath>#include <queue>#include <stack>#include <map>#include <set>#include <numeric>#include <cctype>#include <tuple>#include <climits>#include <bitset>#include <cassert>#include <random>#include <complex>#ifdef _MSC_VER#include <agents.h>#endif#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)#define rep(i, n) FOR(i, 0, n)#define ALL(v) v.begin(), v.end()#define REV(v) v.rbegin(), v.rend()#define MEMSET(v, s) memset(v, s, sizeof(v))#define UNIQUE(v) (v).erase(unique(ALL(v)), (v).end())#define MP make_pair#define MT make_tupleusing 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));}void generateA(int N, vector<int> &A) {for (int i = 0; i < N; ++i)A[i] = xor128() % 100003;}const int mod = 100003;ll mod_pow(ll x, ll n){ll res = 1;while (n){if (n & 1) res = res*x%mod;x = x*x%mod;n /= 2;}return res;}ll calcrev(ll x){return mod_pow(x, mod - 2);}int rev[mod];int main(){cin.tie(0);ios::sync_with_stdio(false);int n, q;cin >> n >> q;if (n <= 1000){vector<int> a(n);generateA(n, a);while (q--){ll x;cin >> x;ll ans = 0;rep(i, n) ans = max(ans, a[i] * x%mod);cout << ans << '\n';}}else{vector<int> b(n);generateA(n, b);vector<int> a(mod);for (auto e : b) a[e] = 1;for (int i = 1; i < mod; ++i) rev[i] = calcrev(i);int cnt = 0;vector<int> ans(mod);rep(i, mod){for (ll j = mod - 1; j >= 0; --j){++cnt;if (a[j*rev[i] % mod]){ans[i] = j;break;}}}ans[0] = 0;while (q--){int x;cin >> x;cout << ans[x] << '\n';}}return 0;}