Submission #68159465


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
static const int MOD = 998244353;

int mod_pow(long long a, long long e = MOD-2) {
    long long r = 1 % MOD;
    while (e) {
        if (e & 1) r = r * a % MOD;
        a = a * a % MOD;
        e >>= 1;
    }
    return (int)r;
}

struct SegTree {
    struct Node {
        int sum;
        int assign;
    };
    int n;
    vector<Node> st;
    
    SegTree(int _n, vector<int>& A) : n(_n) {
        st.assign(4*n, {0, -1});
        build(1,1,n,A);
    }
    
    void build(int p, int l, int r, vector<int>& A) {
        if (l == r) {
            st[p].sum = A[l] % MOD;
        } else {
            int m = (l + r) >> 1;
            build(p<<1, l, m, A);
            build(p<<1|1, m+1, r, A);
            st[p].sum = (st[p<<1].sum + st[p<<1|1].sum) % MOD;
        }
    }
    
    void apply_assign(int p, int l, int r, int v) {
        st[p].sum    = (long long)v * (r - l + 1) % MOD;
        st[p].assign = v;
    }
    
    void push(int p, int l, int r) {
        if (st[p].assign >= 0 && l < r) {
            int m = (l + r) >> 1;
            apply_assign(p<<1,   l,   m, st[p].assign);
            apply_assign(p<<1|1, m+1, r, st[p].assign);
            st[p].assign = -1;
        }
    }
    
    void update_assign(int p, int l, int r, int L, int R, int v) {
        if (R < l || r < L) return;
        if (L <= l && r <= R) {
            apply_assign(p, l, r, v);
            return;
        }
        push(p,l,r);
        int m = (l + r) >> 1;
        update_assign(p<<1,   l,   m, L, R, v);
        update_assign(p<<1|1, m+1, r, L, R, v);
        st[p].sum = (st[p<<1].sum + st[p<<1|1].sum) % MOD;
    }
    
    int query_sum(int p, int l, int r, int L, int R) {
        if (R < l || r < L) return 0;
        if (L <= l && r <= R) return st[p].sum;
        push(p,l,r);
        int m = (l + r) >> 1;
        int s1 = query_sum(p<<1,   l,   m, L, R);
        int s2 = query_sum(p<<1|1, m+1, r, L, R);
        return (s1 + s2) % MOD;
    }
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int N, M;
    cin >> N >> M;
    vector<int> A(N+1);
    for(int i = 1; i <= N; i++){
        cin >> A[i];
        A[i] %= MOD;
    }
    
    SegTree st(N, A);
    
    while (M--) {
        int L, R;
        cin >> L >> R;
        int len = R - L + 1;
        int S   = st.query_sum(1,1,N,L,R);
        int avg = (long long)S * mod_pow(len) % MOD;
        st.update_assign(1,1,N,L,R,avg);
    }
    for(int i = 1; i <= N; i++){
        int v = st.query_sum(1,1,N,i,i);
        cout << v << (i==N?'\n':' ');
    }
    return 0;
}

Submission Info

Submission Time
Task F - Random Gathering
User reginox
Language C++ 20 (gcc 12.2)
Score 500
Code Size 2715 Byte
Status AC
Exec Time 229 ms
Memory 10324 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 3
AC × 49
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 01_random_35.txt, 01_random_36.txt, 01_random_37.txt, 01_random_38.txt, 01_random_39.txt, 01_random_40.txt, 01_random_41.txt, 01_random_42.txt, 01_random_43.txt, 01_random_44.txt, 01_random_45.txt, 01_random_46.txt, 01_random_47.txt, 01_random_48.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3516 KiB
00_sample_01.txt AC 1 ms 3516 KiB
00_sample_02.txt AC 1 ms 3436 KiB
01_random_03.txt AC 228 ms 10176 KiB
01_random_04.txt AC 228 ms 10140 KiB
01_random_05.txt AC 228 ms 10160 KiB
01_random_06.txt AC 228 ms 10192 KiB
01_random_07.txt AC 229 ms 10140 KiB
01_random_08.txt AC 228 ms 10324 KiB
01_random_09.txt AC 229 ms 10224 KiB
01_random_10.txt AC 229 ms 10108 KiB
01_random_11.txt AC 155 ms 5920 KiB
01_random_12.txt AC 176 ms 6256 KiB
01_random_13.txt AC 55 ms 5456 KiB
01_random_14.txt AC 100 ms 7820 KiB
01_random_15.txt AC 131 ms 9204 KiB
01_random_16.txt AC 228 ms 10176 KiB
01_random_17.txt AC 181 ms 10264 KiB
01_random_18.txt AC 163 ms 10136 KiB
01_random_19.txt AC 228 ms 10164 KiB
01_random_20.txt AC 181 ms 10188 KiB
01_random_21.txt AC 164 ms 10264 KiB
01_random_22.txt AC 227 ms 10160 KiB
01_random_23.txt AC 180 ms 10264 KiB
01_random_24.txt AC 165 ms 10180 KiB
01_random_25.txt AC 228 ms 10176 KiB
01_random_26.txt AC 180 ms 10128 KiB
01_random_27.txt AC 164 ms 10248 KiB
01_random_28.txt AC 139 ms 10172 KiB
01_random_29.txt AC 146 ms 10188 KiB
01_random_30.txt AC 227 ms 10220 KiB
01_random_31.txt AC 226 ms 10204 KiB
01_random_32.txt AC 227 ms 10176 KiB
01_random_33.txt AC 226 ms 10176 KiB
01_random_34.txt AC 227 ms 10316 KiB
01_random_35.txt AC 207 ms 9964 KiB
01_random_36.txt AC 149 ms 3596 KiB
01_random_37.txt AC 73 ms 6204 KiB
01_random_38.txt AC 1 ms 3448 KiB
01_random_39.txt AC 1 ms 3584 KiB
01_random_40.txt AC 40 ms 3540 KiB
01_random_41.txt AC 84 ms 3388 KiB
01_random_42.txt AC 93 ms 3468 KiB
01_random_43.txt AC 86 ms 3520 KiB
01_random_44.txt AC 124 ms 3676 KiB
01_random_45.txt AC 94 ms 3656 KiB
01_random_46.txt AC 114 ms 3388 KiB
01_random_47.txt AC 125 ms 3688 KiB
01_random_48.txt AC 68 ms 3584 KiB