結果

問題 No.2697 Range LIS Query
ユーザー hitonanodehitonanode
提出日時 2024-04-05 09:32:09
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 245 ms / 10,000 ms
コード長 2,119 bytes
コンパイル時間 1,396 ms
コンパイル使用メモリ 124,632 KB
実行使用メモリ 19,432 KB
最終ジャッジ日時 2024-10-01 00:58:20
合計ジャッジ時間 4,977 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,248 KB
testcase_02 AC 2 ms
5,248 KB
testcase_03 AC 7 ms
5,248 KB
testcase_04 AC 7 ms
5,248 KB
testcase_05 AC 7 ms
5,248 KB
testcase_06 AC 223 ms
19,304 KB
testcase_07 AC 225 ms
19,300 KB
testcase_08 AC 222 ms
19,432 KB
testcase_09 AC 184 ms
19,176 KB
testcase_10 AC 188 ms
19,308 KB
testcase_11 AC 186 ms
19,308 KB
testcase_12 AC 131 ms
18,792 KB
testcase_13 AC 148 ms
18,020 KB
testcase_14 AC 199 ms
18,024 KB
testcase_15 AC 245 ms
19,172 KB
testcase_16 AC 243 ms
19,304 KB
testcase_17 AC 236 ms
19,428 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In member function 'int S::longest() const':
main.cpp:20:39: warning: narrowing conversion of '(int)((const S*)this)->S::a11' from 'int' to 'int:18' [-Wnarrowing]
   20 |     int longest() const { return max({a11, a12, a13, a14, a22, a23, a24, a33, a34, a44}); }
      |                                       ^~~
main.cpp:20:39: warning: narrowing conversion of '((const S*)this)->S::a11' from 'const int' to 'int:18' [-Wnarrowing]
main.cpp:20:44: warning: narrowing conversion of '(int)((const S*)this)->S::a12' from 'int' to 'int:18' [-Wnarrowing]
   20 |     int longest() const { return max({a11, a12, a13, a14, a22, a23, a24, a33, a34, a44}); }
      |                                            ^~~
main.cpp:20:44: warning: narrowing conversion of '((const S*)this)->S::a12' from 'const int' to 'int:18' [-Wnarrowing]
main.cpp:20:49: warning: narrowing conversion of '(int)((const S*)this)->S::a13' from 'int' to 'int:18' [-Wnarrowing]
   20 |     int longest() const { return max({a11, a12, a13, a14, a22, a23, a24, a33, a34, a44}); }
      |                                                 ^~~
main.cpp:20:49: warning: narrowing conversion of '((const S*)this)->S::a13' from 'const int' to 'int:18' [-Wnarrowing]
main.cpp:20:54: warning: narrowing conversion of '(int)((const S*)this)->S::a14' from 'int' to 'int:18' [-Wnarrowing]
   20 |     int longest() const { return max({a11, a12, a13, a14, a22, a23, a24, a33, a34, a44}); }
      |                                                      ^~~
main.cpp:20:54: warning: narrowing conversion of '((const S*)this)->S::a14' from 'const int' to 'int:18' [-Wnarrowing]
main.cpp:20:59: warning: narrowing conversion of '(int)((const S*)this)->S::a22' from 'int' to 'int:18' [-Wnarrowing]
   20 |     int longest() const { return max({a11, a12, a13, a14, a22, a23, a24, a33, a34, a44}); }
      |                                                           ^~~
main.cpp:20:59: warning: narrowing conversion of '((const S*)this)->S::a22' fro

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;

#include <atcoder/lazysegtree>

struct S {
    int n : 18 = 0;
    int a11 : 18 = 0;
    int a12 : 18 = 0;
    int a13 : 18 = 0;
    int a14 : 18 = 0;
    int a22 : 18 = 0;
    int a23 : 18 = 0;
    int a24 : 18 = 0;
    int a33 : 18 = 0;
    int a34 : 18 = 0;
    int a44 : 18 = 0;

    int longest() const { return max({a11, a12, a13, a14, a22, a23, a24, a33, a34, a44}); }
};

S gen1(int n) { return S{n, n, n, n, n, 0, 0, 0, 0, 0, 0}; }
S gen2(int n) { return S{n, 0, n, n, n, n, n, n, 0, 0, 0}; }
S gen3(int n) { return S{n, 0, 0, n, n, 0, n, n, n, n, 0}; }
S gen4(int n) { return S{n, 0, 0, 0, n, 0, 0, n, 0, n, n}; }

S op(S l, S r) {
    return {
        l.n + r.n,
        l.a11 + r.a11,
        max({l.a11 + r.a12, l.a12 + r.a22}),
        max({l.a11 + r.a13, l.a12 + r.a23, l.a13 + r.a33}),
        max({l.a11 + r.a14, l.a12 + r.a24, l.a13 + r.a34, l.a14 + r.a44}),
        l.a22 + r.a22,
        max({l.a22 + r.a23, l.a23 + r.a33}),
        max({l.a22 + r.a24, l.a23 + r.a34, l.a24 + r.a44}),
        l.a33 + r.a33,
        max({l.a33 + r.a34, l.a34 + r.a44}),
        l.a44 + r.a44,
    };
}

S e() { return S{}; }

S gen(int a, int n) {
    if (a == 1) return gen1(n);
    if (a == 2) return gen2(n);
    if (a == 3) return gen3(n);
    if (a == 4) return gen4(n);
    assert(false);
}

using F = int;

S mapping(F f, S x) {
    if (!f) return x;
    return gen(f, x.n);
}

F composition(F f, F g) {
    if (!f) return g;
    return f;
}

F id() { return 0; }

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);

    int N;
    cin >> N;

    vector<S> init;
    for (int i = 0; i < N; ++i) {
        int a;
        cin >> a;
        init.push_back(gen(a, 1));
    }

    atcoder::lazy_segtree<S, op, e, F, mapping, composition, id> seg(init);

    int Q;
    cin >> Q;
    while (Q--) {
        int tp, l, r;
        cin >> tp >> l >> r;
        --l;
        if (tp == 1) {
            cout << seg.prod(l, r).longest() << '\n';
        } else {
            int x;
            cin >> x;
            seg.apply(l, r, x);
        }
    }
}
0