結果

問題 No.1746 Sqrt Integer Segments
ユーザー miscalcmiscalc
提出日時 2021-11-18 01:08:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 2,934 bytes
コンパイル時間 2,427 ms
コンパイル使用メモリ 219,840 KB
実行使用メモリ 814,196 KB
最終ジャッジ日時 2023-08-25 22:58:46
合計ジャッジ時間 5,942 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
27,628 KB
testcase_01 AC 73 ms
27,748 KB
testcase_02 MLE -
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 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/modint>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
//using mint = modint1000000007;
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
using tlll = tuple<ll, ll, ll>;
constexpr ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll safemod(ll A, ll M) {return (A % M + M) % M;}
ll divfloor(ll A, ll B) {if (B < 0) {return divfloor(-A, -B);} return (A - safemod(A, B)) / B;}
ll divceil(ll A, ll B) {if (B < 0) {return divceil(-A, -B);} return divfloor(A + B - 1, B);}
#define FINALANS(A) do {cout << (A) << '\n'; exit(0);} while (false)

class eratosthenes
{
public:
  vector<bool> isprime;
  vector<ll> primes;
  vector<ll> primeid;
  vector<ll> minfactor;
  vector<ll> mobius;

  eratosthenes(ll N)
  {
    isprime.assign(N + 1, true);
    primeid.assign(N + 1, -1);
    minfactor.assign(N + 1, -1);
    mobius.assign(N + 1, 1);
    isprime.at(0) = false, isprime.at(1) = false;
    minfactor.at(1) = 1;

    for (ll p = 2; p <= N; p++)
    {
      if (!isprime.at(p))
        continue;

      primeid.at(p) = primes.size();
      primes.emplace_back(p);
      minfactor.at(p) = p;
      mobius.at(p) = -1;

      for (ll k = 2; k * p <= N; k++)
      {
        isprime.at(k * p) = false;
        if (minfactor.at(k * p) == -1)
          minfactor.at(k * p) = p;
        if (k % p == 0)
          mobius.at(k * p) = 0;
        else
          mobius.at(k * p) *= -1;
      }
    }
  }

  vector<pll> factorize(ll n)
  {
    vector<pll> ret;
    while (n > 1)
    {
      ll p = minfactor.at(n);
      ll e = 0;
      while (minfactor.at(n) == p)
      {
        n /= p;
        e++;
      }
      ret.emplace_back(make_pair(p, e));
    }
    return ret;
  }
};

const ll M = 1000000;
eratosthenes er(M);

const ll T = 78498;
using bs = bitset<T>;
bs f(ll a)
{
  bs ret = (bs)0;
  auto pes = er.factorize(a);
  for (auto pe : pes)
  {
    auto [p, e] = pe;
    if (e % 2 == 1)
      ret.set(er.primeid.at(p));
  }
  return ret;
}

int main()
{
  ll N;
  cin >> N;
  vector<ll> A(N);
  for (ll i = 0; i < N; i++)
  {
    cin >> A.at(i);
  }

  vector<bs> B(N);
  for (ll i = 0; i < N; i++)
  {
    B.at(i) = f(A.at(i));
  }

  vector<bs> S(N + 1);
  S.at(0) = (bs)0;
  for (ll i = 0; i < N; i++)
  {
    S.at(i + 1) = S.at(i) ^ B.at(i);
  }

  sort(S.begin(), S.end(), [&](bs b1, bs b2)
       {for (ll i = 0; i < T; i++)
  {
    if (!b1.test(i) && b2.test(i))
      return true;
    if (b1.test(i) && !b2.test(i))
      return false;
  }
  return true; });
  ll ans = 0;
  ll cnt = 1;
  for (ll i = 0; i < N; i++)
  {
    if (S.at(i) == S.at(i + 1))
      cnt++;
    else
    {
      ans += cnt * (cnt - 1) / 2;
      cnt = 1;
    }
  }
  ans += cnt * (cnt - 1) / 2;

  cout << ans << endl;
}
0