結果
問題 | No.1261 数字集め |
ユーザー | 👑 emthrm |
提出日時 | 2020-10-18 17:56:46 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 2,496 ms / 8,000 ms |
コード長 | 5,586 bytes |
コンパイル時間 | 2,620 ms |
コンパイル使用メモリ | 215,320 KB |
実行使用メモリ | 115,968 KB |
最終ジャッジ日時 | 2024-07-21 06:39:08 |
合計ジャッジ時間 | 116,386 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2,496 ms
115,584 KB |
testcase_01 | AC | 409 ms
40,320 KB |
testcase_02 | AC | 1,159 ms
83,200 KB |
testcase_03 | AC | 1,167 ms
84,224 KB |
testcase_04 | AC | 670 ms
54,400 KB |
testcase_05 | AC | 1,613 ms
110,848 KB |
testcase_06 | AC | 681 ms
61,840 KB |
testcase_07 | AC | 1,140 ms
87,040 KB |
testcase_08 | AC | 489 ms
49,024 KB |
testcase_09 | AC | 724 ms
63,952 KB |
testcase_10 | AC | 14 ms
5,504 KB |
testcase_11 | AC | 1,760 ms
109,316 KB |
testcase_12 | AC | 1,375 ms
97,892 KB |
testcase_13 | AC | 1,126 ms
88,436 KB |
testcase_14 | AC | 53 ms
11,520 KB |
testcase_15 | AC | 418 ms
43,904 KB |
testcase_16 | AC | 1,198 ms
87,316 KB |
testcase_17 | AC | 951 ms
70,528 KB |
testcase_18 | AC | 416 ms
44,544 KB |
testcase_19 | AC | 1,096 ms
84,608 KB |
testcase_20 | AC | 81 ms
13,696 KB |
testcase_21 | AC | 1,730 ms
115,916 KB |
testcase_22 | AC | 1,694 ms
115,828 KB |
testcase_23 | AC | 1,735 ms
115,840 KB |
testcase_24 | AC | 1,808 ms
115,712 KB |
testcase_25 | AC | 1,991 ms
115,840 KB |
testcase_26 | AC | 1,789 ms
115,708 KB |
testcase_27 | AC | 1,768 ms
115,804 KB |
testcase_28 | AC | 1,710 ms
115,836 KB |
testcase_29 | AC | 1,625 ms
115,712 KB |
testcase_30 | AC | 1,643 ms
115,832 KB |
testcase_31 | AC | 1,669 ms
115,840 KB |
testcase_32 | AC | 1,680 ms
115,840 KB |
testcase_33 | AC | 1,839 ms
115,712 KB |
testcase_34 | AC | 1,793 ms
115,828 KB |
testcase_35 | AC | 1,728 ms
115,672 KB |
testcase_36 | AC | 1,725 ms
115,968 KB |
testcase_37 | AC | 1,734 ms
115,840 KB |
testcase_38 | AC | 1,793 ms
115,840 KB |
testcase_39 | AC | 1,787 ms
115,712 KB |
testcase_40 | AC | 1,782 ms
115,840 KB |
testcase_41 | AC | 1,822 ms
115,820 KB |
testcase_42 | AC | 1,877 ms
115,840 KB |
testcase_43 | AC | 1,775 ms
115,712 KB |
testcase_44 | AC | 1,477 ms
102,016 KB |
testcase_45 | AC | 175 ms
24,252 KB |
testcase_46 | AC | 759 ms
56,080 KB |
testcase_47 | AC | 354 ms
39,296 KB |
testcase_48 | AC | 1,270 ms
85,632 KB |
testcase_49 | AC | 1,535 ms
100,992 KB |
testcase_50 | AC | 1,346 ms
90,360 KB |
testcase_51 | AC | 231 ms
26,944 KB |
testcase_52 | AC | 24 ms
5,376 KB |
testcase_53 | AC | 192 ms
27,264 KB |
testcase_54 | AC | 268 ms
30,592 KB |
testcase_55 | AC | 89 ms
15,872 KB |
testcase_56 | AC | 147 ms
19,416 KB |
testcase_57 | AC | 1,167 ms
81,152 KB |
testcase_58 | AC | 174 ms
24,796 KB |
testcase_59 | AC | 1,609 ms
103,808 KB |
testcase_60 | AC | 235 ms
29,800 KB |
testcase_61 | AC | 366 ms
40,960 KB |
testcase_62 | AC | 1,371 ms
93,056 KB |
testcase_63 | AC | 91 ms
17,920 KB |
testcase_64 | AC | 1,920 ms
111,788 KB |
testcase_65 | AC | 926 ms
73,972 KB |
testcase_66 | AC | 736 ms
62,080 KB |
testcase_67 | AC | 1,262 ms
94,020 KB |
testcase_68 | AC | 648 ms
58,880 KB |
testcase_69 | AC | 620 ms
57,600 KB |
testcase_70 | AC | 494 ms
45,952 KB |
testcase_71 | AC | 1,227 ms
88,960 KB |
testcase_72 | AC | 275 ms
33,484 KB |
testcase_73 | AC | 388 ms
38,428 KB |
testcase_74 | AC | 162 ms
19,840 KB |
testcase_75 | AC | 668 ms
53,880 KB |
testcase_76 | AC | 1,086 ms
81,664 KB |
testcase_77 | AC | 1,325 ms
94,772 KB |
testcase_78 | AC | 18 ms
5,376 KB |
testcase_79 | AC | 1,448 ms
98,304 KB |
testcase_80 | AC | 37 ms
5,376 KB |
testcase_81 | AC | 65 ms
12,416 KB |
testcase_82 | AC | 1,012 ms
76,764 KB |
testcase_83 | AC | 343 ms
35,200 KB |
testcase_84 | AC | 1,806 ms
115,840 KB |
testcase_85 | AC | 1,848 ms
115,840 KB |
testcase_86 | AC | 1,969 ms
115,816 KB |
testcase_87 | AC | 1,809 ms
115,840 KB |
testcase_88 | AC | 1,913 ms
115,712 KB |
testcase_89 | AC | 1,765 ms
115,840 KB |
testcase_90 | AC | 1,819 ms
115,840 KB |
testcase_91 | AC | 1,841 ms
115,840 KB |
testcase_92 | AC | 1,792 ms
115,828 KB |
testcase_93 | AC | 1,868 ms
115,820 KB |
ソースコード
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; #define FOR(i,m,n) for(int i=(m);i<(n);++i) #define REP(i,n) FOR(i,0,n) #define ALL(v) (v).begin(),(v).end() using ll = long long; constexpr int INF = 0x3f3f3f3f; constexpr ll LINF = 0x3f3f3f3f3f3f3f3fLL; constexpr double EPS = 1e-8; constexpr int MOD = 1000000007; // constexpr int MOD = 998244353; constexpr int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1}; constexpr int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1}; template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; } template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; } struct IOSetup { IOSetup() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(20); } } iosetup; template <int MOD> struct MInt { unsigned val; MInt(): val(0) {} MInt(long long x) : val(x >= 0 ? x % MOD : x % MOD + MOD) {} static int get_mod() { return MOD; } static void set_mod(int divisor) { assert(divisor == MOD); } MInt pow(long long exponent) const { MInt tmp = *this, res = 1; while (exponent > 0) { if (exponent & 1) res *= tmp; tmp *= tmp; exponent >>= 1; } return res; } MInt &operator+=(const MInt &x) { if((val += x.val) >= MOD) val -= MOD; return *this; } MInt &operator-=(const MInt &x) { if((val += MOD - x.val) >= MOD) val -= MOD; return *this; } MInt &operator*=(const MInt &x) { val = static_cast<unsigned long long>(val) * x.val % MOD; return *this; } MInt &operator/=(const MInt &x) { // assert(std::__gcd(static_cast<int>(x.val), MOD) == 1); unsigned a = x.val, b = MOD; int u = 1, v = 0; while (b) { unsigned tmp = a / b; std::swap(a -= tmp * b, b); std::swap(u -= tmp * v, v); } return *this *= u; } bool operator==(const MInt &x) const { return val == x.val; } bool operator!=(const MInt &x) const { return val != x.val; } bool operator<(const MInt &x) const { return val < x.val; } bool operator<=(const MInt &x) const { return val <= x.val; } bool operator>(const MInt &x) const { return val > x.val; } bool operator>=(const MInt &x) const { return val >= x.val; } MInt &operator++() { if (++val == MOD) val = 0; return *this; } MInt operator++(int) { MInt res = *this; ++*this; return res; } MInt &operator--() { val = (val == 0 ? MOD : val) - 1; return *this; } MInt operator--(int) { MInt res = *this; --*this; return res; } MInt operator+() const { return *this; } MInt operator-() const { return MInt(val ? MOD - val : 0); } MInt operator+(const MInt &x) const { return MInt(*this) += x; } MInt operator-(const MInt &x) const { return MInt(*this) -= x; } MInt operator*(const MInt &x) const { return MInt(*this) *= x; } MInt operator/(const MInt &x) const { return MInt(*this) /= x; } friend std::ostream &operator<<(std::ostream &os, const MInt &x) { return os << x.val; } friend std::istream &operator>>(std::istream &is, MInt &x) { long long val; is >> val; x = MInt(val); return is; } }; namespace std { template <int MOD> MInt<MOD> abs(const MInt<MOD> &x) { return x; } } template <int MOD> struct Combinatorics { using ModInt = MInt<MOD>; int val; // "val!" and "mod" must be disjoint. std::vector<ModInt> fact, fact_inv, inv; Combinatorics(int val = 10000000) : val(val), fact(val + 1), fact_inv(val + 1), inv(val + 1) { fact[0] = 1; for (int i = 1; i <= val; ++i) fact[i] = fact[i - 1] * i; fact_inv[val] = ModInt(1) / fact[val]; for (int i = val; i > 0; --i) fact_inv[i - 1] = fact_inv[i] * i; for (int i = 1; i <= val; ++i) inv[i] = fact[i - 1] * fact_inv[i]; } ModInt nCk(int n, int k) const { if (n < 0 || n < k || k < 0) return 0; assert(n <= val && k <= val); return fact[n] * fact_inv[k] * fact_inv[n - k]; } ModInt nPk(int n, int k) const { if (n < 0 || n < k || k < 0) return 0; assert(n <= val); return fact[n] * fact_inv[n - k]; } ModInt nHk(int n, int k) const { if (n < 0 || k < 0) return 0; return k == 0 ? 1 : nCk(n + k - 1, k); } }; using ModInt = MInt<MOD>; ModInt solve(int a, int b, int c, int m) { vector<int> d{a, b, c}; sort(ALL(d)); int x = d[0], y = d[1], z = d[2]; if (x == z) { return ModInt(x).pow(m) * (m + 1) * (m + 2) / 2; } else if (x == y) { return (ModInt(x).pow(m + 1) * (ModInt(m + 1) * x - ModInt(m + 2) * z) + ModInt(z).pow(m + 2)) / ModInt(x - z).pow(2); } else if (y == z) { return (ModInt(x).pow(m + 2) - ModInt(y).pow(m + 1) * (ModInt(m + 1) * y - ModInt(m + 2) * x)) / ModInt(x - y).pow(2); } else { return (ModInt(x).pow(m + 2) * (y - z) + (ModInt(z).pow(m + 2) - ModInt(y).pow(m + 2)) * x + (ModInt(y).pow(m + 1) - ModInt(z).pow(m + 1)) * y * z) / (x - y) / (y - z) / (x - z); } } int main() { int n, m; cin >> n >> m; m -= 3; vector<int> a(n + 1); FOR(i, 2, n + 1) cin >> a[i], --a[i]; vector<bool> to_n(n, false); FOR(i, 3, n) to_n[i] = n % i == 0; vector<vector<int>> from(n); ModInt ans = 0; FOR(i, 2, n) for (int j = i * 2; j < n; j += i) { from[j].emplace_back(i); if (to_n[j]) ans += solve(a[i], a[j], a[n], m); } cout << ans << '\n'; int q; cin >> q; while (q--) { int x, y; cin >> x >> y; if (y == n) { to_n[x] = true; for (int e : from[x]) ans += solve(a[e], a[x], a[n], m); } else { from[y].emplace_back(x); if (to_n[y]) ans += solve(a[x], a[y], a[n], m); } cout << ans << '\n'; } return 0; }