結果

問題 No.2697 Range LIS Query
ユーザー eve__fuyukieve__fuyuki
提出日時 2024-03-23 05:24:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 399 ms / 10,000 ms
コード長 1,773 bytes
コンパイル時間 2,731 ms
コンパイル使用メモリ 211,520 KB
実行使用メモリ 27,872 KB
最終ジャッジ日時 2024-03-23 05:24:18
合計ジャッジ時間 8,145 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 3 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 9 ms
6,676 KB
testcase_04 AC 9 ms
6,676 KB
testcase_05 AC 9 ms
6,676 KB
testcase_06 AC 358 ms
27,872 KB
testcase_07 AC 331 ms
27,872 KB
testcase_08 AC 329 ms
27,872 KB
testcase_09 AC 259 ms
27,872 KB
testcase_10 AC 292 ms
27,872 KB
testcase_11 AC 265 ms
27,872 KB
testcase_12 AC 202 ms
26,976 KB
testcase_13 AC 225 ms
25,720 KB
testcase_14 AC 340 ms
25,880 KB
testcase_15 AC 366 ms
27,872 KB
testcase_16 AC 365 ms
27,872 KB
testcase_17 AC 399 ms
27,872 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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);
        }
    }
}
0