結果

問題 No.1036 Make One With GCD 2
ユーザー stoqstoq
提出日時 2020-04-24 23:06:07
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,466 bytes
コンパイル時間 2,508 ms
コンパイル使用メモリ 178,580 KB
実行使用メモリ 24,536 KB
最終ジャッジ日時 2023-08-06 23:55:56
合計ジャッジ時間 10,922 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
using namespace std;
using ll = long long int;

ll temp;
inline ll gcd(ll a, ll b)
{
  if (a < b)
    swap(a, b);
  while (b != 0)
  {
    temp = b;
    b = a % b;
    a = temp;
  }
  return a;
}

ll a[500010];

ll n;
int N;
ll dat[2000010];

void init()
{
  for (int i = n; i < N; ++i)
    dat[i + N - 1] = 0;
  for (int i = N - 2; i >= 0; --i)
    dat[i] = gcd(dat[i * 2 + 1], dat[i * 2 + 2]);
}

ll val_left, val_right;
ll query(int a, int b)
{
  val_left = 0;
  val_right = 0;
  for (a += (N - 1), b += (N - 1); a < b; a >>= 1, b >>= 1)
  {
    if ((a & 1) == 0)
    {
      val_left = gcd(val_left, dat[a]);
    }
    if ((b & 1) == 0)
    {
      val_right = gcd(val_right, dat[--b]);
    }
  }
  return gcd(val_left, val_right);
}

int main()
{
  /*
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);
*/

  cin >> n;
  N = 1;
  while (N < n)
    N *= 2;
  int i;
  for (i = 0; i < n; i++)
    scanf("%lld", &dat[i + N - 1]);
  init();
  if (dat[0] > 1)
  {
    printf("0\n");
    return 0;
  }
  ll ans = (n + 1) * n / 2;
  int lo, hi, mi;
  for (i = 0; i < n; i++)
  {
    lo = i, hi = n + 1;
    while (hi - lo > 1)
    {
      mi = (lo + hi) / 2;
      if (query(i, mi) > 1)
        lo = mi;
      else
        hi = mi;
    }
    ans -= (lo - i);
  }
  printf("%lld\n", ans);

  return 0;
}
0