結果
| 問題 |
No.2697 Range LIS Query
|
| コンテスト | |
| ユーザー |
eve__fuyuki
|
| 提出日時 | 2024-03-23 05:24:09 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 463 ms / 10,000 ms |
| コード長 | 1,773 bytes |
| コンパイル時間 | 2,402 ms |
| コンパイル使用メモリ | 202,620 KB |
| 最終ジャッジ日時 | 2025-02-20 13:04:17 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 15 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/lazysegtree>
using namespace std;
using namespace atcoder;
struct S {
int sz;
array<array<int, 4>, 4> cnt;
};
S e() {
S res;
res.sz = 0;
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
res.cnt[i][j] = 0;
}
}
return res;
}
S op(S a, S b) {
S res = e();
res.sz = a.sz + b.sz;
for (int i = 0; i < 4; i++) {
for (int j = i; j < 4; j++) {
for (int k = j; k < 4; k++) {
for (int l = k; l < 4; l++) {
res.cnt[i][l] =
max(res.cnt[i][l], a.cnt[i][j] + b.cnt[k][l]);
}
}
}
}
return res;
}
S mapping(int f, S x) {
if (f == -1) {
return x;
}
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
x.cnt[i][j] = 0;
}
}
x.cnt[f][f] = x.sz;
return x;
}
int composition(int f, int g) {
if (f == -1) {
return g;
}
return f;
}
int id() { return -1; }
void fast_io() {
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
}
int main() {
fast_io();
int n;
cin >> n;
vector<S> a(n, e());
for (int i = 0; i < n; i++) {
int x;
cin >> x;
x--;
a[i].sz = 1;
a[i].cnt[x][x] = 1;
}
lazy_segtree<S, op, e, int, mapping, composition, id> seg(a);
int q;
cin >> q;
for (; q--;) {
int type;
cin >> type;
if (type == 1) {
int l, r;
cin >> l >> r;
cout << seg.prod(l - 1, r).cnt[0][3] << "\n";
} else {
int l, r, x;
cin >> l >> r >> x;
seg.apply(l - 1, r, x - 1);
}
}
}
eve__fuyuki