結果
| 問題 |
No.1746 Sqrt Integer Segments
|
| ユーザー |
|
| 提出日時 | 2023-07-23 21:31:49 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 602 ms / 2,000 ms |
| コード長 | 1,708 bytes |
| コンパイル時間 | 1,231 ms |
| コンパイル使用メモリ | 119,900 KB |
| 最終ジャッジ日時 | 2025-02-15 18:38:27 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 28 |
ソースコード
/*
ハッシュ化
*/
#include<iostream>
#include<set>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<numeric>
#include<queue>
#include<cmath>
#include<random>
//#include<fstream>
using namespace std;
typedef long long ll;
const ll INF=1LL<<60;
typedef pair<ll,ll> P;
typedef pair<int,P> PP;
const ll MOD=998244353;
vector<pair<ll,ll>> prime_factor(ll n){
vector<pair<ll,ll>> res;
for(ll i=2;i*i<=n;i++){
if(n%i==0){
pair<ll,ll> tmp;
tmp.first=i;
tmp.second=0;
while(n%i==0){
tmp.second++;
n/=i;
}
res.push_back(tmp);
}
}
if(n>1){
res.emplace_back(n,1);
n/=n;
}
return res;
}
int main(){
int N;
cin>>N;
vector<ll> a(N);
for(int i=0;i<N;i++){
cin>>a[i];
}
std::random_device seed_gen;
mt19937 engine(seed_gen());
uniform_int_distribution dist(1LL,1LL<<60);//[1,1LL<<60]までの乱数
vector<ll> b(N),c(N+1);
map<ll,ll> mp;//mp[v]=vに対しての乱数
for(int i=0;i<N;i++){
auto c=prime_factor(a[i]);
for(auto [v,num]:c){
if(num%2==1){
if(!mp.count(v)){
mp[v]=dist(engine);//ハッシュ
}
b[i]^=mp[v];
}
}
}
//累積和のxorバージョン
for(int i=0;i<N;i++){
c[i+1]=c[i]^b[i];
}
map<ll,ll> mp2;
for(int i=0;i<N+1;i++){
mp2[c[i]]++;
}
ll ans=0;
for(auto [v,num]:mp2){
//vが同じになる区間
ans+=num*(num-1)/2;
}
cout<<ans<<endl;
}