結果

問題 No.1746 Sqrt Integer Segments
ユーザー 👑 NachiaNachia
提出日時 2021-11-18 00:36:11
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,108 bytes
コンパイル時間 1,174 ms
コンパイル使用メモリ 101,028 KB
実行使用メモリ 87,208 KB
最終ジャッジ日時 2023-08-25 22:08:56
合計ジャッジ時間 16,071 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 318 ms
75,544 KB
testcase_01 AC 320 ms
75,468 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 350 ms
76,284 KB
testcase_19 AC 359 ms
76,432 KB
testcase_20 AC 351 ms
76,284 KB
testcase_21 AC 345 ms
75,764 KB
testcase_22 AC 355 ms
75,792 KB
testcase_23 AC 335 ms
75,504 KB
testcase_24 AC 379 ms
76,340 KB
testcase_25 AC 376 ms
76,256 KB
testcase_26 AC 383 ms
76,332 KB
testcase_27 AC 388 ms
76,320 KB
testcase_28 AC 395 ms
76,328 KB
testcase_29 AC 395 ms
76,456 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using m32 = atcoder::modint998244353;

struct RollingHashed{
  atcoder::static_modint<998244053> a;
  atcoder::static_modint<1000000009> b;
  unsigned int base = 357;

  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::static_modint<998244053>(base).pow(r); b *= atcoder::static_modint<1000000009>(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