結果
問題 | No.1233 割り切れない気持ち |
ユーザー | 沙耶花 |
提出日時 | 2020-09-18 21:57:17 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 161 ms / 3,153 ms |
コード長 | 4,897 bytes |
コンパイル時間 | 2,146 ms |
コンパイル使用メモリ | 206,628 KB |
実行使用メモリ | 8,192 KB |
最終ジャッジ日時 | 2024-06-22 19:15:16 |
合計ジャッジ時間 | 6,184 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 19 ms
7,936 KB |
testcase_01 | AC | 11 ms
7,936 KB |
testcase_02 | AC | 27 ms
8,064 KB |
testcase_03 | AC | 45 ms
7,936 KB |
testcase_04 | AC | 41 ms
8,064 KB |
testcase_05 | AC | 30 ms
8,064 KB |
testcase_06 | AC | 31 ms
7,936 KB |
testcase_07 | AC | 75 ms
7,936 KB |
testcase_08 | AC | 84 ms
7,936 KB |
testcase_09 | AC | 110 ms
7,936 KB |
testcase_10 | AC | 118 ms
7,936 KB |
testcase_11 | AC | 72 ms
8,064 KB |
testcase_12 | AC | 132 ms
7,936 KB |
testcase_13 | AC | 121 ms
7,936 KB |
testcase_14 | AC | 118 ms
7,936 KB |
testcase_15 | AC | 129 ms
8,192 KB |
testcase_16 | AC | 133 ms
7,936 KB |
testcase_17 | AC | 39 ms
7,936 KB |
testcase_18 | AC | 161 ms
7,936 KB |
testcase_19 | AC | 67 ms
7,936 KB |
testcase_20 | AC | 41 ms
7,936 KB |
testcase_21 | AC | 49 ms
7,936 KB |
testcase_22 | AC | 48 ms
8,064 KB |
testcase_23 | AC | 48 ms
7,936 KB |
testcase_24 | AC | 50 ms
8,064 KB |
testcase_25 | AC | 47 ms
7,936 KB |
testcase_26 | AC | 49 ms
7,936 KB |
testcase_27 | AC | 57 ms
7,936 KB |
testcase_28 | AC | 61 ms
7,936 KB |
testcase_29 | AC | 62 ms
7,936 KB |
testcase_30 | AC | 63 ms
7,936 KB |
testcase_31 | AC | 60 ms
8,064 KB |
testcase_32 | AC | 62 ms
8,064 KB |
testcase_33 | AC | 61 ms
7,936 KB |
testcase_34 | AC | 59 ms
7,936 KB |
testcase_35 | AC | 59 ms
7,936 KB |
testcase_36 | AC | 61 ms
7,936 KB |
testcase_37 | AC | 12 ms
7,936 KB |
testcase_38 | AC | 44 ms
7,936 KB |
testcase_39 | AC | 95 ms
7,936 KB |
testcase_40 | AC | 97 ms
7,936 KB |
ソースコード
#include <stdio.h> #include <bits/stdc++.h> #include <cassert> #include <numeric> #include <type_traits> namespace atcoder { namespace internal { #ifndef _MSC_VER template <class T> using is_signed_int128 = typename std::conditional<std::is_same<T, __int128_t>::value || std::is_same<T, __int128>::value, std::true_type, std::false_type>::type; template <class T> using is_unsigned_int128 = typename std::conditional<std::is_same<T, __uint128_t>::value || std::is_same<T, unsigned __int128>::value, std::true_type, std::false_type>::type; template <class T> using make_unsigned_int128 = typename std::conditional<std::is_same<T, __int128_t>::value, __uint128_t, unsigned __int128>; template <class T> using is_integral = typename std::conditional<std::is_integral<T>::value || is_signed_int128<T>::value || is_unsigned_int128<T>::value, std::true_type, std::false_type>::type; template <class T> using is_signed_int = typename std::conditional<(is_integral<T>::value && std::is_signed<T>::value) || is_signed_int128<T>::value, std::true_type, std::false_type>::type; template <class T> using is_unsigned_int = typename std::conditional<(is_integral<T>::value && std::is_unsigned<T>::value) || is_unsigned_int128<T>::value, std::true_type, std::false_type>::type; template <class T> using to_unsigned = typename std::conditional< is_signed_int128<T>::value, make_unsigned_int128<T>, typename std::conditional<std::is_signed<T>::value, std::make_unsigned<T>, std::common_type<T>>::type>::type; #else template <class T> using is_integral = typename std::is_integral<T>; template <class T> using is_signed_int = typename std::conditional<is_integral<T>::value && std::is_signed<T>::value, std::true_type, std::false_type>::type; template <class T> using is_unsigned_int = typename std::conditional<is_integral<T>::value && std::is_unsigned<T>::value, std::true_type, std::false_type>::type; template <class T> using to_unsigned = typename std::conditional<is_signed_int<T>::value, std::make_unsigned<T>, std::common_type<T>>::type; #endif template <class T> using is_signed_int_t = std::enable_if_t<is_signed_int<T>::value>; template <class T> using is_unsigned_int_t = std::enable_if_t<is_unsigned_int<T>::value>; template <class T> using to_unsigned_t = typename to_unsigned<T>::type; } // namespace internal } // namespace atcoder #include <cassert> #include <vector> namespace atcoder { // Reference: https://en.wikipedia.org/wiki/Fenwick_tree template <class T> struct fenwick_tree { using U = internal::to_unsigned_t<T>; public: fenwick_tree() : _n(0) {} fenwick_tree(int n) : _n(n), data(n) {} void add(int p, T x) { assert(0 <= p && p < _n); p++; while (p <= _n) { data[p - 1] += U(x); p += p & -p; } } T sum(int l, int r) { assert(0 <= l && l <= r && r <= _n); return sum(r) - sum(l); } private: int _n; std::vector<U> data; U sum(int r) { U s = 0; while (r > 0) { s += data[r - 1]; r -= r & -r; } return s; } }; } // namespace atcoder using namespace atcoder; using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf 1000000000 int main(){ vector<long long> A(200001,0LL); int N; cin>>N; rep(i,N){ int a; cin>>a; A[a] ++; } fenwick_tree<long long> B0(A.size()); rep(i,A.size())B0.add(i,A[i]); fenwick_tree<long long> B1(A.size()); rep(i,A.size())B1.add(i,A[i]*i); long long ans = 0LL; rep(i,A.size()){ if(A[i]==0)continue; long long temp = 0LL; for(int j=0;j<A.size();j+=i){ int r =min(j+i,(int)A.size()); temp += B1.sum(j,r) - B0.sum(j,r) * j; } ans += temp * A[i]; } cout<<ans<<endl; return 0; }