結果

問題 No.2697 Range LIS Query
ユーザー maeshunmaeshun
提出日時 2024-03-22 23:21:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 8,006 ms / 10,000 ms
コード長 2,189 bytes
コンパイル時間 5,668 ms
コンパイル使用メモリ 287,576 KB
実行使用メモリ 100,512 KB
最終ジャッジ日時 2024-03-22 23:23:05
合計ジャッジ時間 80,723 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,548 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 AC 3 ms
6,548 KB
testcase_03 AC 115 ms
6,548 KB
testcase_04 AC 114 ms
6,548 KB
testcase_05 AC 121 ms
6,548 KB
testcase_06 AC 6,454 ms
100,512 KB
testcase_07 AC 6,408 ms
100,512 KB
testcase_08 AC 6,417 ms
100,512 KB
testcase_09 AC 4,875 ms
100,512 KB
testcase_10 AC 4,791 ms
100,512 KB
testcase_11 AC 4,836 ms
100,512 KB
testcase_12 AC 4,653 ms
96,928 KB
testcase_13 AC 4,868 ms
91,828 KB
testcase_14 AC 6,319 ms
92,416 KB
testcase_15 AC 7,916 ms
100,512 KB
testcase_16 AC 8,006 ms
100,512 KB
testcase_17 AC 7,985 ms
100,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i, n) for(int i=0;i<(n);++i)
#define rep1(i, n) for(int i=0;i<=(n);i++)
#define ll long long
using mint = modint998244353;
using P = pair<ll,ll>;
using lb = long double;
using T = tuple<ll, ll, ll>;
#ifdef LOCAL
#  include <debug_print.hpp>
#  define dbg(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__)
#else
#  define dbg(...) (static_cast<void>(0))
#endif

struct S { 
   vector<vector<int>> v;
   int len;
};

S op(S a, S b){
    S c;
    c.v = vector<vector<int>>(4, vector<int>(4));
    for(int i=0;i<4;i++) for(int j=0;j<4;j++){
        c.v[i][j] = max(a.v[i][j],b.v[i][j]);
    }
    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++){
                    c.v[i][l] = max(c.v[i][l], a.v[i][j]+b.v[k][l]);
                }
            }
        }
    }
    c.len = a.len + b.len;
    return c;
}

S e(){
    S c;
    c.v = vector<vector<int>>(4, vector<int>(4));
    c.len = 0;
    return c;
}

S mapping(int f, S a) {
    if(f==-1) return a;
    a.v = vector<vector<int>>(4, vector<int>(4));
    a.v[f][f] = a.len;
    return a;
}

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);
    rep(i,n) cin >> a[i];
    lazy_segtree<S, op, e,int, mapping, composition, id> seg(n);
    rep(i,n){
        --a[i];
        S c;
        c.v = vector<vector<int>>(4,vector<int>(4));
        c.v[a[i]][a[i]] = 1;
        c.len = 1;
        seg.set(i,c);
    }
    int q;
    cin >> q;
    while(q--){
        int t;
        cin >> t;
        if(t==1){
            int l, r;
            cin >> l >> r;
            --l;
            auto vs = seg.prod(l,r);
            int ans = 0;
            dbg(vs.v);
            rep(i,4) rep(j,4) {
                ans = max(ans, vs.v[i][j]);
            }
            cout<<ans<<endl;
        }
        else{
            int l, r, x;
            cin >> l >> r >> x;
            --l;
            --x;
            seg.apply(l,r,x);
        }
    }
    return 0;
}
0