結果

問題 No.2697 Range LIS Query
ユーザー mayocornmayocorn
提出日時 2024-03-23 12:46:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 3,752 bytes
コンパイル時間 5,575 ms
コンパイル使用メモリ 289,184 KB
実行使用メモリ 130,700 KB
最終ジャッジ日時 2024-03-23 12:46:27
合計ジャッジ時間 18,155 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 217 ms
7,004 KB
testcase_04 AC 215 ms
6,984 KB
testcase_05 AC 236 ms
7,204 KB
testcase_06 TLE -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;

// type
typedef long long ll;
typedef long double ld;
using i128 = __int128_t;
template<class T> using pq = priority_queue<T>;
template<class T> using pqg = priority_queue<T, vector<T>, greater<T>>;
template<class T> using v = vector<T>;
#define V vector
#define pl pair<ll, ll>
#define vl v<ll>
#define vp v<pl>
#define vm v<mint>
 
// IN-OUT
#define NYAN ios::sync_with_stdio(false);cin.tie(nullptr);cout<<fixed<<setprecision(15);
ostream &operator<<(ostream &os, const i128 &v) {
    if(v == 0) { return (os << "0"); }
    i128 num = v;
    if(v < 0) { os << '-'; num = -num; }
    string s;
    for(; num > 0; num /= 10) { s.push_back((char)(num % 10) + '0'); }
    reverse(s.begin(), s.end());
    return (os << s);
}
void Yes(bool b=1) { cout << ( b == 1 ? "Yes" : "No" ) << "\n"; }
void YES(bool b=1) { cout << ( b == 1 ? "YES" : "NO" ) << "\n"; }
void No(bool b=1) { cout << ( b == 1 ? "No" : "Yes" ) << "\n"; }
void NO(bool b=1) { cout << ( b == 1 ? "NO" : "YES" ) << "\n"; }
void CIN() {}
template <typename T, class... U> void CIN(T &t, U &...u) { cin >> t; CIN(u...); }
void COUT() { cout << "\n"; }
template <typename T, class... U, char sep = ' '> void COUT(const T &t, const U &...u) { cout << t; if (sizeof...(u)) cout << sep; COUT(u...); }
#define dump(x) cerr << #x << ":"<< x << "\n";
#define vdump(x) rep(repeat, sz(x)) cerr << repeat << ":" << x[repeat] << "\n";
 
// macro
#define bp __builtin_popcountll
#define ALL(x) x.begin(),x.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define reps(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define sz(x) (ll)x.size()
ll xd[]={0, 1, 0, -1, 1, 1, -1, -1};
ll yd[]={1, 0, -1, 0, 1, -1, -1, 1};

// function
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T>int bl(T x) { int s = 0; while(x) {x >>= 1; s++;} return s; } // bitlength
ll rmax(ll a, ll b){return max(a, b);}
ll rmin(ll a, ll b){return min(a, b);}
ll rsum(ll a, ll b){return a + b;}
ll rzero(){return 0;}

// constant
long double PI = 3.14159265358979;
#define INF32 2147483647
#define INF64 9223372036854775807
#define INF 922337203685477580
using mint = modint998244353;
// using mint = modint1000000007;


/* SOLVE BEGIN ************************************************************************** */

// 幅, dp
using S = tuple<ll, v<vl>>;
S op(S a, S b){
  auto [wa, A] = a;
  auto [wb, B] = b;
  
  v<vl> C(4, vl(4));
  rep(i, 4)reps(j, i, 4)reps(k, j, 4)reps(l, k, 4){
    chmax(C[i][l], A[i][j] + B[k][l]);
  }
  return S(wa + wb, C);
} //セグ木の関数

S e(){ 
  v<vl> vec(4, vl(4));
  return S(1, vec);
}

using F = ll;
S mapping(F a, S b){
  auto [w, B] = b;
  
  if(a == -1) return b;
  
  rep(i, 4)reps(j, i, 4) B[i][j] = 0;
  // rep(i, a + 1)reps(j, a, 4) B[i][j] = w;
  B[a][a] = w;
  
  return S(w, B);
} //モノイドに作用させるやつ
F composition(F a, F b){
  return (a == -1) ? b : a;
} //関数合成 bが元の関数 aが新しく合成する関数(注意)
F id(){return -1;} //単位元

void solve()
{
  ll n;
  cin >> n;
  vl a(n);
  rep(i, n) cin >> a[i];
  rep(i, n) a[i]--;
  
  lazy_segtree<S, op, e, F, mapping, composition, id> sg(n);
  rep(i, n) sg.apply(i, i + 1, a[i]);
  
  ll q;
  cin >> q;
  while(q--){
    ll t, l ,r;
    CIN(t, l, r);
    l--;
    if(t == 1){
      auto [w, dp] = sg.prod(l, r);
      ll ans = 0;
      rep(i, 4)reps(j, i, 4) chmax(ans, dp[i][j]);
      cout << ans << "\n";
    }else{
      ll x;
      cin >> x;
      x--;
      sg.apply(l, r, x);
    }
  }
}

int main()
{
  NYAN
  solve();
  return 0;
}
0