結果
問題 | No.1261 数字集め |
ユーザー | msm1993 |
提出日時 | 2020-10-23 15:40:47 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 2,519 ms / 8,000 ms |
コード長 | 4,100 bytes |
コンパイル時間 | 1,824 ms |
コンパイル使用メモリ | 171,848 KB |
実行使用メモリ | 133,632 KB |
最終ジャッジ日時 | 2024-07-21 10:14:26 |
合計ジャッジ時間 | 171,104 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2,393 ms
133,164 KB |
testcase_01 | AC | 740 ms
56,960 KB |
testcase_02 | AC | 1,700 ms
100,352 KB |
testcase_03 | AC | 1,682 ms
101,364 KB |
testcase_04 | AC | 1,154 ms
71,168 KB |
testcase_05 | AC | 2,275 ms
128,548 KB |
testcase_06 | AC | 1,221 ms
78,592 KB |
testcase_07 | AC | 1,736 ms
104,464 KB |
testcase_08 | AC | 958 ms
65,664 KB |
testcase_09 | AC | 1,240 ms
81,024 KB |
testcase_10 | AC | 257 ms
21,504 KB |
testcase_11 | AC | 2,351 ms
126,916 KB |
testcase_12 | AC | 2,103 ms
115,200 KB |
testcase_13 | AC | 1,745 ms
105,612 KB |
testcase_14 | AC | 281 ms
27,520 KB |
testcase_15 | AC | 969 ms
60,160 KB |
testcase_16 | AC | 1,774 ms
104,584 KB |
testcase_17 | AC | 1,374 ms
87,364 KB |
testcase_18 | AC | 882 ms
61,184 KB |
testcase_19 | AC | 1,816 ms
101,816 KB |
testcase_20 | AC | 314 ms
29,824 KB |
testcase_21 | AC | 2,353 ms
133,504 KB |
testcase_22 | AC | 2,503 ms
133,548 KB |
testcase_23 | AC | 2,360 ms
133,376 KB |
testcase_24 | AC | 2,427 ms
133,412 KB |
testcase_25 | AC | 2,498 ms
133,508 KB |
testcase_26 | AC | 2,519 ms
133,488 KB |
testcase_27 | AC | 2,411 ms
133,504 KB |
testcase_28 | AC | 2,443 ms
133,604 KB |
testcase_29 | AC | 2,419 ms
133,416 KB |
testcase_30 | AC | 2,440 ms
133,632 KB |
testcase_31 | AC | 2,381 ms
133,432 KB |
testcase_32 | AC | 2,460 ms
133,632 KB |
testcase_33 | AC | 2,506 ms
133,504 KB |
testcase_34 | AC | 2,408 ms
133,632 KB |
testcase_35 | AC | 2,364 ms
133,400 KB |
testcase_36 | AC | 2,387 ms
133,404 KB |
testcase_37 | AC | 2,349 ms
133,624 KB |
testcase_38 | AC | 2,364 ms
133,408 KB |
testcase_39 | AC | 2,407 ms
133,588 KB |
testcase_40 | AC | 2,399 ms
133,504 KB |
testcase_41 | AC | 2,476 ms
133,628 KB |
testcase_42 | AC | 2,411 ms
133,492 KB |
testcase_43 | AC | 2,323 ms
133,624 KB |
testcase_44 | AC | 2,052 ms
119,680 KB |
testcase_45 | AC | 573 ms
40,320 KB |
testcase_46 | AC | 1,085 ms
72,960 KB |
testcase_47 | AC | 790 ms
55,936 KB |
testcase_48 | AC | 1,717 ms
102,912 KB |
testcase_49 | AC | 2,013 ms
118,400 KB |
testcase_50 | AC | 1,790 ms
107,648 KB |
testcase_51 | AC | 491 ms
43,392 KB |
testcase_52 | AC | 236 ms
20,736 KB |
testcase_53 | AC | 556 ms
43,392 KB |
testcase_54 | AC | 611 ms
46,976 KB |
testcase_55 | AC | 336 ms
31,872 KB |
testcase_56 | AC | 401 ms
35,584 KB |
testcase_57 | AC | 1,692 ms
98,304 KB |
testcase_58 | AC | 479 ms
41,088 KB |
testcase_59 | AC | 2,102 ms
121,344 KB |
testcase_60 | AC | 561 ms
46,208 KB |
testcase_61 | AC | 773 ms
57,216 KB |
testcase_62 | AC | 1,940 ms
110,436 KB |
testcase_63 | AC | 347 ms
33,920 KB |
testcase_64 | AC | 2,309 ms
129,340 KB |
testcase_65 | AC | 1,482 ms
90,912 KB |
testcase_66 | AC | 1,248 ms
78,848 KB |
testcase_67 | AC | 1,796 ms
111,360 KB |
testcase_68 | AC | 1,197 ms
75,776 KB |
testcase_69 | AC | 1,109 ms
74,368 KB |
testcase_70 | AC | 922 ms
62,336 KB |
testcase_71 | AC | 1,738 ms
105,940 KB |
testcase_72 | AC | 628 ms
49,664 KB |
testcase_73 | AC | 853 ms
55,168 KB |
testcase_74 | AC | 430 ms
36,096 KB |
testcase_75 | AC | 1,149 ms
70,656 KB |
testcase_76 | AC | 1,617 ms
98,816 KB |
testcase_77 | AC | 1,968 ms
112,128 KB |
testcase_78 | AC | 230 ms
19,328 KB |
testcase_79 | AC | 2,007 ms
115,584 KB |
testcase_80 | AC | 234 ms
20,480 KB |
testcase_81 | AC | 270 ms
28,544 KB |
testcase_82 | AC | 1,524 ms
94,080 KB |
testcase_83 | AC | 696 ms
51,456 KB |
testcase_84 | AC | 2,397 ms
133,576 KB |
testcase_85 | AC | 2,278 ms
133,600 KB |
testcase_86 | AC | 2,318 ms
133,504 KB |
testcase_87 | AC | 2,326 ms
133,456 KB |
testcase_88 | AC | 2,494 ms
133,560 KB |
testcase_89 | AC | 2,505 ms
133,428 KB |
testcase_90 | AC | 2,426 ms
133,504 KB |
testcase_91 | AC | 2,478 ms
133,528 KB |
testcase_92 | AC | 2,492 ms
133,504 KB |
testcase_93 | AC | 2,436 ms
133,632 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for(int i = 0; i < n; i++) #define rep2(i, x, n) for(int i = x; i <= n; i++) #define rep3(i, x, n) for(int i = x; i >= n; i--) #define elif else if #define sp(x) fixed << setprecision(x) #define pb push_back #define eb emplace_back #define all(x) x.begin(), x.end() #define sz(x) (int)x.size() using ll = long long; using pii = pair<int, int>; using pil = pair<int, ll>; using pli = pair<ll, int>; using pll = pair<ll, ll>; const int MOD = 1000000007; //const int MOD = 998244353; const int inf = (1<<30)-1; const ll INF = (1LL<<60)-1; const double pi = acos(-1.0); const double EPS = 1e-10; template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;}; template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;}; template<int mod> struct Mod_Int{ ll x; Mod_Int() : x(0) {} Mod_Int(ll y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {} Mod_Int &operator += (const Mod_Int &p){ x = (x + p.x) % mod; return *this; } Mod_Int &operator -= (const Mod_Int &p){ x = (x + mod - p.x) % mod; return *this; } Mod_Int &operator *= (const Mod_Int &p){ x = (x * p.x) % mod; return *this; } Mod_Int &operator /= (const Mod_Int &p){ *this *= p.inverse(); return *this; } Mod_Int &operator ++ () {return *this += Mod_Int(1);} Mod_Int operator ++ (int){ Mod_Int tmp = *this; ++*this; return tmp; } Mod_Int &operator -- () {return *this -= Mod_Int(1);} Mod_Int operator -- (int){ Mod_Int tmp = *this; --*this; return tmp; } Mod_Int operator - () const {return Mod_Int(-x);} Mod_Int operator + (const Mod_Int &p) const {return Mod_Int(*this) += p;} Mod_Int operator - (const Mod_Int &p) const {return Mod_Int(*this) -= p;} Mod_Int operator * (const Mod_Int &p) const {return Mod_Int(*this) *= p;} Mod_Int operator / (const Mod_Int &p) const {return Mod_Int(*this) /= p;} bool operator == (const Mod_Int &p) const {return x == p.x;} bool operator != (const Mod_Int &p) const {return x != p.x;} Mod_Int inverse() const { assert(*this != Mod_Int(0)); return pow(mod-2); } Mod_Int pow(ll k) const{ Mod_Int now = *this, ret = 1; while(k){ if(k&1) ret *= now; now *= now, k >>= 1; } return ret; } friend ostream &operator << (ostream &os, const Mod_Int &p){ return os << p.x; } friend istream &operator >> (istream &is, Mod_Int &p){ ll a; is >> a; p = Mod_Int<mod>(a); return is; } }; using mint = Mod_Int<MOD>; const int MAX = 1000000; int A[MAX+1]; mint iv[MAX+1], pw[MAX+1]; mint inv(int a){ if(a > 0) return iv[a]; else return iv[abs(a)]*(-1); } mint calc(int i, int j, int k){ int a = A[i], b = A[j], c = A[k]; return (pw[a]*(b-c)+pw[b]*(c-a)+pw[c]*(a-b))*inv(a-b)*inv(b-c)*inv(c-a); } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int N, M; cin >> N >> M; rep2(i, 2, N){ cin >> A[i]; A[i]--; } bool st[N+1], en[N+1]; fill(st, st+N+1, false), fill(en, en+N+1, false); rep2(i, 2, N-1){ st[i] = true, en[i] = (N%i == 0); } rep2(i, 1, MAX) iv[i] = mint(i).inverse(); rep2(i, 1, MAX) pw[i] = mint(i).pow(M-1); vector<int> es[N+1]; mint ans = 0; rep2(i, 2, N-1){ for(int j = i+i; j <= N; j += i){ es[j].pb(i); if(st[i] && en[j]) ans -= calc(i, j, N); } } cout << ans << '\n'; int Q; cin >> Q; while(Q--){ int x, y; cin >> x >> y; if(y < N){ es[y].pb(x); if(st[x] && en[y]) ans -= calc(x, y, N); } else{ en[x] = true; for(auto &e: es[x]){ if(st[e]) ans -= calc(e, x, N); } } cout << ans << '\n'; } }