GitanshSS's blog

By GitanshSS, history, 6 weeks ago, In English,

i dont know why this is giving runtime error on codeforces BUT on sublime its running FINE & giving correct output.. why this is happening?

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ff first
#define ss second
#define pb push_back
#define mkp make_pair
const ll mod=1e9+7;
 
void solve(){
    ll n,m;
    cin>>n>>m;
    ll a[27]={0};
    ll mis[m];
    map<ll,ll> mp;
    string s;
    cin>>s;
    for(ll i=0;i<s.length();i++){
            ll p=s[i]-'a';
            a[p]++;
    }

    for(ll i=0;i<m;i++){
        cin>>mis[i];
        mp[mis[i]]++;
    }
    for(auto i=mp.rbegin();i!=mp.rend();i++){
        ll f=i->first;
        ll cnt=i->second;
        i++;
        if(i==mp.rend()){
            break;
        }
        ll f1=i->first;
        i->second+=cnt;

        for(ll j=f1;j<f;j++){
            ll p=s[j]-'a';
            a[p]+=cnt;
        }
        mp.erase(f);
        i--;
    }

    for(auto i=mp.begin();i!=mp.end();i++){
        ll flag=i->second;
        ll f=i->first;
        for(ll j=0;j<=f-1;j++){
            ll p=s[j]-'a';
            a[p]+=flag;
        }
    }
    for(ll i=0;i<26;i++){
        cout<<a[i]<<" ";
    }

    return;
}
int main()
{
    IOS;
    ll t;
    cin>>t;
    while(t--){
        solve();
        cout<<endl;
    }
    //solve();
 
    return 0;
}
 
 
 
 
  • Vote: I like it
  • -11
  • Vote: I do not like it

»
6 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Oh, look, what a miserable code......

»
6 weeks ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

whats problem in that