結果

問題 No.1746 Sqrt Integer Segments
ユーザー 👑 NachiaNachia
提出日時 2021-11-18 00:31:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,070 bytes
コンパイル時間 1,082 ms
コンパイル使用メモリ 100,864 KB
実行使用メモリ 87,204 KB
最終ジャッジ日時 2023-08-25 21:58:09
合計ジャッジ時間 12,700 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 237 ms
75,536 KB
testcase_01 AC 237 ms
75,692 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 263 ms
76,332 KB
testcase_19 AC 263 ms
76,292 KB
testcase_20 AC 272 ms
76,288 KB
testcase_21 AC 269 ms
75,756 KB
testcase_22 AC 259 ms
75,756 KB
testcase_23 AC 255 ms
75,944 KB
testcase_24 AC 303 ms
76,596 KB
testcase_25 AC 294 ms
76,284 KB
testcase_26 AC 294 ms
76,288 KB
testcase_27 AC 303 ms
76,640 KB
testcase_28 AC 302 ms
76,284 KB
testcase_29 AC 300 ms
76,468 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <atcoder/modint>
using namespace std;

using m32 = atcoder::modint998244353;

struct RollingHashed{
  atcoder::modint998244353 a;
  atcoder::modint1000000007 b;
  unsigned int base = 3;

  RollingHashed(unsigned long long c = 0){ a = c; b = c; }
  bool operator==(RollingHashed r) const { return a == r.a && b == r.b; }
  RollingHashed& parallel_add(RollingHashed r) { a += r.a; b += r.b; return *this; }
  RollingHashed& parallel_subtract(RollingHashed r) { a -= r.a; b -= r.b; return *this; }
  bool operator<(RollingHashed r) const { return (a == r.a) ? (b.val() < r.b.val()) : (a.val() < r.a.val()); }
  RollingHashed& operator<<=(unsigned long long r){ a *= atcoder::modint998244353(base).pow(r); b *= atcoder::modint1000000007(base).pow(r); return *this; }
  RollingHashed operator<<(unsigned long long r){ auto buf = *this; buf <<= r; return buf; }
};


vector<int> unsquared;
vector<vector<int>> factor_list;
vector<RollingHashed> hashed;

int Z = 1000000;


int main(){
  unsquared.assign(Z+1,0);
  for(int i=1; i<=Z; i++) unsquared[i] = i;
  for(int i=1; i*i<=Z; i++) for(int k=1; k*i*i<=Z; k++) unsquared[k*i*i] = k;

  factor_list.resize(Z+1);
  for(int i=2; i*i<=Z; i++) if(factor_list[i].empty()) for(int j=i; j<=Z; j+=i) factor_list[j].push_back(i);

  hashed.resize(Z+1);
  for(int i=2; i<=Z; i++) if(factor_list[i].size() == 1){
    RollingHashed g = RollingHashed(1) << i;
    hashed[i] = g;
  }

  int N; cin >> N;
  vector<int> A(N);
  vector<int> prime_flag(Z+1, 0);
  for(auto& a : A){ int x; cin >> x; a = unsquared[x]; }

  map<RollingHashed, int> cnt;
  RollingHashed nowhash = RollingHashed(0);
  cnt[nowhash]++;
  for(auto& a : A){
    for(int c : factor_list[a]){
      if(prime_flag[c] == 0) nowhash.parallel_add(hashed[c]);
      else nowhash.parallel_subtract(hashed[c]);
      prime_flag[c] ^= 1;
    }
    cnt[nowhash]++;
  }

  long long ans = 0;
  for(auto a : cnt) ans += (long long)a.second * (a.second-1) / 2;
  cout << ans << endl;

  return 0;
}

0