結果

問題 No.3594 Subset OR
ユーザー Jeroen Op de Beek
提出日時 2026-07-23 22:13:01
言語 C++23
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 527 ms / 3,000 ms
+ 447µs
コード長 1,759 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,824 ms
コンパイル使用メモリ 346,164 KB
実行使用メモリ 134,912 KB
最終ジャッジ日時 2026-07-23 22:13:30
合計ジャッジ時間 27,507 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 37
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#pragma GCC optimize("O3")
#include "bits/stdc++.h"
using namespace std;
#define all(x) x.begin(),x.end()
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << p.first << " " << p.second; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { string sep; for (const T &x : v) os << sep << x, sep = " "; return os; }
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#define ASSERT(...) 42
#endif
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pi;
const int oo = 1e9;
const int N = 1<<30;
const int B = 64;
const int K = N/B;

typedef unsigned long long ull;
ull x[K];
int ans[1<<16];
int calc4(ull x) {
    return ans[x];
}
int calc2(ull x) {
    ull y = x>>(B/4);
    return calc4(y) + calc4((x|y) &( (1ULL<<(B/4)) - 1) );
    
}
int calc(ull x) {
    ull y = x>>(B/2);
    return calc2((x|y)&( (1ULL<<(B/2)) - 1))+calc2(y);
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n; cin >> n;
    for(int i=0;i<1<<16;++i) {
        bool b[16] = {};
        for(int j=0;j<16;++j) b[j] = i>>j&1;
        for(int j=0;j<4;++j) {
            for(int x=0;x<16;++x) if(!(1<<j & x)) {
                b[x]|=b[x|1<<j];
            }
        }
        for(int j=0;j<16;++j) ans[i]+=b[j];
    }
    while(n--) {
        int a; cin >> a;
        x[a/B]|=1ULL<<(a%B);
    }
    for(int j=0;(1<<j)<K;++j) {
        for(int i=0;i<K;++i) if(!(1<<j & i)) {
            x[i]|=x[i|1<<j];
        }
    }
    int res=0;
    for(int i=0;i<K;++i) {
        res+=calc(x[i]);
    }
    cout << res << '\n';
}
0