QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#245822#5474. Incredibly Cute Penguin ChicksFireball0424#ML 564ms157096kbC++143.4kb2023-11-10 12:59:362023-11-10 12:59:37

Judging History

你现在查看的是最新测评结果

  • [2023-11-10 12:59:37]
  • 评测
  • 测评结果:ML
  • 用时:564ms
  • 内存:157096kb
  • [2023-11-10 12:59:36]
  • 提交

answer

#pragma GCC optimizer("Ofast")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
//#define int long long 
#define ld long double
#define ull unsigned long long 
#define fr first
#define fi first
#define sc second
#define se second
#define all(x) x.begin(), x.end()
#define pii pair<int,int>
using namespace std;

#ifndef fireball
#define tofu ios::sync_with_stdio(0); cin.tie(0);
#else
#define tofu freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif 

void db() {cout << '\n';}
template <typename T, typename ...U> void db(T a, U ...b) {cout << a << ' ', db(b...);}

const int N = 1e6;
const int mod = 998244353;

struct Seg{
    int l, r, mid, sum = 0;
    Seg *ch[2] = {nullptr, nullptr};
    Seg(int lc, int rc) : l(lc), r(rc), mid(lc + rc >> 1){}

    void pull(){
        sum = (ch[0] ? ch[0] -> sum : 0) + (ch[1] ? ch[1] -> sum : 0);
        if(sum >= mod) sum -= mod;
    }

    void add(int pos, int val){
        if(l == r){
            sum += val;
            if(sum >= mod) sum -= mod;
            return;
        }
        if(pos <= mid){
            if(!ch[0]) ch[0] = new Seg(l, mid);
            ch[0] -> add(pos, val);
        }
        if(pos > mid){
            if(!ch[1]) ch[1] = new Seg(mid + 1, r);
            ch[1] -> add(pos, val);
        }
        pull();
    }

    int query(int lc, int rc){
        if(lc <= l and r <= rc) return sum;
        int res = 0;
        if(lc <= mid and ch[0]) {
            res += ch[0] -> query(lc, rc);
            if(res >= mod) res -= mod;
        }
        if(rc >= mid + 1 and ch[1]){
            res += ch[1] -> query(lc, rc);
            if(res >= mod) res -= mod;
        }
        return res;
    }
};

