結果

問題 No.1233 割り切れない気持ち
ユーザー vjudge1
提出日時 2025-08-15 16:20:16
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 17 ms / 3,153 ms
コード長 6,441 bytes
コンパイル時間 1,923 ms
コンパイル使用メモリ 199,900 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-08-15 16:20:21
合計ジャッジ時間 4,221 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 39
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:26:39: warning: bad option ‘-fwhole-program’ to pragma ‘optimize’ [-Wpragmas]
   26 | #pragma GCC optimize("-fwhole-program")
      |                                       ^
main.cpp:33:41: warning: bad option ‘-fstrict-overflow’ to pragma ‘optimize’ [-Wpragmas]
   33 | #pragma GCC optimize("-fstrict-overflow")
      |                                         ^
main.cpp:35:41: warning: bad option ‘-fcse-skip-blocks’ to pragma ‘optimize’ [-Wpragmas]
   35 | #pragma GCC optimize("-fcse-skip-blocks")
      |                                         ^
main.cpp:49:51: warning: bad option ‘-funsafe-loop-optimizations’ to pragma ‘optimize’ [-Wpragmas]
   49 | #pragma GCC optimize("-funsafe-loop-optimizations")
      |                                                   ^
main.cpp:52:32: warning: bad option ‘-funroll 8’ to pragma ‘optimize’ [-Wpragmas]
   52 | #pragma GCC optimize("unroll 8")
      |                                ^
main.cpp:62:31: warning: bad option ‘-fwhole-program’ to attribute ‘optimize’ [-Wattributes]
   62 | inline bool blank(const char x) {return !(x^32)||!(x^10)||!(x^13)||!(x^9);}
      |                               ^
main.cpp:62:31: warning: bad option ‘-fstrict-overflow’ to attribute ‘optimize’ [-Wattributes]
main.cpp:62:31: warning: bad option ‘-fcse-skip-blocks’ to attribute ‘optimize’ [-Wattributes]
main.cpp:62:31: warning: bad option ‘-funsafe-loop-optimizations’ to attribute ‘optimize’ [-Wattributes]
main.cpp:62:31: warning: bad option ‘-funroll 8’ to attribute ‘optimize’ [-Wattributes]
main.cpp:63:45: warning: bad option ‘-fwhole-program’ to attribute ‘optimize’ [-Wattributes]
   63 | template<typename Tp> inline void read(Tp &x) {x=0; register bool z=true; register char a=gc(); for(;!isdigit(a);a=gc()) if(a=='-') z=false; for(;isdigit(a);a=gc()) x=(x<<1)+(x<<3)+(a^48); x=(z?x:~x+1);}
      |                                             ^
main.cpp:

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#pragma GCC optimize(8)
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
#pragma GCC optimize("unroll 8")


#ifdef __linux__
#define gc getchar_unlocked
#define pc putchar_unlocked
#else
#define gc _getchar_nolock
#define pc _putchar_nolock
#endif
inline bool blank(const char x) {return !(x^32)||!(x^10)||!(x^13)||!(x^9);}
template<typename Tp> inline void read(Tp &x) {x=0; register bool z=true; register char a=gc(); for(;!isdigit(a);a=gc()) if(a=='-') z=false; for(;isdigit(a);a=gc()) x=(x<<1)+(x<<3)+(a^48); x=(z?x:~x+1);}
inline void read(double &x) {x=0.0; register bool z=true; register double y=0.1; register char a=gc(); for(;!isdigit(a);a=gc()) if(a=='-') z=false; for(;isdigit(a);a=gc()) x=x*10+(a^48); if(a!='.') return x=z?x:-x,void(); for(a=gc();isdigit(a);a=gc(),y/=10) x+=y*(a^48); x=(z?x:-x);}
inline void read(char &x) {for(x=gc();blank(x)&&(x^-1);x=gc());}
inline void read(char *x) {register char a=gc(); for(;blank(a)&&(a^-1);a=gc()); for(;!blank(a)&&(a^-1);a=gc()) *x++=a; *x=0;}
inline void read(string &x) {x=""; register char a=gc(); for(;blank(a)&&(a^-1);a=gc()); for(;!blank(a)&&(a^-1);a=gc()) x+=a;}
template<typename T,typename ...Tp> inline void read(T &x,Tp &...y) {read(x),read(y...);}
template<typename Tp> inline void write(Tp x) {if(!x) return pc(48),void(); if(x<0) pc('-'),x=~x+1; register int len=0; register char tmp[64]; for(;x;x/=10) tmp[++len]=x%10+48; while(len) pc(tmp[len--]);}
inline void write(const double x) {register int a=6; register double b=x,c=b; if(b<0) pc('-'),b=-b,c=-c; register double y=5*powl(10,-a-1); b+=y,c+=y; register int len=0; register char tmp[64]; if(b<1) pc(48); else for(;b>=1;b/=10) tmp[++len]=floor(b)-floor(b/10)*10+48; while(len) pc(tmp[len--]); pc('.'); for(c*=10;a;a--,c*=10) pc(floor(c)-floor(c/10)*10+48);}
inline void write(const pair<int,double>x) {register int a=x.first; if(a<7) {register double b=x.second,c=b; if(b<0) pc('-'),b=-b,c=-c; register double y=5*powl(10,-a-1); b+=y,c+=y; register int len=0; register char tmp[64]; if(b<1) pc(48); else for(;b>=1;b/=10) tmp[++len]=floor(b)-floor(b/10)*10+48; while(len) pc(tmp[len--]); a&&(pc('.')); for(c*=10;a;a--,c*=10) pc(floor(c)-floor(c/10)*10+48);} else cout<<fixed<<setprecision(a)<<x.second;}
inline void write(const char x) {pc(x);}
inline void write(const bool x) {pc(x?49:48);}
inline void write(char *x) {fputs(x,stdout);}
inline void write(const char *x) {fputs(x,stdout);}
inline void write(const string &x) {fputs(x.c_str(),stdout);}
template<typename T,typename ...Tp> inline void write(T x,Tp ...y) {write(x),write(y...);}


const int N = 2e5 + 1;
ll cnt[N];

int main(){
    ///ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);

///    freopen("mod.in", "r", stdin);
///    freopen("mod.out", "w", stdout);

    int n;
    ll ans = 0;
    ll a[N];

    read(n);
    for(int i = 1; i <= n; i ++){
        read(a[i]);
        cnt[a[i]] ++;
        ans += a[i] * n;
    }

    for(int i = 1; i < N; i ++){
        cnt[i] += cnt[i - 1];
    }

    for(int mod = 1; mod < N; mod ++){
        for(int k = 0; k * mod < N; k += 8){
            n = k * mod - 1;
            ans -= (n + 1 < N ? (cnt[(n + mod >= N ? N - 1 : n + mod)] - (n >= 0 ? cnt[n] : 0)) * (cnt[mod] - cnt[mod - 1]) * (n + 1) : 0);
            n += mod;
            ans -= (n + 1 < N ? (cnt[(n + mod >= N ? N - 1 : n + mod)] - (n >= 0 ? cnt[n] : 0)) * (cnt[mod] - cnt[mod - 1]) * (n + 1) : 0);
            n += mod;
            ans -= (n + 1 < N ? (cnt[(n + mod >= N ? N - 1 : n + mod)] - (n >= 0 ? cnt[n] : 0)) * (cnt[mod] - cnt[mod - 1]) * (n + 1) : 0);
            n += mod;
            ans -= (n + 1 < N ? (cnt[(n + mod >= N ? N - 1 : n + mod)] - (n >= 0 ? cnt[n] : 0)) * (cnt[mod] - cnt[mod - 1]) * (n + 1) : 0);
            n += mod;
            ans -= (n + 1 < N ? (cnt[(n + mod >= N ? N - 1 : n + mod)] - (n >= 0 ? cnt[n] : 0)) * (cnt[mod] - cnt[mod - 1]) * (n + 1) : 0);
            n += mod;
            ans -= (n + 1 < N ? (cnt[(n + mod >= N ? N - 1 : n + mod)] - (n >= 0 ? cnt[n] : 0)) * (cnt[mod] - cnt[mod - 1]) * (n + 1) : 0);
            n += mod;
            ans -= (n + 1 < N ? (cnt[(n + mod >= N ? N - 1 : n + mod)] - (n >= 0 ? cnt[n] : 0)) * (cnt[mod] - cnt[mod - 1]) * (n + 1) : 0);
            n += mod;
            ans -= (n + 1 < N ? (cnt[(n + mod >= N ? N - 1 : n + mod)] - (n >= 0 ? cnt[n] : 0)) * (cnt[mod] - cnt[mod - 1]) * (n + 1) : 0);
        }
    }

    write(ans);

    return 0;
}

/***

3
1 5 3

8
8 8 8 8 8 8 8 8

***/

0