QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#24680#5. 在线 O(1) 逆元skip2004Compile Error//C++201.5kb2022-04-02 10:41:062024-11-05 21:46:55

Judging History

你现在查看的是最新测评结果

  • [2024-11-05 21:46:55]
  • 管理员手动重测本题所有提交记录
  • [2024-11-05 21:43:27]
  • 管理员手动重测本题所有提交记录
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-18 04:17:09]
  • 评测
  • [2022-04-02 10:41:06]
  • 提交

answer

#include<bits/stdc++.h>
#include"inv.h"
using std::cin;
using std::cout;
namespace {
	const int mod = 998244353;
	const int mod2 = 974849; 
	const int w = sqrt(mod2);
	const int limit = 3 * (w + 1) * 1024;
	int inv[limit], arr[mod2];
	using u64 = unsigned long long;
}
int query(int x) {
	const int p = (u64) x * arr[x >> 10] % mod;
	/*
	if(p >= limit && p <= mod - limit) {
		std::cerr << "debug : " << x << '\n';
	}
	*/
	return (u64) arr[x >> 10] * (p < limit ? inv[p] : mod - inv[mod - p]) % mod;
}
void init(int) {
	for(int i = w;i >= 1;--i) {
		std::function<int(int)> getinv = [&](int x) {
			return x == 1 ? 1 : mod2 - u64(mod2 / x) * getinv(mod2 % x) % mod2;
		};
		int inv = getinv(i);
		for(int j = 1;j <= w;++j) {
			arr[(u64) j * inv % mod2] = i;
			arr[mod2 - (u64) j * inv % mod2] = mod - i;
		}
	}
	arr[0] = 1;
	// 0 <= x * arr[x] - k * mod2 < w, and arr[x] < w, k < w
	// 998244353 = mod2 * 1024 - 1023
	// 0 <= 1024x * arr[x] - k * 998244353 < w * 1024 + 1023 * k
	// 0 <= (1024x + y) * arr[x] - k * 998244353 < w * 1024 + 1023 * k + 1024 * w
	inv[1] = 1;
	// 等下再优化这个
	for(int i = 2;i < limit;++i) {
		inv[i] = mod - u64(mod / i) * inv[mod % i] % mod;
	}
}
/*
int main() {
	std::ios::sync_with_stdio(false), cin.tie(0);
	init();
	for(int i = 1;i < mod;++i) {
		if(u64(getinv(i)) * i % mod != 1) {
			cout << getinv(i) << ' ' << i << '\n';
			return 0;
		}
		if(i % 300000 == 0) {
			std::cerr << "debug : " << i << std::endl;
		}

	}
}
*/

Details

implementer.cpp: In function ‘int main()’:
implementer.cpp:22:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   22 |         scanf("%d", &n);
      |         ~~~~~^~~~~~~~~~
answer.code: In function ‘int query(int)’:
answer.code:20:50: error: reference to ‘inv’ is ambiguous
   20 |         return (u64) arr[x >> 10] * (p < limit ? inv[p] : mod - inv[mod - p]) % mod;
      |                                                  ^~~
answer.code:10:13: note: candidates are: ‘int {anonymous}::inv [3035136]’
   10 |         int inv[limit], arr[mod2];
      |             ^~~
In file included from answer.code:2:
inv.h:2:5: note:                 ‘int inv(int)’
    2 | int inv(int n);
      |     ^~~
answer.code:20:65: error: reference to ‘inv’ is ambiguous
   20 |         return (u64) arr[x >> 10] * (p < limit ? inv[p] : mod - inv[mod - p]) % mod;
      |                                                                 ^~~
answer.code:10:13: note: candidates are: ‘int {anonymous}::inv [3035136]’
   10 |         int inv[limit], arr[mod2];
      |             ^~~
inv.h:2:5: note:                 ‘int inv(int)’
    2 | int inv(int n);
      |     ^~~
answer.code: In function ‘void init(int)’:
answer.code:38:9: error: reference to ‘inv’ is ambiguous
   38 |         inv[1] = 1;
      |         ^~~
answer.code:10:13: note: candidates are: ‘int {anonymous}::inv [3035136]’
   10 |         int inv[limit], arr[mod2];
      |             ^~~
inv.h:2:5: note:                 ‘int inv(int)’
    2 | int inv(int n);
      |     ^~~
answer.code:41:17: error: reference to ‘inv’ is ambiguous
   41 |                 inv[i] = mod - u64(mod / i) * inv[mod % i] % mod;
      |                 ^~~
answer.code:10:13: note: candidates are: ‘int {anonymous}::inv [3035136]’
   10 |         int inv[limit], arr[mod2];
      |             ^~~
inv.h:2:5: note:                 ‘int inv(int)’
    2 | int inv(int n);
      |     ^~~
answer.code:41:47: error: reference to ‘inv’ is ambiguous
   41 |                 inv[i] = mod - u64(mod / i) * inv[mod % i] % mod;
      |                                               ^~~
answer.code:10:13: note: candidates are: ‘int {anonymous}::inv [3035136]’
   10 |         int inv[limit], arr[mod2];
      |             ^~~
inv.h:2:5: note:                 ‘int inv(int)’
    2 | int inv(int n);
      |     ^~~