結果
問題 | No.1746 Sqrt Integer Segments |
ユーザー | 👑 Nachia |
提出日時 | 2021-11-18 00:46:05 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 672 ms / 2,000 ms |
コード長 | 2,106 bytes |
コンパイル時間 | 1,094 ms |
コンパイル使用メモリ | 100,976 KB |
実行使用メモリ | 91,240 KB |
最終ジャッジ日時 | 2023-10-11 10:38:47 |
合計ジャッジ時間 | 17,523 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 364 ms
77,856 KB |
testcase_01 | AC | 358 ms
77,872 KB |
testcase_02 | AC | 570 ms
87,376 KB |
testcase_03 | AC | 443 ms
83,456 KB |
testcase_04 | AC | 496 ms
85,092 KB |
testcase_05 | AC | 650 ms
91,240 KB |
testcase_06 | AC | 414 ms
82,168 KB |
testcase_07 | AC | 370 ms
79,196 KB |
testcase_08 | AC | 537 ms
87,148 KB |
testcase_09 | AC | 639 ms
91,072 KB |
testcase_10 | AC | 416 ms
81,876 KB |
testcase_11 | AC | 598 ms
89,808 KB |
testcase_12 | AC | 645 ms
91,216 KB |
testcase_13 | AC | 665 ms
91,112 KB |
testcase_14 | AC | 636 ms
91,120 KB |
testcase_15 | AC | 651 ms
91,236 KB |
testcase_16 | AC | 672 ms
91,180 KB |
testcase_17 | AC | 520 ms
86,200 KB |
testcase_18 | AC | 379 ms
78,656 KB |
testcase_19 | AC | 378 ms
78,824 KB |
testcase_20 | AC | 381 ms
78,664 KB |
testcase_21 | AC | 385 ms
78,460 KB |
testcase_22 | AC | 385 ms
78,540 KB |
testcase_23 | AC | 372 ms
78,140 KB |
testcase_24 | AC | 411 ms
78,836 KB |
testcase_25 | AC | 416 ms
78,668 KB |
testcase_26 | AC | 414 ms
78,724 KB |
testcase_27 | AC | 426 ms
78,808 KB |
testcase_28 | AC | 418 ms
78,768 KB |
testcase_29 | AC | 417 ms
78,648 KB |
ソースコード
#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<=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; }