結果
問題 | No.1261 数字集め |
ユーザー | tokusakurai |
提出日時 | 2020-10-17 16:56:57 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 2,026 ms / 8,000 ms |
コード長 | 4,100 bytes |
コンパイル時間 | 2,868 ms |
コンパイル使用メモリ | 204,884 KB |
実行使用メモリ | 133,632 KB |
最終ジャッジ日時 | 2024-07-21 05:47:49 |
合計ジャッジ時間 | 127,998 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1,918 ms
133,248 KB |
testcase_01 | AC | 556 ms
56,704 KB |
testcase_02 | AC | 1,360 ms
100,480 KB |
testcase_03 | AC | 1,274 ms
101,376 KB |
testcase_04 | AC | 760 ms
71,168 KB |
testcase_05 | AC | 1,801 ms
128,640 KB |
testcase_06 | AC | 897 ms
78,592 KB |
testcase_07 | AC | 1,262 ms
104,448 KB |
testcase_08 | AC | 629 ms
65,664 KB |
testcase_09 | AC | 844 ms
80,768 KB |
testcase_10 | AC | 240 ms
21,504 KB |
testcase_11 | AC | 1,870 ms
126,784 KB |
testcase_12 | AC | 1,569 ms
115,328 KB |
testcase_13 | AC | 1,321 ms
105,728 KB |
testcase_14 | AC | 273 ms
27,520 KB |
testcase_15 | AC | 573 ms
60,160 KB |
testcase_16 | AC | 1,448 ms
104,576 KB |
testcase_17 | AC | 1,037 ms
87,552 KB |
testcase_18 | AC | 624 ms
61,056 KB |
testcase_19 | AC | 1,305 ms
101,632 KB |
testcase_20 | AC | 309 ms
29,696 KB |
testcase_21 | AC | 1,832 ms
133,504 KB |
testcase_22 | AC | 1,810 ms
133,632 KB |
testcase_23 | AC | 1,947 ms
133,504 KB |
testcase_24 | AC | 2,019 ms
133,632 KB |
testcase_25 | AC | 1,877 ms
133,504 KB |
testcase_26 | AC | 1,879 ms
133,504 KB |
testcase_27 | AC | 1,892 ms
133,376 KB |
testcase_28 | AC | 1,840 ms
133,632 KB |
testcase_29 | AC | 1,845 ms
133,376 KB |
testcase_30 | AC | 1,812 ms
133,504 KB |
testcase_31 | AC | 1,832 ms
133,632 KB |
testcase_32 | AC | 1,815 ms
133,504 KB |
testcase_33 | AC | 1,829 ms
133,632 KB |
testcase_34 | AC | 1,941 ms
133,632 KB |
testcase_35 | AC | 1,873 ms
133,504 KB |
testcase_36 | AC | 1,910 ms
133,504 KB |
testcase_37 | AC | 1,903 ms
133,632 KB |
testcase_38 | AC | 1,838 ms
133,376 KB |
testcase_39 | AC | 1,809 ms
133,504 KB |
testcase_40 | AC | 1,841 ms
133,632 KB |
testcase_41 | AC | 1,860 ms
133,504 KB |
testcase_42 | AC | 1,883 ms
133,504 KB |
testcase_43 | AC | 1,895 ms
133,632 KB |
testcase_44 | AC | 1,590 ms
119,552 KB |
testcase_45 | AC | 353 ms
40,320 KB |
testcase_46 | AC | 754 ms
72,832 KB |
testcase_47 | AC | 526 ms
55,808 KB |
testcase_48 | AC | 1,231 ms
102,656 KB |
testcase_49 | AC | 1,530 ms
118,528 KB |
testcase_50 | AC | 1,325 ms
107,648 KB |
testcase_51 | AC | 359 ms
43,264 KB |
testcase_52 | AC | 218 ms
20,736 KB |
testcase_53 | AC | 368 ms
43,392 KB |
testcase_54 | AC | 399 ms
46,848 KB |
testcase_55 | AC | 276 ms
31,872 KB |
testcase_56 | AC | 310 ms
35,456 KB |
testcase_57 | AC | 1,219 ms
98,304 KB |
testcase_58 | AC | 347 ms
40,832 KB |
testcase_59 | AC | 1,618 ms
121,216 KB |
testcase_60 | AC | 402 ms
45,952 KB |
testcase_61 | AC | 523 ms
57,344 KB |
testcase_62 | AC | 1,465 ms
110,208 KB |
testcase_63 | AC | 279 ms
33,920 KB |
testcase_64 | AC | 1,792 ms
129,408 KB |
testcase_65 | AC | 1,044 ms
91,008 KB |
testcase_66 | AC | 848 ms
78,976 KB |
testcase_67 | AC | 1,393 ms
111,232 KB |
testcase_68 | AC | 761 ms
75,776 KB |
testcase_69 | AC | 752 ms
74,112 KB |
testcase_70 | AC | 593 ms
62,336 KB |
testcase_71 | AC | 1,811 ms
106,064 KB |
testcase_72 | AC | 451 ms
49,536 KB |
testcase_73 | AC | 501 ms
55,040 KB |
testcase_74 | AC | 291 ms
35,840 KB |
testcase_75 | AC | 705 ms
70,656 KB |
testcase_76 | AC | 1,174 ms
98,688 KB |
testcase_77 | AC | 1,410 ms
112,256 KB |
testcase_78 | AC | 200 ms
19,200 KB |
testcase_79 | AC | 1,459 ms
115,456 KB |
testcase_80 | AC | 201 ms
20,352 KB |
testcase_81 | AC | 232 ms
28,416 KB |
testcase_82 | AC | 1,117 ms
93,952 KB |
testcase_83 | AC | 478 ms
51,456 KB |
testcase_84 | AC | 1,898 ms
133,504 KB |
testcase_85 | AC | 1,787 ms
133,504 KB |
testcase_86 | AC | 1,795 ms
133,632 KB |
testcase_87 | AC | 1,810 ms
133,632 KB |
testcase_88 | AC | 1,884 ms
133,504 KB |
testcase_89 | AC | 2,026 ms
133,376 KB |
testcase_90 | AC | 1,998 ms
133,504 KB |
testcase_91 | AC | 1,899 ms
133,504 KB |
testcase_92 | AC | 1,913 ms
133,504 KB |
testcase_93 | AC | 1,850 ms
133,504 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'; } }