結果
問題 | No.1036 Make One With GCD 2 |
ユーザー | 👑 emthrm |
提出日時 | 2020-04-25 20:30:37 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 590 ms / 2,000 ms |
コード長 | 2,220 bytes |
コンパイル時間 | 2,958 ms |
コンパイル使用メモリ | 205,632 KB |
実行使用メモリ | 87,296 KB |
最終ジャッジ日時 | 2024-04-25 08:37:04 |
合計ジャッジ時間 | 18,498 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 559 ms
87,168 KB |
testcase_01 | AC | 414 ms
87,168 KB |
testcase_02 | AC | 387 ms
87,168 KB |
testcase_03 | AC | 61 ms
32,768 KB |
testcase_04 | AC | 105 ms
57,728 KB |
testcase_05 | AC | 4 ms
5,376 KB |
testcase_06 | AC | 3 ms
5,376 KB |
testcase_07 | AC | 141 ms
37,248 KB |
testcase_08 | AC | 129 ms
31,104 KB |
testcase_09 | AC | 423 ms
85,248 KB |
testcase_10 | AC | 450 ms
79,488 KB |
testcase_11 | AC | 438 ms
87,040 KB |
testcase_12 | AC | 427 ms
80,256 KB |
testcase_13 | AC | 516 ms
83,328 KB |
testcase_14 | AC | 529 ms
84,096 KB |
testcase_15 | AC | 487 ms
78,976 KB |
testcase_16 | AC | 486 ms
79,616 KB |
testcase_17 | AC | 493 ms
81,920 KB |
testcase_18 | AC | 2 ms
5,376 KB |
testcase_19 | AC | 3 ms
5,376 KB |
testcase_20 | AC | 3 ms
5,376 KB |
testcase_21 | AC | 4 ms
5,376 KB |
testcase_22 | AC | 473 ms
78,080 KB |
testcase_23 | AC | 363 ms
58,112 KB |
testcase_24 | AC | 494 ms
81,152 KB |
testcase_25 | AC | 452 ms
74,112 KB |
testcase_26 | AC | 498 ms
76,672 KB |
testcase_27 | AC | 2 ms
5,376 KB |
testcase_28 | AC | 2 ms
5,376 KB |
testcase_29 | AC | 2 ms
5,376 KB |
testcase_30 | AC | 2 ms
5,376 KB |
testcase_31 | AC | 2 ms
5,376 KB |
testcase_32 | AC | 2 ms
5,376 KB |
testcase_33 | AC | 2 ms
5,376 KB |
testcase_34 | AC | 2 ms
5,376 KB |
testcase_35 | AC | 2 ms
5,376 KB |
testcase_36 | AC | 2 ms
5,376 KB |
testcase_37 | AC | 2 ms
5,376 KB |
testcase_38 | AC | 368 ms
87,168 KB |
testcase_39 | AC | 556 ms
87,296 KB |
testcase_40 | AC | 364 ms
58,112 KB |
testcase_41 | AC | 590 ms
87,168 KB |
testcase_42 | AC | 563 ms
87,168 KB |
testcase_43 | AC | 568 ms
87,296 KB |
testcase_44 | AC | 590 ms
87,296 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; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fLL; const double EPS = 1e-8; const int MOD = 1000000007; // const int MOD = 998244353; const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1}; const 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 <typename MeetSemilattice> struct SparseTable { using Fn = function<MeetSemilattice(MeetSemilattice, MeetSemilattice)>; SparseTable() {} SparseTable(const vector<MeetSemilattice> &a, Fn fn, MeetSemilattice UNITY = 0) { init(a, fn); } void init(const vector<MeetSemilattice> &a, Fn fn_) { fn = fn_; int n = a.size(), table_h = 0; lg.assign(n + 1, 0); FOR(i, 2, n + 1) lg[i] = lg[i >> 1] + 1; while ((1 << table_h) <= n) ++table_h; dat.assign(table_h, vector<MeetSemilattice>(n)); REP(j, n) dat[0][j] = a[j]; FOR(i, 1, table_h) for (int j = 0; j + (1 << i) <= n; ++j) { dat[i][j] = fn(dat[i - 1][j], dat[i - 1][j + (1 << (i - 1))]); } } MeetSemilattice query(int left, int right) { assert(left < right); int h = lg[right - left]; return fn(dat[h][left], dat[h][right - (1 << h)]); } private: Fn fn; vector<int> lg; vector<vector<MeetSemilattice> > dat; }; int main() { int n; cin >> n; vector<ll> a(n); REP(i, n) cin >> a[i]; SparseTable<ll> st(a, [](ll a, ll b) { return gcd(a, b); }); ll ans = 0; REP(i, n) { if (a[i] == 1) { ans += n - i; continue; } int lb = i, ub = n; while (ub - lb > 1) { int mid = (lb + ub) >> 1; (st.query(i, mid + 1) > 1 ? lb : ub) = mid; } ans += n - ub; } cout << ans << '\n'; return 0; }