結果
| 問題 |
No.1746 Sqrt Integer Segments
|
| ユーザー |
Nachia
|
| 提出日時 | 2021-11-18 00:36:11 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,108 bytes |
| コンパイル時間 | 1,161 ms |
| コンパイル使用メモリ | 95,384 KB |
| 最終ジャッジ日時 | 2025-01-25 19:12:26 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 12 WA * 16 |
ソースコード
#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;
}
Nachia