結果

問題 No.1746 Sqrt Integer Segments
ユーザー rogi52rogi52
提出日時 2022-03-09 22:03:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,789 bytes
コンパイル時間 2,459 ms
コンパイル使用メモリ 215,672 KB
実行使用メモリ 30,332 KB
最終ジャッジ日時 2023-10-11 23:30:56
合計ジャッジ時間 10,339 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
15,416 KB
testcase_01 AC 46 ms
15,424 KB
testcase_02 WA -
testcase_03 AC 110 ms
21,348 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 57 ms
16,852 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 90 ms
19,588 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 55 ms
17,904 KB
testcase_19 AC 55 ms
17,796 KB
testcase_20 AC 56 ms
17,844 KB
testcase_21 AC 65 ms
16,712 KB
testcase_22 AC 65 ms
16,856 KB
testcase_23 AC 50 ms
15,952 KB
testcase_24 AC 85 ms
17,816 KB
testcase_25 AC 88 ms
17,844 KB
testcase_26 AC 90 ms
17,952 KB
testcase_27 AC 116 ms
17,764 KB
testcase_28 AC 113 ms
17,812 KB
testcase_29 AC 118 ms
17,840 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

struct Eratosthenes {
    vector<bool> isprime;
    vector<int> primes;
    vector<int> spf; // smallest prime factors
    vector<int> mobius;

    Eratosthenes(int N) : isprime(N + 1, true),
                          spf(N + 1, -1),
                          mobius(N + 1, 1) {
        isprime[1] = false;
        spf[1] = 1;

        for(int p = 2; p <= N; p++){
            if(!isprime[p]) continue;
            primes.push_back(p);
            spf[p] = p;
            mobius[p] = -1;
            for(int q = p * 2; q <= N; q += p){
                isprime[q] = false;
                if(spf[q] == -1) spf[q] = p;
                mobius[q] = ((q / p) % p == 0 ? 0 : -mobius[q]);
            }
        }
    }

    vector<pair<int,int>> factorize(int n) {
        vector<pair<int,int>> res;
        while(n > 1) {
            int p = spf[n], e = 0;
            while(spf[n] == p) n /= p, e++;
            res.push_back({p, e}); // p^e
        }
        return res;
    }

    vector<int> divisors(int n) {
        vector<int> res({1});
        auto pf = factorize(n);
        for(auto p : pf) {
            int s = (int)res.size();
            for(int i = 0; i < s; i++) {
                int v = 1;
                for(int j = 0; j < p.second; j++) {
                    v *= p.first;
                    res.push_back(res[i] * v);
                }
            }
        }
        return res;
    }

    template<class T> void fast_zeta(vector< T > &f) {
        int N = f.size();
        vector<bool> isprime = Eratosthenes(N);
        for(int p = 2; p < N; p++) {
            if(!isprime[p]) continue;
            for(int k = (N - 1) / p; k >= 1; k--) {
                f[k] += f[k * p];
            }
        }
    }

    template<class T> void fast_mobius(vector< T > &F) {
        int N = F.size();
        vector<bool> isprime = Eratosthenes(N);
        for(int p = 2; p < N; p++) {
            if(!isprime[p]) continue;
            for(int k = 1; k * p < N; k++) {
                F[k] -= F[k * p];
            }
        }
    }

    template<class T> vector< T > gcd_convolution(const vector< T > &f, const vector< T > &g) {
        int N = max(f.size(), g.size());
        vector< T > F(N, 0), G(N, 0), H(N);
        for(int i = 0; i < f.size(); i++) F[i] = f[i];
        for(int i = 0; i < g.size(); i++) G[i] = g[i];

        fast_zeta(F);
        fast_zeta(G);

        for(int i = 1; i < N; i++) H[i] = F[i] * G[i];

        fast_mobius(H);
        return H;
    }

    long long fast_euler_phi(int n) {
        auto pf = factorize(n);
        long long res = n;
        for(auto p : pf) {
            res *= p.first - 1;
            res /= p.first;
        }
        return res;
    }
};

using uint = unsigned int;
unsigned int randint() {
    static unsigned int tx = 123456789, ty = 362436069, tz = 521288629, tw = 88675123;
    unsigned int tt = (tx^(tx<<11));
    tx = ty; ty = tz; tz = tw;
    return ( tw=(tw^(tw>>19))^(tt^(tt>>8)) );
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int n; cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];

    Eratosthenes sieve(1010101);
    vector<uint> hash_p(1010101);
    for(int p : sieve.primes) hash_p[p] = randint();

    vector<uint> hash_a(n);
    rep(i,n) {
        auto ds = sieve.factorize(a[i]);
        for(auto [p, e] : ds) {
            if(e % 2 == 1) {
                hash_a[i] ^= hash_p[p];
            }
        }
    }

    vector<uint> hash_sum(n + 1, 0);
    rep(i,n) hash_sum[i + 1] ^= (hash_sum[i] ^ hash_a[i]);

    ll ans = 0;
    map<uint,ll> mp;
    rep(i,n+1) {
        ans += mp[hash_sum[i]];
        mp[hash_sum[i]]++;
    }
    cout << ans << endl;
}
0