結果

問題 No.3507 RangeSum RangeUpdate RangeSqrt
コンテスト
ユーザー tau1235
提出日時 2026-04-18 14:15:35
言語 C++23
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 1,197 ms / 2,000 ms
コード長 1,873 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,485 ms
コンパイル使用メモリ 349,296 KB
実行使用メモリ 161,540 KB
最終ジャッジ日時 2026-04-18 14:16:14
合計ジャッジ時間 28,079 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

unsigned long long isqrt_aux(int c,unsigned long long n){
  if (c == 0){
    return 1;
  } else {
    int k = (c - 1) / 2;
    unsigned long long a = isqrt_aux(c / 2, n >> (2*k + 2));
    return (a << k) + (n >> (k+2)) / a;
  }
}
unsigned long isqrt(unsigned long long n){
  if (n == 0){
    return 0;
  } else {
    unsigned long long a = isqrt_aux(( 63 - __builtin_clzll(n)) / 2, n);
    return (n <= a * a - 1 ? a - 1 : a);
  }
}

using ll=long long;
const int l=33;
struct S{
  int now=0;
  array<ll,l> val;
  ll sz;
};
unordered_map<ll,array<ll,l>> mp;
array<ll,l> ar;
array<ll,l> calc(ll x){
  if (mp.count(x)) return mp[x];
  array<ll,l> ret=ar;
  ret[0]=x;
  for (int i=1;i<l;i++) ret[i]=isqrt(ret[i-1]);
  return mp[x]=ret;
}
S op(S a,S b){
  S c;
  c.val=array<ll,l>();
  for (int i=0;i<l;i++) c.val[i]=a.val[min(l-1,a.now+i)]+b.val[min(l-1,b.now+i)];
  c.now=0;
  c.sz=a.sz+b.sz;
  return c;
}
S e(){return S{0,ar,0};}
struct F{
  ll cnt;
  ll x;
};
S mapping(F f,S x){
  if (f.x!=-1){
    x.val=calc(f.x);
    for (int i=0;i<l;i++) x.val[i]*=x.sz;
    x.now=0;
  }
  x.now=min((ll)l-1,x.now+f.cnt);
  return x;
}
F composition(F f,F g){
  if (f.x!=-1) return f;
  g.cnt+=f.cnt;
  return g;
}
F id(){return F{0,-1};}

int main(){
  for (int i=0;i<l;i++) ar[i]=0;
  int n,q;
  cin>>n>>q;
  vector<ll> a(n);
  vector<S> v(n);
  for (int i=0;i<n;i++){
    cin>>a[i];
    v[i]={0,calc(a[i]),1};
  }
  atcoder::lazy_segtree<S,op,e,F,mapping,composition,id> seg(v);
  while (q--){
    int t;
    cin>>t;
    if (t==0){
      int l,r;
      cin>>l>>r;
      auto p=seg.prod(l,r);
      cout<<p.val[p.now]<<endl;
    }
    if (t==1){
      int l,r,x;
      cin>>l>>r>>x;
      seg.apply(l,r,F{0,x});
    }
    if (t==2){
      int l,r;
      cin>>l>>r;
      seg.apply(l,r,F{1,-1});
    }
  }
}
0