結果

問題 No.2697 Range LIS Query
ユーザー SSRSSSRS
提出日時 2024-03-22 21:52:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,804 bytes
コンパイル時間 2,498 ms
コンパイル使用メモリ 209,664 KB
実行使用メモリ 21,500 KB
最終ジャッジ日時 2024-03-22 21:52:15
合計ジャッジ時間 8,902 ms
ジャッジサーバーID
(参考情報)
judge11 / 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 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
array<array<int, 4>, 4> e(){
  array<array<int, 4>, 4> ans;
  for (int i = 0; i < 4; i++){
    for (int j = i; j < 4; j++){
      ans[i][j] = 0;
    }
  }
  return ans;
}
array<array<int, 4>, 4> p(int x, int k){
  array<array<int, 4>, 4> ans;
  for (int i = 0; i < 4; i++){
    for (int j = i; j < 4; j++){
      if (i <= x && x <= j){
        ans[i][j] = k;
      } else {
        ans[i][j] = 0;
      }
    }
  }
  return ans;
}
array<array<int, 4>, 4> op(array<array<int, 4>, 4> L, array<array<int, 4>, 4> R){
  array<array<int, 4>, 4> ans = e();
  for (int i = 0; i < 4; i++){
    for (int j = i; j < 4; j++){
      for (int k = j; k < 4; k++){
        ans[i][k] = max(ans[i][k], L[i][j] + R[j][k]);
      }
    }
  }
  return ans;
}
struct lazy_segment_tree{
  int N;
  vector<array<array<int, 4>, 4>> ST;
  vector<int> lazy;
  lazy_segment_tree(vector<int> A){
    int n = A.size();
    N = 1;
    while (N < n){
      N *= 2;
    }
    ST = vector<array<array<int, 4>, 4>>(N * 2 - 1, e());
    for (int i = 0; i < n; i++){
      ST[N - 1 + i] = p(A[i], 1);
    }
    for (int i = N - 2; i >= 0; i--){
      ST[i] = op(ST[i * 2 + 1], ST[i * 2 + 2]);
    }
    lazy = vector<int>(N * 2 - 1, -1);
  }
  void push(int i, int l, int r){
    if (lazy[i] != -1){
      if (i < N - 1){
        lazy[i * 2 + 1] = lazy[i];
        lazy[i * 2 + 2] = lazy[i];
      }
      ST[i] = p(lazy[i], r - l);
      lazy[i] = -1;
    }
  }
  void range_update(int L, int R, int x, int i, int l, int r){
    push(i, l, r);
    if (r <= L || R <= l){
      return;
    } else if (L <= l && r <= R){
      lazy[i] = x;
      push(i, l, r);
    } else {
      int m = (l + r) / 2;
      range_update(L, R, x, i * 2 + 1, l, m);
      range_update(L, R, x, i * 2 + 2, m, r);
      ST[i] = op(ST[i * 2 + 1], ST[i * 2 + 2]);
    }
  }
  void range_update(int L, int R, int x){
    range_update(L, R, x, 0, 0, N);
  }
  array<array<int, 4>, 4> range_fold(int L, int R, int i, int l, int r){
    push(i, l, r);
    if (r <= L || R <= l){
      return e();
    } else if (L <= l && r <= R){
      return ST[i];
    } else {
      int m = (l + r) / 2;
      return op(range_fold(L, R, i * 2 + 1, l, m), range_fold(L, R, i * 2 + 2, m, r));
    }
  }
  int range_query(int L, int R){
    return range_fold(L, R, 0, 0, N)[0][3];
  }
};
int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  lazy_segment_tree ST(A);
  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--;
      cout << ST.range_query(l, r) << endl;
    }
    if (t == 2){
      int l, r, x;
      cin >> l >> r >> x;
      l--;
      x--;
      ST.range_update(l, r, x);
    }
  }
}
0