結果
問題 | No.1233 割り切れない気持ち |
ユーザー | 沙耶花 |
提出日時 | 2020-09-18 21:57:17 |
言語 | C++17 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 167 ms / 3,153 ms |
コード長 | 4,897 bytes |
コンパイル時間 | 2,102 ms |
コンパイル使用メモリ | 202,572 KB |
実行使用メモリ | 8,076 KB |
最終ジャッジ日時 | 2023-09-04 21:47:14 |
合計ジャッジ時間 | 6,884 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 20 ms
7,932 KB |
testcase_01 | AC | 12 ms
7,740 KB |
testcase_02 | AC | 31 ms
7,748 KB |
testcase_03 | AC | 52 ms
7,744 KB |
testcase_04 | AC | 44 ms
7,896 KB |
testcase_05 | AC | 33 ms
7,856 KB |
testcase_06 | AC | 37 ms
7,760 KB |
testcase_07 | AC | 88 ms
7,800 KB |
testcase_08 | AC | 98 ms
7,844 KB |
testcase_09 | AC | 119 ms
7,764 KB |
testcase_10 | AC | 122 ms
8,020 KB |
testcase_11 | AC | 79 ms
7,932 KB |
testcase_12 | AC | 132 ms
7,800 KB |
testcase_13 | AC | 127 ms
8,032 KB |
testcase_14 | AC | 129 ms
7,804 KB |
testcase_15 | AC | 132 ms
7,760 KB |
testcase_16 | AC | 136 ms
7,808 KB |
testcase_17 | AC | 38 ms
7,808 KB |
testcase_18 | AC | 167 ms
7,752 KB |
testcase_19 | AC | 67 ms
7,932 KB |
testcase_20 | AC | 43 ms
7,932 KB |
testcase_21 | AC | 51 ms
7,924 KB |
testcase_22 | AC | 50 ms
7,800 KB |
testcase_23 | AC | 49 ms
7,764 KB |
testcase_24 | AC | 50 ms
7,852 KB |
testcase_25 | AC | 50 ms
7,864 KB |
testcase_26 | AC | 49 ms
7,804 KB |
testcase_27 | AC | 57 ms
7,800 KB |
testcase_28 | AC | 57 ms
7,756 KB |
testcase_29 | AC | 57 ms
8,076 KB |
testcase_30 | AC | 57 ms
7,872 KB |
testcase_31 | AC | 57 ms
7,800 KB |
testcase_32 | AC | 57 ms
7,788 KB |
testcase_33 | AC | 57 ms
7,752 KB |
testcase_34 | AC | 57 ms
8,024 KB |
testcase_35 | AC | 57 ms
7,752 KB |
testcase_36 | AC | 57 ms
7,812 KB |
testcase_37 | AC | 12 ms
7,920 KB |
testcase_38 | AC | 43 ms
7,868 KB |
testcase_39 | AC | 102 ms
7,812 KB |
testcase_40 | AC | 102 ms
7,748 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; }