結果

問題 No.1746 Sqrt Integer Segments
ユーザー HIcoderHIcoder
提出日時 2023-07-23 21:31:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 742 ms / 2,000 ms
コード長 1,708 bytes
コンパイル時間 2,896 ms
コンパイル使用メモリ 123,516 KB
実行使用メモリ 22,556 KB
最終ジャッジ日時 2023-10-25 05:31:59
合計ジャッジ時間 15,464 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 505 ms
17,276 KB
testcase_03 AC 260 ms
11,204 KB
testcase_04 AC 356 ms
13,844 KB
testcase_05 AC 703 ms
22,292 KB
testcase_06 AC 209 ms
9,884 KB
testcase_07 AC 68 ms
5,660 KB
testcase_08 AC 492 ms
17,012 KB
testcase_09 AC 720 ms
22,292 KB
testcase_10 AC 189 ms
9,356 KB
testcase_11 AC 655 ms
20,444 KB
testcase_12 AC 742 ms
22,556 KB
testcase_13 AC 742 ms
22,556 KB
testcase_14 AC 738 ms
22,556 KB
testcase_15 AC 737 ms
22,556 KB
testcase_16 AC 741 ms
22,556 KB
testcase_17 AC 427 ms
15,428 KB
testcase_18 AC 36 ms
8,036 KB
testcase_19 AC 37 ms
8,036 KB
testcase_20 AC 37 ms
8,036 KB
testcase_21 AC 195 ms
5,660 KB
testcase_22 AC 192 ms
5,660 KB
testcase_23 AC 96 ms
4,348 KB
testcase_24 AC 390 ms
8,036 KB
testcase_25 AC 392 ms
8,036 KB
testcase_26 AC 392 ms
8,036 KB
testcase_27 AC 161 ms
8,036 KB
testcase_28 AC 160 ms
8,036 KB
testcase_29 AC 160 ms
8,036 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/*
ハッシュ化
*/
#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;

}
0