結果

問題 No.1746 Sqrt Integer Segments
ユーザー ぷらぷら
提出日時 2021-11-18 00:48:11
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 232 ms / 2,000 ms
コード長 1,497 bytes
コンパイル時間 2,427 ms
コンパイル使用メモリ 214,540 KB
実行使用メモリ 29,720 KB
最終ジャッジ日時 2023-10-11 10:37:57
合計ジャッジ時間 7,791 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 22 ms
14,692 KB
testcase_01 AC 21 ms
14,604 KB
testcase_02 AC 171 ms
25,372 KB
testcase_03 AC 98 ms
20,832 KB
testcase_04 AC 128 ms
22,664 KB
testcase_05 AC 227 ms
29,344 KB
testcase_06 AC 81 ms
19,320 KB
testcase_07 AC 40 ms
16,344 KB
testcase_08 AC 164 ms
25,132 KB
testcase_09 AC 231 ms
29,592 KB
testcase_10 AC 79 ms
19,156 KB
testcase_11 AC 208 ms
28,124 KB
testcase_12 AC 230 ms
29,716 KB
testcase_13 AC 230 ms
29,720 KB
testcase_14 AC 230 ms
29,456 KB
testcase_15 AC 229 ms
29,496 KB
testcase_16 AC 232 ms
29,544 KB
testcase_17 AC 150 ms
23,988 KB
testcase_18 AC 54 ms
17,056 KB
testcase_19 AC 52 ms
16,984 KB
testcase_20 AC 52 ms
16,996 KB
testcase_21 AC 61 ms
15,724 KB
testcase_22 AC 59 ms
16,000 KB
testcase_23 AC 41 ms
15,260 KB
testcase_24 AC 99 ms
16,984 KB
testcase_25 AC 99 ms
17,120 KB
testcase_26 AC 99 ms
17,064 KB
testcase_27 AC 114 ms
17,032 KB
testcase_28 AC 115 ms
17,040 KB
testcase_29 AC 114 ms
16,992 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

mt19937_64 rng;

struct primenumber {
    vector<int> spf;
    vector<long long>pura;
    primenumber(int N) {
        init(N);
    }
    void init(int N) {
        spf.assign(N+1,0);
        pura.assign(N+1,0);
        for(int i = 0; i <= N; i++) {
            spf[i] = i;
            pura[i] = rng()%1001001001001001001;
        }
        for(int i = 2; i*i <= N; i++) {
            if(spf[i] == i) {
                for(int j = i*i; j <= N; j += i) {
                    if(spf[j] == j) {
                        spf[j] = i;
                    }
                }
            }
        }
    }
    bool is_prime(long long n) {
        bool flag = true;
        if(n == 1) {
            flag = false;
        }
        for(long long i = 2; i*i <= n; i++) {
            if(n%i == 0) {
                flag = false;
            }
        }
        return flag;
    }
    long long get(int n) {
        long long m = 0;
        while(n != 1) {
            m ^= pura[spf[n]];
            n /= spf[n];
        }
        return m;
    }
};

int main() {
    int n;
    cin >> n;
    vector<int>a(n);
    vector<long long>b(n+1);
    primenumber zz(1000001);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        b[i+1] = b[i]^zz.get(a[i]);
    }
    sort(b.begin(),b.end());
    long long ans = 0;
    map<long long,int>tmp;
    for(int i = 0; i < b.size(); i++) {
        ans += tmp[b[i]];
        tmp[b[i]]++;
    }
    cout << ans << endl;
}
0