結果
問題 | No.1036 Make One With GCD 2 |
ユーザー | 👑 emthrm |
提出日時 | 2020-04-30 20:16:28 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 287 ms / 2,000 ms |
コード長 | 2,159 bytes |
コンパイル時間 | 2,254 ms |
コンパイル使用メモリ | 209,292 KB |
実行使用メモリ | 87,128 KB |
最終ジャッジ日時 | 2023-10-14 20:24:54 |
合計ジャッジ時間 | 11,927 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 247 ms
86,940 KB |
testcase_01 | AC | 186 ms
86,948 KB |
testcase_02 | AC | 184 ms
87,040 KB |
testcase_03 | AC | 47 ms
32,524 KB |
testcase_04 | AC | 79 ms
57,544 KB |
testcase_05 | AC | 1 ms
4,348 KB |
testcase_06 | AC | 2 ms
4,356 KB |
testcase_07 | AC | 84 ms
37,020 KB |
testcase_08 | AC | 70 ms
30,964 KB |
testcase_09 | AC | 211 ms
85,104 KB |
testcase_10 | AC | 202 ms
79,320 KB |
testcase_11 | AC | 211 ms
86,680 KB |
testcase_12 | AC | 197 ms
80,164 KB |
testcase_13 | AC | 279 ms
83,216 KB |
testcase_14 | AC | 287 ms
84,040 KB |
testcase_15 | AC | 273 ms
78,824 KB |
testcase_16 | AC | 273 ms
79,568 KB |
testcase_17 | AC | 276 ms
81,864 KB |
testcase_18 | AC | 2 ms
4,352 KB |
testcase_19 | AC | 2 ms
4,352 KB |
testcase_20 | AC | 3 ms
4,348 KB |
testcase_21 | AC | 3 ms
4,352 KB |
testcase_22 | AC | 264 ms
78,036 KB |
testcase_23 | AC | 208 ms
58,120 KB |
testcase_24 | AC | 274 ms
81,068 KB |
testcase_25 | AC | 260 ms
73,896 KB |
testcase_26 | AC | 253 ms
76,812 KB |
testcase_27 | AC | 2 ms
4,372 KB |
testcase_28 | AC | 2 ms
4,352 KB |
testcase_29 | AC | 2 ms
4,352 KB |
testcase_30 | AC | 2 ms
4,352 KB |
testcase_31 | AC | 2 ms
4,348 KB |
testcase_32 | AC | 1 ms
4,368 KB |
testcase_33 | AC | 1 ms
4,352 KB |
testcase_34 | AC | 1 ms
4,348 KB |
testcase_35 | AC | 1 ms
4,352 KB |
testcase_36 | AC | 1 ms
4,348 KB |
testcase_37 | AC | 1 ms
4,352 KB |
testcase_38 | AC | 181 ms
87,004 KB |
testcase_39 | AC | 267 ms
87,128 KB |
testcase_40 | AC | 203 ms
58,056 KB |
testcase_41 | AC | 254 ms
87,088 KB |
testcase_42 | AC | 245 ms
87,088 KB |
testcase_43 | AC | 246 ms
86,884 KB |
testcase_44 | AC | 244 ms
87,008 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; int r = 0; REP(i, n) { if (a[i] == 1) { ans += n - i; continue; } chmax(r, i + 1); while (r < n && st.query(i, r + 1) > 1) ++r; ans += n - r; } cout << ans << '\n'; return 0; }