結果
問題 | No.2362 Inversion Number of Mod of Linear |
ユーザー | 👑 Nachia |
提出日時 | 2023-06-24 01:13:00 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,675 bytes |
コンパイル時間 | 964 ms |
コンパイル使用メモリ | 89,940 KB |
実行使用メモリ | 21,532 KB |
最終ジャッジ日時 | 2024-07-01 04:54:26 |
合計ジャッジ時間 | 4,529 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
13,752 KB |
testcase_01 | AC | 2 ms
6,944 KB |
testcase_02 | AC | 2 ms
6,944 KB |
testcase_03 | TLE | - |
testcase_04 | -- | - |
testcase_05 | -- | - |
testcase_06 | -- | - |
testcase_07 | -- | - |
testcase_08 | -- | - |
testcase_09 | -- | - |
ソースコード
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <atcoder/modint> #include <atcoder/math> using namespace std; using i32 = int; using u32 = unsigned int; using i64 = long long; using u64 = unsigned long long; #define rep(i,n) for(int i=0; i<(int)(n); i++) const i64 INF = 1001001001001001001; using Modint = atcoder::static_modint<998244353>; template<class modint> modint TriangleSumTimesLinear( long long n, long long a, long long b, modint c, modint d, modint e ){ if(n <= 0) return modint(0); if(a < b) return TriangleSumTimesLinear(n, b, a, d, c, e); long long maxi = (n - 1) / a + 1; modint offset = 0; offset += c * modint(maxi) * modint(maxi-1) * modint(maxi+1) / modint(6); offset += d * modint(maxi) * modint(maxi-1) * modint(maxi+1) / modint(6); offset += e * modint(maxi) * modint(maxi+1) / modint(2); return offset + TriangleSumTimesLinear(n-maxi*b, b, a-b, d, c-d, e+d*modint(maxi)); } template<class modint> modint AKindOfFloorSum( long long n, long long m, long long a, long long b ){ long long q = b / m; modint tmp = modint(n) * modint(n-1) / 2 * q; b -= q * m; long long newn = a * (n-1) + b - (m-1); if(newn <= 0) return 0; return tmp + TriangleSumTimesLinear<modint>(newn, a, m, -1, 0, n-1); } template<class modint> modint BKindOfFloorSum( long long n, long long m, long long a, long long b ){ long long q = b / m; modint tmp = modint(n) * modint(n-1) / 2 * q; b -= q * m; long long newn = a * (n-1) + b - (m-1); if(newn <= 0) return 0; return tmp + TriangleSumTimesLinear<modint>(newn, a, m, 0, 0, 1); } using Modint1 = atcoder::static_modint<1000000007>; using Modint2 = atcoder::static_modint<1000000009>; template<class modint> modint find_mod( long long N, long long M, long long X, long long Y ){ modint x1 = AKindOfFloorSum<modint>(N, M, X, Y) * 2; modint x2 = BKindOfFloorSum<modint>(N, M, X, Y) * (1-N); modint x3 = AKindOfFloorSum<modint>(N, M, X, 0); modint x4 = BKindOfFloorSum<modint>(N, M, X, 0) * (-N); return x1 + x2 + x3 + x4; } int main(){ int T; cin >> T; rep(t,T){ long long N,M,X,Y; cin >> N >> M >> X >> Y; auto x1 = find_mod<Modint1>(N, M, X, Y); auto x2 = find_mod<Modint2>(N, M, X, Y); long long ans = atcoder::crt({ x1.val(), x2.val() }, { x1.mod(), x2.mod() }).first; cout << ans << '\n'; } return 0; } struct ios_do_not_sync{ ios_do_not_sync(){ ios::sync_with_stdio(false); cin.tie(nullptr); } } ios_do_not_sync_instance;