結果

問題 No.3110 WIP Editorial
ユーザー kokoseikokosei
提出日時 2024-04-01 23:26:47
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,166 bytes
コンパイル時間 1,445 ms
コンパイル使用メモリ 128,912 KB
実行使用メモリ 29,696 KB
最終ジャッジ日時 2024-04-01 23:26:53
合計ジャッジ時間 5,233 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <atcoder/lazysegtree>
using namespace std;
using ll = long long;

const int primes[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97};
struct S{
    int val, siz;
};
struct F{
    int add, set;
};
S op(S a, S b){
    return {a.val + b.val, a.siz + b.siz};
}
S e(){
    return {0, 0};
}
S mp(F f, S x){
    if(f.set == -1){
        return {x.val + x.siz * f.add, x.siz};
    }
    return {f.set * x.siz, x.siz};
}
F cm(F f, F g){
    if(f.set == -1){
        return {f.add + g.add, g.set};
    }
    return {0, f.set};
}
F id(){
    return {0, -1};
}
using segtree = atcoder::lazy_segtree<S, op, e, F, mp, cm, id>;

int N, Q;
int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    cin >> N;
    vector<vector<S>> cnt(30, vector<S>(N, {0, 1}));
    for(int i = 0;i < N;i++){
        ll a; cin >> a;
        int id = 0;
        for(int p : primes){
            while(a % p == 0){
                a /= p;
                cnt[id][i].val++;
            }
            id++;
        }
    }
    vector<segtree> seg(30);
    for(int i = 0;i < 25;i++){
        seg[i] = segtree(cnt[i]);
    }
    cin >> Q;
    while(Q--){
        ll t, l, r, x;
        cin >> t >> l >> r >> x;
        l--;
        if(t == 1){
            int id = 0;
            for(int p : primes){
                int num = 0;
                while(x % p == 0){
                    x /= p;
                    num++;
                }
                seg[id].apply(l, r, {0, num});
                id++;
            }
        }else if(t == 2){
            int id = 0;
            for(int p : primes){
                int num = 0;
                while(x % p == 0){
                    x /= p;
                    num++;
                }
                seg[id].apply(l, r, {num, -1});
                id++;
            }
        }else{
            ll ans = 1;
            int id = 0;
            for(int p : primes){
                if(p > x)break;
                ans *= seg[id].prod(l, r).val + 1;
                id++;
            }
            cout << ans << endl;
        }
    }
    return 0;
}
0