結果

問題 No.2697 Range LIS Query
ユーザー Today03Today03
提出日時 2024-03-22 23:14:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 690 ms / 10,000 ms
コード長 2,165 bytes
コンパイル時間 2,884 ms
コンパイル使用メモリ 215,648 KB
実行使用メモリ 28,248 KB
最終ジャッジ日時 2024-03-22 23:15:09
合計ジャッジ時間 11,266 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 16 ms
6,676 KB
testcase_04 AC 16 ms
6,676 KB
testcase_05 AC 16 ms
6,676 KB
testcase_06 AC 656 ms
28,248 KB
testcase_07 AC 636 ms
28,248 KB
testcase_08 AC 690 ms
28,248 KB
testcase_09 AC 595 ms
28,248 KB
testcase_10 AC 617 ms
28,248 KB
testcase_11 AC 642 ms
28,248 KB
testcase_12 AC 417 ms
27,376 KB
testcase_13 AC 403 ms
25,968 KB
testcase_14 AC 544 ms
26,144 KB
testcase_15 AC 664 ms
28,248 KB
testcase_16 AC 637 ms
28,248 KB
testcase_17 AC 676 ms
28,248 KB
権限があれば一括ダウンロードができます

ソースコード

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