結果

問題 No.2697 Range LIS Query
ユーザー shkiiii_shkiiii_
提出日時 2024-03-23 00:09:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,956 bytes
コンパイル時間 2,048 ms
コンパイル使用メモリ 179,124 KB
実行使用メモリ 18,432 KB
最終ジャッジ日時 2024-03-23 00:09:24
合計ジャッジ時間 5,338 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 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>
// #include<atcoder/all>
// #include<boost/multiprecision/cpp_int.hpp>

using namespace std;
// using namespace atcoder;
// using bint = boost::multiprecision::cpp_int;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using vi = vector<ll>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define sz(c) ((ll)(c).size())
#define LB(A,x) (int)(lower_bound(A.begin(),A.end(),x)-A.begin())
// #define MOD 1000000007
#define MOD 998244353
template<typename T>using min_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<typename T>ostream&operator<<(ostream&os,vector<T>&v){for(int i = 0;i < v.size();i++)os<<v[i]<<(i+1!=v.size()?" ":"");return os;}
template<typename T>istream&operator>>(istream&is,vector<T>&v){for(T&in:v)is>>in;return is;}
template<typename T1,typename T2>ostream&operator<<(ostream&os,pair<T1,T2>&p){os<<p.first<<" "<<p.second;return os;}
template<typename T1,typename T2>istream&operator>>(istream&is,pair<T1,T2>&p){is>>p.first>>p.second;return is;}

template<typename T,typename E>
class LazySegtree{
  public:
  using F = function<T(T,T)>;
  using G = function<T(T,E)>;
  using H = function<E(E,E)>;
  int n,height;
  F f;
  G g;
  H h;
  T ti;
  E ei;
  vector<T> dat;
  vector<E> laz;
  LazySegtree(F f,G g,H h,T ti,E ei):
    f(f),g(g),h(h),ti(ti),ei(ei){}

  void init(int N){
    n = 1;height = 0;
    while(n < N)n <<= 1,height++;
    dat.assign(n << 1,ti);
    laz.assign(n << 1,ei);
  }
  void build(const vector<T> &v){
    int N = v.size();
    init(N);
    for(int i = 0;i < N;i++)dat[i+n] = v[i];
    for(int i = n-1;i > 0;i--)dat[i] = f(dat[(i<<1)|0],dat[(i<<1)|1]);
  }
  inline T reflect(int k){
    return (laz[k] == ei ? dat[k] : g(dat[k],laz[k]));
  }
  inline void eval(int k){
    if(laz[k] == ei)return;
    laz[(k<<1)|0] = h(laz[(k<<1)|0],laz[k]);
    laz[(k<<1)|1] = h(laz[(k<<1)|1],laz[k]);
    dat[k] = reflect(k);
    laz[k] = ei;
  }
  inline void thrust(int k){
    for(int i = height;i > 0;i--)eval(k >> i);
  }
  inline void recalc(int k){
    while(k >>= 1)dat[k] = f(reflect((k << 1)|0),reflect((k << 1)|1));
  }
  void update(int a,int b,E x){
    thrust(a+=n);
    thrust(b+=n-1);
    for(int l = a,r = b+1;l < r;l >>= 1,r >>= 1){
      if(l & 1)laz[l] = h(laz[l],x),l++;
      if(r & 1)r--,laz[r] = h(laz[r],x);
    }
    recalc(a);
    recalc(b);
  }
  void set_val(int a,T x){
    thrust(a+=n);
    dat[a] = x;laz[a] = ei;
    recalc(a);
  }
  T get(int a,int b){
    thrust(a+=n);
    thrust(b+=n-1);
    T vl = ti,vr = ti;
    for(int l = a,r = b+1;l < r;l >>= 1,r >>= 1){
      if(l & 1)vl = f(vl,reflect(l++));
      if(r & 1)vr = f(reflect(--r),vr);
    }
    return f(vl,vr);
  }
};

struct e{
  ll len[4],L;
  e(){
    rep(i,4)len[i] = 0;
    L = 0;
  }
};

int main(){
  
  ios_base::sync_with_stdio(0), cin.tie(0);
  int n;
  cin >> n;
  vector<e> a(n);
  rep(i,n){
    a[i].L = 1;
    int g;cin >> g;
    g--;
    a[i].len[g] = 1;
  }
  auto f = [](e a,e b){
    if(a.L == 0)return b;
    if(b.L == 0)return a;
    e c;
    int pre = a.len[0],rui = a.len[0];
    rep(i,4){
      pre += b.len[i];
      if(i != 3)rui += a.len[i+1];
      c.len[i] = pre;
      if(rui > pre)pre = rui;
    }
    for(int i = 3;i > 0;i--)c.len[i] = c.len[i]-c.len[i-1];
    c.L = a.L + b.L;
    return c;
  };
  auto g = [](e a,int x){
    if(x == -1)return a;
    e c;
    c.L = a.L;
    c.len[x] = a.L;
    return c;
  };
  auto h = [](int a,int b){
    if(b == -1)return a;
    return b;
  };
  e ti;
  LazySegtree<e,int> seg(f,g,h,ti,-1);
  seg.build(a);
  int Q;
  cin >> Q;
  while(Q--){
    int t,l,r;
    cin >> t >> l >> r;
    l--;
    if(t == 1){
      e res = seg.get(l,r);
      ll ans = 0;
      rep(i,4)ans += res.len[i];
      cout << ans << "\n";
    }else{
      int x;cin >> x;
      x--;
      seg.update(l,r,x);
    }
  }
  

  return 0;
}
0