signed main(){
    tofu;
    string s;
    cin >> s;
    int n = (int)s.length();
    int pa[n + 1] = {}, pb[n + 1] = {}, pc[n + 1] = {};
    for(int i = 0; i < n; ++i){
        pa[i + 1] = pa[i] + (s[i] == 'I');
        pb[i + 1] = pb[i] + (s[i] == 'C');
        pc[i + 1] = pc[i] + (s[i] == 'P');
    }

    vector<Seg*> ab(2 * N + 5, nullptr), ac(2 * N + 5, nullptr), bc(2 * N + 5, nullptr);

    for(int i = 1; i <= n; ++i){
        int x1 = pa[i] - pb[i] + N + 2, y1 = pc[i] - pa[i] + N + 2;
        int x2 = pa[i] - pc[i] + N + 2, y2 = pb[i] - pa[i] + N + 2;
        int x3 = pb[i] - pc[i] + N + 2, y3 = pa[i] - pb[i] + N + 2;

        if(!ab[x1]){
            ab[x1] = new Seg(1, 2 * N + 5);
            if(x1 == N + 2) ab[x1] -> add(N + 2, 1);
        }
        if(!ac[x2]){
            ac[x2] = new Seg(1, 2 * N + 5);
            if(x2 == N + 2) ac[x2] -> add(N + 2, 1);
        }
        if(!bc[x3]){
            bc[x3] = new Seg(1, 2 * N + 5);
            if(x3 == N + 2) bc[x3] -> add(N + 2, 1);
        }
        
        int res = ab[x1] -> query(1, y1 - 1);
        res += ac[x2] -> query(1, y2 - 1); 
        if(res >= mod) res -= mod;
        res += bc[x3] -> query(1, y3 - 1);
        if(res >= mod) res -= mod;

        //db(i, res, bc[x3] -> query(1, y3 - 1));
        ab[x1] -> add(y1, res);
        ac[x2] -> add(y2, res);
        bc[x3] -> add(y3, res);

        // ab[pa[i - 1] - pb[i - 1] + N + 2] -> add(pc[i - 1] - pa[i - 1] + N + 2, res);
        // ac[pa[i - 1] - pc[i - 1] + N + 2] -> add(pb[i - 1] - pa[i - 1] + N + 2, res);
        // bc[pb[i - 1] - pc[i - 1] + N + 2] -> add(pa[i - 1] - pb[i - 1] + N + 2, res);

        if(i == n) db(res);
    }
    
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 49936kb

input:

ICPC

output:

2 

result:

ok single line: '2 '

Test #2:

score: 0
Accepted
time: 0ms
memory: 50020kb

input:

CCCIIIPPP

output:

69 

result:

ok single line: '69 '

Test #3:

score: 0
Accepted
time: 3ms
memory: 50132kb

input:

PICCICCIPPI

output:

24 

result:

ok single line: '24 '

Test #4:

score: 0
Accepted
time: 522ms
memory: 144044kb

input:

PCPPCCICPICPCPCPCCPPIPPPIICCCICPICCPPPIPCCCCICCIICPCCICCCPCICIPPIPIPIPPCCPCIPPCCPPCCIPPPIPPCIICIIIPPCIPPICPPICCPIICCCCCCCICPCCPPIPIPICPCIICPCCIPICCCPPCPIIICPCPPPIIIIICCCPCICCPPCPPCICIIIPIPICPCPPPPICPCPIPIIICCICPCIPPICCICPIIPPCCCIICPCPCCICCPICPPPPPPICCCIPCCICICIPICIIICCICPCIPIICPIPIIICCPCCIIPCCCCPIPI...

output:

216523282 

result:

ok single line: '216523282 '

Test #5:

score: 0
Accepted
time: 537ms
memory: 141296kb

input:

ICIPCICCIPIPIIPPCPCICICPCPCPIIICICPPICCICPIPCPCIIPPIPCCIPIPIPIICCICICCCIPPIIPCPPCIIICCICCCCCCPIPICCIPIICIICPIPCCICPPCCIPIPIICCCPCCIPCPPCCIIIIIPCIPIIPICIIIPIICCCIPPPIPICIIIICIIIPICIICPIPCCICIPCCIPICCCPPIPIIPICPPCPICIPIPPPPPCIPCCIPPICIPCICPCCCCPPIIIPCPICCICIPIIPICPIIIIPPPCPIIIPCCPPIIPPICPIIICCCPICPPIC...

output:

977504498 

result:

ok single line: '977504498 '

Test #6:

score: 0
Accepted
time: 557ms
memory: 157096kb

input:

PPCCCICCIPPICCPCCCCIPPPIICPIPIPPPPIPPPPPPCPIPICCPCCPICPIPPPIIPIPIIPPCCPIICPPIIIPPCCCIIPCCIPCCCCCCIIIPIPCICCIICIIICCCCPCCICPPCCPCCIPICCPPIIPIIPIPCIIPIIPPPCCIPCPCCICCIPICPPPCIPPIPCCPCPCCIPIICCIPCCIPPCPCIPICIICPPICIIICIPIIIIIPCCCPPIPPPCIICIIIPPCIPCIPCIICCCCPIPCPICICPIPCPPIPIPICCPCCCCPCIPCPPCCIPCCCCCPII...

output:

785880133 

result:

ok single line: '785880133 '

Test #7:

score: 0
Accepted
time: 564ms
memory: 133116kb

input:

ICIPCPIPCCCCCCCPCCPCCIPCPCPIPPCPIPCICPPIPPPPICPIIPPIICPICPICPPICICICCCIIPCPPCCICCCCPIICPPPIPIPCICPIPPPPCCPICPCPICICPPIIIICIICPPIPIIICCCCPIPIIPICCCIPCCPPCPPPPIIIIICIPCPCCPIIICICIPPCCPIPPCIIPCCCIIICPCIPCIIIIPCIIPCIICCCIPPIPPCIIPCICIPIIPICCICCPCPIICCCIPIICCCPIPPCCIIIICPPIICPCPCIPPPCPCICPPIPIPCCPIPPPIPI...

output:

687587235 

result:

ok single line: '687587235 '

Test #8:

score: 0
Accepted
time: 536ms
memory: 144228kb

input:

IICCCIPIIIIIPICIICPCPCIICCIIICCCIIPICICCCPCPCPPPIIPIPPICIICICIPIICCICCIIIPCIICCPPIPICIPPCPCPCPIICCIIICIPPICCICPPIPPPPICPCPIPCCCPCPCPPPPIICPCIIIIIIIPIPIICICCPPIIPPCICPCPCIPCPICPPPICCICIICPPIPPPIPIPIPPCIPPCIPPCPPPIICICCCPICIPPIPCCPIIPPCIPPICCIIIPPPPPIIPPICPCPCIPPCCPCIIIPPICCCIIIIICIPPIIICPCIIICPPCPCPP...

output:

698376687 

result:

ok single line: '698376687 '

Test #9:

score: 0
Accepted
time: 540ms
memory: 148380kb

input:

IIPICCCCIPPCCPICCIIPPPCIPCCPPIPIICICPCCIIPPCCCICICPPICCICPPIICIIPICPICIPPPPCPCCPIICCPPIPPCIIIIPICICICCIIPPCICCCCCPICPIPCPPCCPPICPICCCICCIPICCICPIICCPIPIPICCPPCCPCPCCPICCPICCCCCCIPIICPIPICICCPIIPIPICIICIPPPIPCICIPIPPICPICICPPICICCIPCIPPPCIPIIPPPIICICPPPIICCCPIIICIPIPPICICIPPPCCPCCIIPCCCPPPCPICPICPPCP...

output:

850857669 

result:

ok single line: '850857669 '

Test #10:

score: -100
Memory Limit Exceeded

input:

IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII...

output:

709758735 

result: