結果
問題 | No.1746 Sqrt Integer Segments |
ユーザー | rogi52 |
提出日時 | 2022-03-09 22:08:04 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 297 ms / 2,000 ms |
コード長 | 4,004 bytes |
コンパイル時間 | 2,315 ms |
コンパイル使用メモリ | 217,448 KB |
実行使用メモリ | 35,736 KB |
最終ジャッジ日時 | 2023-10-11 10:49:52 |
合計ジャッジ時間 | 8,558 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 43 ms
19,368 KB |
testcase_01 | AC | 45 ms
19,316 KB |
testcase_02 | AC | 197 ms
30,940 KB |
testcase_03 | AC | 116 ms
25,836 KB |
testcase_04 | AC | 149 ms
27,892 KB |
testcase_05 | AC | 271 ms
35,460 KB |
testcase_06 | AC | 97 ms
24,412 KB |
testcase_07 | AC | 59 ms
20,980 KB |
testcase_08 | AC | 192 ms
30,712 KB |
testcase_09 | AC | 271 ms
35,668 KB |
testcase_10 | AC | 92 ms
23,972 KB |
testcase_11 | AC | 247 ms
34,004 KB |
testcase_12 | AC | 274 ms
35,624 KB |
testcase_13 | AC | 279 ms
35,668 KB |
testcase_14 | AC | 283 ms
35,600 KB |
testcase_15 | AC | 287 ms
35,736 KB |
testcase_16 | AC | 297 ms
35,716 KB |
testcase_17 | AC | 177 ms
29,364 KB |
testcase_18 | AC | 58 ms
23,308 KB |
testcase_19 | AC | 59 ms
23,268 KB |
testcase_20 | AC | 60 ms
23,252 KB |
testcase_21 | AC | 68 ms
21,348 KB |
testcase_22 | AC | 67 ms
21,280 KB |
testcase_23 | AC | 57 ms
20,364 KB |
testcase_24 | AC | 91 ms
23,240 KB |
testcase_25 | AC | 89 ms
23,196 KB |
testcase_26 | AC | 91 ms
23,236 KB |
testcase_27 | AC | 117 ms
23,288 KB |
testcase_28 | AC | 120 ms
23,264 KB |
testcase_29 | AC | 118 ms
23,324 KB |
ソースコード
#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); using H = pair<uint,uint>; vector<H> hash_p(1010101); for(int p : sieve.primes) hash_p[p] = {randint(), randint()}; vector<H> hash_a(n); rep(i,n) { auto ds = sieve.factorize(a[i]); for(auto [p, e] : ds) { if(e % 2 == 1) { hash_a[i].first ^= hash_p[p].first; hash_a[i].second ^= hash_p[p].second; } } } vector<H> hash_sum(n + 1, {0, 0}); rep(i,n) { hash_sum[i + 1].first ^= (hash_sum[i].first ^ hash_a[i].first); hash_sum[i + 1].second ^= (hash_sum[i].second ^ hash_a[i].second); } ll ans = 0; map<H,ll> mp; rep(i,n+1) { ans += mp[hash_sum[i]]; mp[hash_sum[i]]++; } cout << ans << endl; }