/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 3ms 6.527 MiB
#2 Time Exceeded ≥1077ms ≥13.027 MiB
#3 Time Exceeded ≥1097ms ≥13.027 MiB
#4 Time Exceeded ≥1099ms ≥12.027 MiB
#5 Time Exceeded ≥1098ms ≥13.277 MiB
#6 Time Exceeded ≥1098ms ≥13.527 MiB
#7 Time Exceeded ≥1097ms ≥16.898 MiB
#8 Wrong Answer 146ms 17.234 MiB
#9 Time Exceeded ≥1099ms ≥16.77 MiB
#10 Time Exceeded ≥1100ms ≥16.77 MiB
#11 Time Exceeded ≥1093ms ≥16.965 MiB
#12 Time Exceeded ≥1099ms ≥16.77 MiB

Code

#include<bits/stdc++.h>
using namespace std;
const long long M=1e5+10,MOD=1000000000;
typedef long long ll;
int level[M];
vector<int>edge[M];
int cnt=0;
int in[M],out[M];
int bit[26][M];
int query(int id,int c){
    int sum=0;
    while(id>0){
        sum+=bit[c][id];
        id-=id & (-id);
    }
    return sum;
}
void update(int id,int n,int val,int c){
    while(id<=n){
        bit[c][id]+=val;
        id+=id & (-id);

    }
}
void dfs(int x,int p){
    cnt++;
    in[x]=cnt;
    for(auto u:edge[x]){
        if(u!=p){
            dfs(u,x);
        }
    }
   out[x]=cnt;

   
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    //cin>>t;
    while(t--){
        int n;
        cin>>n;
        vector<char>s(n);
        for(int i=0;i<n;i++)cin>>s[i];
        for(int i=1;i<n;i++){
            int x,y;
            cin>>x>>y;
            edge[x].push_back(y);
            edge[y].push_back(x);
        }
        dfs(1,0);
        for(char ch='a';ch<='z';ch++){
            for(int j=1;j<=n;j++){
                if(s[j-1]==ch){
                    update(in[j],n,1,ch-'a');
                }
            }
        }
        
        int q;
        cin>>q;
        while(q--){
            int type;
            cin>>type;
            if(type==1){
                int x;
                char ch;
                cin>>x>>ch;
                if(ch==s[x-1])continue;
                update(in[x-1],n,-1,s[x-1]-'a');
                s[x-1]=ch;
                update(in[x-1],n,1,s[x-1]-'a');

            }
            else{
                int x;
                cin>>x;
                int mx=-1;
                char ans='a';
                for(char ch='a';ch<='z';ch++){
                    int sumoffre=query(out[x],ch-'a')-query(in[x]-1,ch-'a');
                    if(sumoffre>mx){
                        mx=sumoffre;
                        ans=ch;
                    }

                }
                cout<<ans<<"\n";
            }
           
        }
       // for(int i=1;i<=n;i++)edge[i].clear();

    }
        


   return 0;
 
}

Information

Submit By
Type
Submission
Problem
P1091 Alphabetical Kingdom
Language
C++20 (G++ 13.2.0)
Submit At
2024-08-22 14:13:24
Judged At
2024-08-22 14:13:24
Judged By
Score
5
Total Time
≥1100ms
Peak Memory
≥17.234 MiB