Submission #65690725


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 998244353;
ll modpow(ll a, ll e=MOD-2){
ll r=1;
while(e){
if(e&1) r=r*a%MOD;
a=a*a%MOD;
e>>=1;
}
return r;
}
struct Query {
int l, r, x, idx;
int bl, br, bx;
};
int main(){
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 998244353;

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

struct Query {
    int l, r, x, idx;
    int bl, br, bx;
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N,Q;
    cin>>N>>Q;
    vector<int>A(N+1);
    for(int i=1;i<=N;i++) cin>>A[i];
    vector<Query> qs(Q);
    int B = pow(N, 2.0/3);
    for(int i=0;i<Q;i++){
        cin>>qs[i].l>>qs[i].r>>qs[i].x;
        qs[i].idx = i;
        qs[i].bl = qs[i].l / B;
        qs[i].br = qs[i].r / B;
        qs[i].bx = qs[i].x;
    }
    sort(qs.begin(), qs.end(), [&](auto &a, auto &b){
        if(a.bl != b.bl) return a.bl < b.bl;
        if(a.br != b.br) return a.br < b.br;
        return a.bx < b.bx;
    });
    vector<vector<int>> pos(N+2);
    for(int i=1;i<=N;i++){
        pos[A[i]].push_back(i);
    }
    vector<ll> inv(N+2);
    for(int i=1;i<=N;i++) inv[i] = modpow(i);
    vector<ll> ans(Q);
    vector<int> cnt(N+2,0);
    int curL=1, curR=0, curX=1;
    ll curAns=1;
    int csz=0;
    auto addFreq = [&](int v){
        ll old = cnt[v];
        curAns = curAns * (csz+1) % MOD * inv[old+1] % MOD;
        cnt[v]++; csz++;
    };
    auto remFreq = [&](int v){
        ll old = cnt[v];
        curAns = curAns * inv[csz] % MOD * old % MOD;
        cnt[v]--; csz--;
    };
    auto addPos = [&](int i){
        if(A[i] < curX) addFreq(A[i]);
    };
    auto remPos = [&](int i){
        if(A[i] < curX) remFreq(A[i]);
    };
    auto incX = [&](){
        for(int p: pos[curX]){
            if(curL <= p && p <= curR) addFreq(curX);
        }
        curX++;
    };
    auto decX = [&](){
        curX--;
        for(int p: pos[curX]){
            if(curL <= p && p <= curR) remFreq(curX);
        }
    };
    for(auto &q: qs){
        while(curX < q.x) incX();
        while(curX > q.x) decX();
        while(curL > q.l) addPos(--curL);
        while(curR < q.r) addPos(++curR);
        while(curL < q.l) remPos(curL++);
        while(curR > q.r) remPos(curR--);
        ans[q.idx] = curAns;
    }
    for(ll v: ans) cout << v << "\n";
    return 0;
}

Submission Info

Submission Time
Task G - Range Shuffle Query
User OYU__0YU
Language C++ 20 (gcc 12.2)
Score 0
Code Size 2316 Byte
Status TLE
Exec Time 2208 ms
Memory 29444 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 625
Status
AC × 2
AC × 6
TLE × 14
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt
All 00_sample_00.txt, 00_sample_01.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 02_corner_00.txt, 02_corner_01.txt, 02_corner_02.txt, 03_anti_fenwick_00.txt, 03_anti_fenwick_01.txt, 03_anti_fenwick_02.txt, 03_anti_fenwick_03.txt, 03_anti_fenwick_04.txt, 03_anti_fenwick_05.txt, 03_anti_fenwick_06.txt, 03_anti_fenwick_07.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3652 KiB
00_sample_01.txt AC 1 ms 3528 KiB
01_random_00.txt TLE 2208 ms 23616 KiB
01_random_01.txt TLE 2208 ms 22680 KiB
01_random_02.txt TLE 2208 ms 26892 KiB
01_random_03.txt TLE 2208 ms 25060 KiB
01_random_04.txt TLE 2208 ms 24408 KiB
01_random_05.txt TLE 2208 ms 26904 KiB
01_random_06.txt TLE 2208 ms 23744 KiB
02_corner_00.txt AC 153 ms 29444 KiB
02_corner_01.txt AC 91 ms 22916 KiB
02_corner_02.txt AC 90 ms 23020 KiB
03_anti_fenwick_00.txt AC 1306 ms 22844 KiB
03_anti_fenwick_01.txt TLE 2208 ms 23048 KiB
03_anti_fenwick_02.txt TLE 2208 ms 25044 KiB
03_anti_fenwick_03.txt TLE 2208 ms 25144 KiB
03_anti_fenwick_04.txt TLE 2208 ms 23128 KiB
03_anti_fenwick_05.txt TLE 2208 ms 23344 KiB
03_anti_fenwick_06.txt TLE 2208 ms 23524 KiB
03_anti_fenwick_07.txt TLE 2208 ms 23652 KiB


2025-06-03 (Tue)
18:44:17 +09:00