結果
| 問題 | No.3763 Compress Pancakes |
| コンテスト | |
| ユーザー |
ei1333333
|
| 提出日時 | 2026-09-11 18:13:04 |
| 言語 | C++23(gcc16) (gcc 16.2.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 102 ms / 2,000 ms |
| + 713µs | |
| コード長 | 1,538 bytes |
| 記録 | |
| コンパイル時間 | 2,256 ms |
| コンパイル使用メモリ | 360,608 KB |
| 実行使用メモリ | 56,136 KB |
| 最終ジャッジ日時 | 2026-10-09 20:50:23 |
| 合計ジャッジ時間 | 8,214 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 29 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/segtree>
using namespace std;
using ll = long long;
struct IoSetup {
IoSetup() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
}
} iosetup;
static bool is_power_of_two(const ll x) {
return x > 0 && (x & (x - 1)) == 0;
}
struct S {
ll sum, mx, pos, odd;
bool ok;
constexpr S() : sum(0), mx(0), pos(0), odd(0), ok(true) {
}
S(ll x) {
const auto w = x & -x;
sum = w;
mx = w;
pos = 0;
odd = x / w;
ok = true;
}
[[nodiscard]] bool can_merge() const {
return odd > 0 && ok && pos % mx == 0 && is_power_of_two(sum);
}
};
static constexpr S op(const S& a, const S &b) {
if (a.sum == 0) return b;
if (b.sum == 0) return a;
S c;
c.sum = a.sum + b.sum;
c.odd = a.odd == b.odd ? a.odd : -1;
const auto d = a.sum + b.pos - a.pos;
c.ok = a.ok && b.ok && d % min(a.mx, b.mx) == 0;
if (a.mx >= b.mx) {
c.mx = a.mx;
c.pos = a.pos;
} else {
c.mx = b.mx;
c.pos = a.sum + b.pos;
}
return c;
}
static constexpr S e() {
return {};
}
int main() {
int N, Q;
cin >> N >> Q;
vector<S> init;
init.reserve(N);
for (int i = 0; i < N; i++) {
int x;
cin >> x;
init.emplace_back(x);
}
atcoder::segtree<S, op, e> seg(init);
while (Q--) {
int t;
cin >> t;
if (t == 1) {
int k, x;
cin >> k >> x;
seg.set(k - 1, x);
} else {
int l, r;
cin >> l >> r;
if (seg.prod(l - 1, r).can_merge()) cout << "Yes\n";
else cout << "No\n";
}
}
}
ei1333333