結果

問題 No.2171 OR Assignment
ユーザー suisen
提出日時 2022-12-23 01:15:15
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 224 ms / 3,500 ms
コード長 1,209 bytes
コンパイル時間 1,102 ms
コンパイル使用メモリ 85,684 KB
最終ジャッジ日時 2025-02-09 18:49:20
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <array>
#include <iostream>
#include <vector>

#include <atcoder/modint>

using mint = atcoder::modint998244353;

constexpr int L = 30;

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int n;
    std::cin >> n;

    std::vector<int> a(n);
    for (auto &&e : a) std::cin >> e;

    std::array<int, L> last;
    last.fill(-1);

    std::vector<int> ppos;
    std::vector<mint> pd { 1 };
    for (int i = 0; i < n; ++i) {
        std::vector<int> pos;
        for (int j = 0; j < L; ++j) {
            if ((a[i] >> j) & 1) {
                last[j] = i;
            } else if (last[j] >= 0) {
                pos.push_back(last[j]);
            }
        }
        std::sort(pos.begin(), pos.end());
        pos.erase(std::unique(pos.begin(), pos.end()), pos.end());
        pos.push_back(i);

        const int siz = pos.size();
        std::vector<mint> dp(siz + 1);
        for (int k = 0, j = 0; k < siz; ++k) {
            while (j < int(ppos.size()) and ppos[j] <= pos[k]) ++j;
            dp[k + 1] = dp[k] + pd[j];
        }
        pd.swap(dp);
        ppos.swap(pos);
    }
    std::cout << pd.back().val() << std::endl;
    return 0;
}
0