QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#220707#5474. Incredibly Cute Penguin ChicksacagubicaTL 5998ms744524kbC++142.2kb2023-10-20 18:19:512023-10-20 18:19:51

Judging History

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

  • [2023-10-20 18:19:51]
  • 评测
  • 测评结果:TL
  • 用时:5998ms
  • 内存:744524kb
  • [2023-10-20 18:19:51]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
string S;
int sol,A[1000005],B[1000005],C[1000005];
long long dp[1000009];
long long MOD=998244353;
struct slog{
  int ID;
  int m[3],v[3],mid[3];
}SVE[1000009];
int GLOBcmp=0;
bool cmp(slog x, slog y){
  return x.v[GLOBcmp]<y.v[GLOBcmp];
}map<int,vector<slog>>M[3];
map<int,vector<int>>fM[3];
map<int,bool>imamM[3];
vector<int>ALLm[3];

void update_fenvicks(int ID){
  long long dodaj=dp[ID];
  slog sl=SVE[ID];
  for(int X=0; X<=2; X++){
    int m=sl.m[X];
    int mid=sl.mid[X];
    while(mid<fM[X][m].size()-2){
      fM[X][m][mid]+=dodaj;
      if(fM[X][m][mid]>=MOD)fM[X][m][mid]-=MOD;
      mid+=mid&(-mid);
    }
  }
}
void add_fenvicks_to_dp(int ID){
  slog sl=SVE[ID];
  for(int X=0; X<=2; X++){
    int m=sl.m[X];
    int mid=sl.mid[X]-1;
    long long ukupno=0;
    while(mid>0){
      ukupno+=fM[X][m][mid];
      if(ukupno>=MOD)ukupno-=MOD;
      mid-=mid&(-mid);
    }
    dp[ID]+=ukupno;
    if(dp[ID]>=MOD)dp[ID]-=MOD;
  }
}
int main(){
  cin>>S;
  S=' '+S+' ';
  for(int i=1; i<S.size()-1; i++){
    A[i]=A[i-1]+(S[i]=='I');
    B[i]=B[i-1]+(S[i]=='P');
    C[i]=C[i-1]+(S[i]=='C');
  }
  for(int i=0; i<S.size()-1; i++){
    SVE[i].ID=i;
    SVE[i].m[0]=A[i]-B[i];
    SVE[i].m[1]=A[i]-C[i];
    SVE[i].m[2]=B[i]-C[i];
    SVE[i].v[0]=3*C[i]-i;
    SVE[i].v[1]=3*B[i]-i;
    SVE[i].v[2]=3*A[i]-i;
  }
  for(int i=0; i<S.size()-1; i++){
    slog sl=SVE[i];
    for(int X=0; X<=2; X++){
      M[X][sl.m[X]].push_back(sl);
      if(!imamM[X][sl.m[X]])ALLm[X].push_back(sl.m[X]);
      imamM[X][sl.m[X]]=true;
    }
  }
  for(int X=0; X<=2; X++){
    for(int i=0; i<ALLm[X].size(); i++){
      int m=ALLm[X][i];
      GLOBcmp=X;
      sort(M[X][m].begin(),M[X][m].end(),cmp);
      vector<slog>v=M[X][m];
      int mid=1;
      for(int j=0; j<v.size()-1; j++){
        SVE[v[j].ID].mid[X]=mid;
        if(v[j].v[X]<v[j+1].v[X])mid++;
      }
      SVE[v[v.size()-1].ID].mid[X]=mid;
      for(int i=0; i<=mid+3; i++)fM[X][m].push_back(0);
    }
  }
  dp[0]=1;
  update_fenvicks(0);
  for(int i=1; i<S.size()-1; i++){
    add_fenvicks_to_dp(i);
    update_fenvicks(i);
  }
  cout<<dp[S.size()-2]<<"\n";
  return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 5504kb

input:

ICPC

output:

2

result:

ok single line: '2'

Test #2:

score: 0
Accepted
time: 1ms
memory: 5508kb

input:

CCCIIIPPP

output:

69

result:

ok single line: '69'

Test #3:

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

input:

PICCICCIPPI

output:

24

result:

ok single line: '24'

Test #4:

score: 0
Accepted
time: 1241ms
memory: 205884kb

input:

PCPPCCICPICPCPCPCCPPIPPPIICCCICPICCPPPIPCCCCICCIICPCCICCCPCICIPPIPIPIPPCCPCIPPCCPPCCIPPPIPPCIICIIIPPCIPPICPPICCPIICCCCCCCICPCCPPIPIPICPCIICPCCIPICCCPPCPIIICPCPPPIIIIICCCPCICCPPCPPCICIIIPIPICPCPPPPICPCPIPIIICCICPCIPPICCICPIIPPCCCIICPCPCCICCPICPPPPPPICCCIPCCICICIPICIIICCICPCIPIICPIPIIICCPCCIIPCCCCPIPI...

output:

216523282

result:

ok single line: '216523282'

Test #5:

score: 0
Accepted
time: 1268ms
memory: 212492kb

input:

ICIPCICCIPIPIIPPCPCICICPCPCPIIICICPPICCICPIPCPCIIPPIPCCIPIPIPIICCICICCCIPPIIPCPPCIIICCICCCCCCPIPICCIPIICIICPIPCCICPPCCIPIPIICCCPCCIPCPPCCIIIIIPCIPIIPICIIIPIICCCIPPPIPICIIIICIIIPICIICPIPCCICIPCCIPICCCPPIPIIPICPPCPICIPIPPPPPCIPCCIPPICIPCICPCCCCPPIIIPCPICCICIPIIPICPIIIIPPPCPIIIPCCPPIIPPICPIIICCCPICPPIC...

output:

977504498

result:

ok single line: '977504498'

Test #6:

score: 0
Accepted
time: 1291ms
memory: 211428kb

input:

PPCCCICCIPPICCPCCCCIPPPIICPIPIPPPPIPPPPPPCPIPICCPCCPICPIPPPIIPIPIIPPCCPIICPPIIIPPCCCIIPCCIPCCCCCCIIIPIPCICCIICIIICCCCPCCICPPCCPCCIPICCPPIIPIIPIPCIIPIIPPPCCIPCPCCICCIPICPPPCIPPIPCCPCPCCIPIICCIPCCIPPCPCIPICIICPPICIIICIPIIIIIPCCCPPIPPPCIICIIIPPCIPCIPCIICCCCPIPCPICICPIPCPPIPIPICCPCCCCPCIPCPPCCIPCCCCCPII...

output:

785880133

result:

ok single line: '785880133'

Test #7:

score: 0
Accepted
time: 1230ms
memory: 207452kb

input:

ICIPCPIPCCCCCCCPCCPCCIPCPCPIPPCPIPCICPPIPPPPICPIIPPIICPICPICPPICICICCCIIPCPPCCICCCCPIICPPPIPIPCICPIPPPPCCPICPCPICICPPIIIICIICPPIPIIICCCCPIPIIPICCCIPCCPPCPPPPIIIIICIPCPCCPIIICICIPPCCPIPPCIIPCCCIIICPCIPCIIIIPCIIPCIICCCIPPIPPCIIPCICIPIIPICCICCPCPIICCCIPIICCCPIPPCCIIIICPPIICPCPCIPPPCPCICPPIPIPCCPIPPPIPI...

output:

687587235

result:

ok single line: '687587235'

Test #8:

score: 0
Accepted
time: 1273ms
memory: 209840kb

input:

IICCCIPIIIIIPICIICPCPCIICCIIICCCIIPICICCCPCPCPPPIIPIPPICIICICIPIICCICCIIIPCIICCPPIPICIPPCPCPCPIICCIIICIPPICCICPPIPPPPICPCPIPCCCPCPCPPPPIICPCIIIIIIIPIPIICICCPPIIPPCICPCPCIPCPICPPPICCICIICPPIPPPIPIPIPPCIPPCIPPCPPPIICICCCPICIPPIPCCPIIPPCIPPICCIIIPPPPPIIPPICPCPCIPPCCPCIIIPPICCCIIIIICIPPIIICPCIIICPPCPCPP...

output:

698376687

result:

ok single line: '698376687'

Test #9:

score: 0
Accepted
time: 1285ms
memory: 208248kb

input:

IIPICCCCIPPCCPICCIIPPPCIPCCPPIPIICICPCCIIPPCCCICICPPICCICPPIICIIPICPICIPPPPCPCCPIICCPPIPPCIIIIPICICICCIIPPCICCCCCPICPIPCPPCCPPICPICCCICCIPICCICPIICCPIPIPICCPPCCPCPCCPICCPICCCCCCIPIICPIPICICCPIIPIPICIICIPPPIPCICIPIPPICPICICPPICICCIPCIPPPCIPIIPPPIICICPPPIICCCPIIICIPIPPICICIPPPCCPCCIIPCCCPPPCPICPICPPCP...

output:

850857669

result:

ok single line: '850857669'

Test #10:

score: 0
Accepted
time: 5998ms
memory: 744524kb

input:

IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII...

output:

709758735

result:

ok single line: '709758735'

Test #11:

score: -100
Time Limit Exceeded

input:

PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP...

output:

854001544

result: