結果

問題 No.3662 yuu Hates Sigma Problem
コンテスト
ユーザー くらげ
提出日時 2026-08-21 16:00:50
言語 C++23(gcc16)
(gcc 16.1.0 + boost 1.92.0 + ACL)
コンパイル:
g++-16 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 67 ms / 2,000 ms
+ 930µs
コード長 2,318 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,114 ms
コンパイル使用メモリ 353,144 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2026-08-30 13:02:05
合計ジャッジ時間 6,657 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
サブタスク 配点 結果
subtask1. 20 % AC * 19
subtask2. 30 % AC * 13
subtask3. 50 % AC * 49
合計 2.5 * 100% = 250 点
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(n);i++)

template<ll mod> struct Modint{
    public:
    ll x;
    Modint(ll x=0) : x((x%mod+mod)%mod) {}
    Modint operator-() const { return Modint(-x); }
    Modint& operator+=(const Modint& a){
        if(mod<=(x += a.x)) x-=mod;
        return *this;
    }
    Modint& operator-=(const Modint& a){
        if(mod<=(x+=mod-a.x)) x-=mod;
        return *this;
    }
    Modint& operator*=(const Modint& a){
        (x*=a.x)%=mod;
        return *this;
    }
    Modint& operator++(){
        ++x;
        return *this;
    }
    Modint operator++(int){
        Modint temp = *this;
        x++;
        return temp;
    }
    Modint& operator--(){
        --x;
        return *this;
    }
    Modint operator--(int){
        Modint temp = *this;
        x--;
        return temp;
    }
    Modint pow(ll t) const{
        Modint a=1,b=x;
        while(t){
            if(t&1) a*=b;
            b*=b;
            t/=2;
        }
        return a;
    }
    Modint inv() const { return pow(mod-2); }
    Modint& operator/=(const Modint& a){ return (*this)*=a.inv(); }
    friend Modint operator+(const Modint& a, const Modint& b) { return Modint(a)+=b; }
    friend Modint operator-(const Modint& a, const Modint& b) { return Modint(a)-=b; }
    friend Modint operator*(const Modint& a, const Modint& b) { return Modint(a)*=b; }
    friend Modint operator/(const Modint& a, const Modint& b) { return Modint(a)/=b; }
    friend bool operator==(const Modint& a, const Modint& b) { return (Modint(a).x==b.x); }
    friend bool operator!=(const Modint& a, const Modint& b) { return (Modint(a).x!=b.x); }
    friend ostream& operator<<(ostream& os, const Modint& m){ os << m.x; return os; }
    friend istream& operator>>(istream& is, Modint& m){ is >> m.x; return is; }
};

using fp998 = Modint<998244353>;
using fp107 = Modint<1000000007>;

int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    
    vector<ll> c(20);
    rep(i,n) rep(j,20) if((i>>j)&1) c[j]++;

    fp998 ans = 0;
    rep(i,n){
        fp998 x = 0;
        rep(j,20){
            if((i>>j)&1) x += (1<<j)*(n-c[j]);
            else x += (1<<j)*c[j];
        }
        ans += x*a[i];
    }

    cout << ans << endl;

}
0