結果
| 問題 | No.2171 OR Assignment |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-12-23 00:58:29 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 304 ms / 3,500 ms |
| コード長 | 1,364 bytes |
| 記録 | |
| コンパイル時間 | 1,090 ms |
| コンパイル使用メモリ | 89,016 KB |
| 最終ジャッジ日時 | 2025-02-09 18:47:43 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 30 |
ソースコード
#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<std::vector<int>, L> pos{};
std::vector<std::vector<int>> pre(n);
for (int i = 0; i < n; ++i) {
for (int j = 0; j < L; ++j) {
if ((a[i] >> j) & 1) {
pos[j].push_back(i);
} else if (pos[j].size()) {
pre[i].push_back(pos[j].back());
}
}
std::sort(pre[i].begin(), pre[i].end());
pre[i].erase(std::unique(pre[i].begin(), pre[i].end()), pre[i].end());
pre[i].push_back(i);
}
std::vector<std::vector<mint>> dp(n);
dp[0].push_back(1);
for (int i = 1; i < n; ++i) {
int j = 0;
mint sum = 0;
for (int k = 0; k < int(pre[i].size()); ++k) {
while (j < int(pre[i - 1].size()) and pre[i - 1][j] <= pre[i][k]) {
sum += dp[i - 1][j++];
}
dp[i].push_back(sum);
}
}
mint ans = std::accumulate(dp[n - 1].begin(), dp[n - 1].end(), mint(0));
std::cout << ans.val() << std::endl;
return 0;
}