結果
| 問題 | No.3507 RangeSum RangeUpdate RangeSqrt |
| コンテスト | |
| ユーザー |
AK_Mi
|
| 提出日時 | 2026-04-21 22:00:52 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 1,626 ms / 2,000 ms |
| コード長 | 2,318 bytes |
| 記録 | |
| コンパイル時間 | 4,683 ms |
| コンパイル使用メモリ | 383,960 KB |
| 実行使用メモリ | 108,188 KB |
| 最終ジャッジ日時 | 2026-04-21 22:01:38 |
| 合計ジャッジ時間 | 37,846 ms |
|
ジャッジサーバーID (参考情報) |
judge2_1 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 29 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using mint = modint998244353;
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;
}
}
ll vsize = 31;
struct S{
vector<ll> value;
int size;
};
struct F{
ll ch;
ll sq;
};
const F ID = {-1,0};
S op(S a, S b){
vector<ll> c(vsize,1);
for(ll i = 0; i < vsize; i++){
c[i] = a.value[i] + b.value[i];
}
return {c, a.size+b.size};
}
S e(){
return {vector<ll>(vsize,0),0};
}
S mapping(F f, S x){
if(f.ch != -1){
x.value[0] = f.ch;
for(ll i = 1; i < vsize; i++){
x.value[i] = isqrt(x.value[i-1]);
}
for(ll i = 0; i < vsize; i++){
x.value[i] *= x.size;
}
}
if(f.sq == 0)return x;
for(ll i = 0; i < vsize; i++){
if(i + f.sq < vsize){
x.value[i] = x.value[i + f.sq];
}else{
x.value[i] = x.size;
}
}
return x;
}
F composition(F f, F g){
F ret;
if(f.ch != -1)ret = f;
else ret = {g.ch, f.sq + g.sq};
return ret;
}
F id(){ return ID; }
int main(){
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
ll n,q;
cin >> n >> q;
vector<ll> a(n,0);
lazy_segtree<S, op, e, F, mapping, composition, id> seg(n);
vector<ll> vec(vsize,1);
for(ll i = 0; i < n; i++){
cin >> a[i];
vec[0] = a[i];
for(ll t = 1; t < vsize; t++){
vec[t] = isqrt(vec[t-1]);
}
seg.set(i,{vec,1});
}
ll que,l,r,x;
while(q--){
cin >> que >> l >> r;
if(que == 0){
cout << seg.prod(l,r).value[0] << '\n';
}else if(que == 1){
cin >> x;
seg.apply(l,r,{x,0});
}else{
seg.apply(l,r,{-1,1});
}
}
}
AK_Mi