結果

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

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/lazysegtree>

using namespace std;
using namespace atcoder;
using ll = long long;

//S : 区間の長さ, [l, r] : l~rを使う時のLIS

using S = struct{
    int first;
    int second[4][4];
};
using F = int;
F ID = -1;
S op(S a, S b){
    S res;
    for (int i=0; i<4; i++){
        for (int j=0; j<4; j++){
            res.second[i][j] = 0;
            for (int k=i; k<=j; k++){
                res.second[i][j] = max(res.second[i][j], a.second[i][k] + b.second[k][j]);
            }
        }
    }
    res.first = a.first + b.first;
    return res;
}
S e() {
    S res;
    for (int i=0; i<4; i++){
        for (int j=0; j<4; j++) res.second[i][j] = 0;
    }
    res.first = 0;
    return res;
}
S mapping(F f, S x){
    if (f == ID) return x;
    S res;
    for (int i=0; i<4; i++){
        for (int j=0; j<4; j++){
            if (i <= f && f <= j) res.second[i][j] = x.first;
            else res.second[i][j] = 0;
        }
    }
    res.first = x.first;
    return res;
}
F composition(F f, F g){
    if (f == ID) return g;
    else return f;
}
F id() {return ID;}

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    int N, Q, t, l, r, x, A;
    cin >> N;
    vector<S> v(N);
    for (int i=0; i<N; i++){
        cin >> A; A--;
        S res;
        for (int j=0; j<4; j++){
            for (int k=0; k<4; k++){
                if (j <= A && A <= k) res.second[j][k] = 1;
                else res.second[j][k] = 0;
            }
        }
        res.first = 1;
        v[i] = res;
    }
    cin >> Q;
    lazy_segtree<S, op, e, F, mapping, composition, id> tree(v);
    for (int i=0; i<Q; i++){
        cin >> t;
        if (t == 1){
            cin >> l >> r; l--;
            cout << tree.prod(l, r).second[0][3] << endl;
        }
        else{
            cin >> l >> r >> x; x--; l--;
            tree.apply(l, r, x);
        }
    }

    return 0;
}
0