QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#303278#5474. Incredibly Cute Penguin ChicksELDRVDRE 55ms331588kbC++143.0kb2024-01-12 01:50:382024-01-12 01:50:39

Judging History

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

  • [2024-01-12 01:50:39]
  • 评测
  • 测评结果:RE
  • 用时:55ms
  • 内存:331588kb
  • [2024-01-12 01:50:38]
  • 提交

answer

//https://qoj.ac/contest/1101/problem/5474
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define PI acos(-1)
#define LSB(i) ((i) & -(i))
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define sc second
#define th third
#define fo fourth
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ldb double
#define INF 1e15
#define MOD 998244353
#define endl "\n"

#define all(data)       data.begin(),data.end()
#define TYPEMAX(type)   std::numeric_limits<type>::max()
#define TYPEMIN(type)   std::numeric_limits<type>::min()
#define MAXN 1000007
ll n,a[MAXN],occ[3][MAXN],dp[3][MAXN],DP[MAXN];
vector<ll> dd[3][2*MAXN];
struct Fenwick
{
    vector<ll> BIT; ll n;
    void Init(ll x) {n=x; BIT.assign(n+1,0);}
    void Add(ll x,ll d)
    {
        for(int i=x;i<=n;i+=LSB(i)) BIT[i]=(BIT[i]+d)%MOD;
    }
    ll Psum(ll x)
    {
        ll psum=0;
        for(int i=x;i>0;i-=LSB(i)) psum=(psum+BIT[i])%MOD;
        return psum;
    }
    ll Sum(ll x, ll y) {return (((Psum(y)-Psum(x-1))%MOD)+MOD)%MOD;}
};
Fenwick bit[3][2*MAXN];
void Update(ll aa,ll d,ll x,ll y)
{
    x=lower_bound(all(dd[aa][d+n]),x)-dd[aa][d+n].begin();
    bit[aa][d+n].Add(x,y);
}
ll Query(ll aa,ll d,ll x)
{
    x=upper_bound(all(dd[aa][d+n]),x)-dd[aa][d+n].begin();
    return bit[aa][d+n].Sum(x,dd[aa][d+n].size());
}
int main()
{
    ios::sync_with_stdio(false); cin.tie(0);
    string s; cin>>s; n=s.size();
    for(int i=1;i<=n;i++)
    {
        if(s[i-1]=='C') a[i]=0;
        else if(s[i-1]=='I') a[i]=1;
        else a[i]=2;
    }
    for(int i=0;i<=2*n;i++)
    {
        for(int j=0;j<3;j++) dd[j][i].pb(-INF);
    }
    occ[0][0]=occ[1][0]=occ[2][0]=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<3;j++) occ[j][i]=occ[j][i-1]+(ll)(a[i]==j);
        dd[0][occ[1][i]-occ[2][i]+n].pb(3*occ[1][i]-i);
        dd[1][occ[2][i]-occ[0][i]+n].pb(3*occ[2][i]-i);
        dd[2][occ[0][i]-occ[1][i]+n].pb(3*occ[0][i]-i);
    }
    for(int i=0;i<=2*n;i++)
    {
        for(int j=0;j<3;j++) {sort(all(dd[j][i])); bit[j][i].Init(dd[j][i].size()+1);}
    }
    for(int i=1;i<=n;i++)
    {
        dp[i][0]=(dp[i][0]+Query(0,occ[1][i]-occ[2][i],3*occ[1][i]-i))%MOD;
        dp[i][1]=(dp[i][1]+Query(1,occ[2][i]-occ[0][i],3*occ[2][i]-i))%MOD;
        dp[i][2]=(dp[i][2]+Query(2,occ[0][i]-occ[1][i],3*occ[0][i]-i))%MOD;
        if(occ[1][i]==occ[2][i] && occ[0][i]>occ[1][i]) dp[i][0]=(dp[i][0]+1)%MOD;
        else if(occ[0][i]==occ[2][i] && occ[1][i]>occ[0][i]) dp[i][1]=(dp[i][1]+1)%MOD;
        else if(occ[0][i]==occ[1][i]&&occ[2][i]>occ[0][i]) dp[i][2]=(dp[i][2]+1)%MOD;
        DP[i]=((dp[i][0]+dp[i][1])%MOD+dp[i][2])%MOD;
        Update(0,occ[1][i]-occ[2][i],3*occ[1][i]-i,DP[i]);
        Update(1,occ[2][i]-occ[0][i],3*occ[2][i]-i,DP[i]);
        Update(2,occ[0][i]-occ[1][i],3*occ[0][i]-i,DP[i]);
    }
    cout<<DP[n]<<endl;
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 55ms
memory: 331588kb

input:

ICPC

output:

2

result:

ok single line: '2'

Test #2:

score: -100
Runtime Error

input:

CCCIIIPPP

output:


result: