結果

問題 No.2697 Range LIS Query
ユーザー Today03
提出日時 2024-03-22 23:14:57
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 652 ms / 10,000 ms
コード長 2,165 bytes
コンパイル時間 2,572 ms
コンパイル使用メモリ 207,596 KB
最終ジャッジ日時 2025-02-20 12:30:15
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#ifdef LOCAL
#include "./debug.cpp"
#else
#define debug(...)
#define print_line
#endif
using namespace std;
using ll = long long;

#include <atcoder/lazysegtree>
using namespace atcoder;

struct S {
    array<array<int, 4>, 4> a;
    int len = 0;
    S() {
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 4; j++) {
                a[i][j] = 0;
            }
        }
    }
};

S op(S a, S b) {
    S c;
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 4; j++) {
            c.a[i][j] = 0;
        }
    }
    for (int i = 0; i < 4; i++) {
        for (int j = i; j < 4; j++) {
            for (int k1 = i; k1 <= j; k1++) {
                for (int k2 = k1; k2 <= j; k2++) {
                    c.a[i][j] = max(c.a[i][j], a.a[i][k1] + b.a[k2][j]);
                }
            }
        }
    }
    c.len = a.len + b.len;
    return c;
}
S e() {
    S s;
    return s;
}
S mapping(int f, S x) {
    if (f == -1) {
        return x;
    }
    S c;
    c.len = x.len;
    c.a[f][f] = c.len;
    return c;
}
int composition(int f, int g) {
    if (f == -1) {
        return g;
    }
    return f;
}
int id() {
    return -1;
}

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        A[i]--;
    }

    lazy_segtree<S, op, e, int, mapping, composition, id> seg(N);
    for (int i = 0; i < N; i++) {
        S s;
        s.a[A[i]][A[i]] = 1;
        s.len = 1;
        seg.set(i, s);
    }

    int Q;
    cin >> Q;
    for (int i = 0; i < Q; i++) {
        int t;
        cin >> t;

        if (t == 1) {
            int l, r;
            cin >> l >> r;
            l--;
            S s = seg.prod(l, r);
            int ans = 0;
            for (int i = 0; i < 4; i++) {
                for (int j = i; j < 4; j++) {
                    debug(i, j, s.a[i][j]);
                    ans = max(ans, s.a[i][j]);
                }
            }
            cout << ans << '\n';
        }

        else {
            int l, r, x;
            cin >> l >> r >> x;
            x--;
            l--;
            seg.apply(l, r, x);
        }
    }
}
0