Source Code
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
template<class T> using ordered_set = tree<T, null_type , less<T> , rb_tree_tag , tree_order_statistics_node_update> ;
#define double long double
#define ll long long
#define Test int T;cin>>T;while(T--)
#define pi acos(-1)
#define endl "\n"
#define fx(x) fixed<<setprecision(x)
#define sz(s) (int)s.size()
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define mem(a,n) memset((a),n,sizeof (a))
#define INF 1e9
#define ii pair<ll,ll>
ll gcd(ll x,ll y){return(!y?x:gcd(y,x%y));}
ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
void file(){
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#else
    //freopen("peacefulsets.in", "r", stdin);
    //freopen("peacefulsets.out", "w", stdout);
#endif
}
void fast(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    file();
}
int dx[]= {-1,0,0,1};
int dy[]= {0,-1,1,0};
const double eps=1e-9;
const int mod=32768;
const int N=2e5+2,M=120+5;
struct name{
    map<int,int>mp;
};
int main(){
    fast();
    map<string,name>mp;
    map<string,bool>used;
    int n;
    cin>>n;
    while(n--){
        string s;cin>>s;
        if(!used[s]){
            cout<<"ok\n";
            used[s]=1;
        }
        else{
            //cout<<"H "<<s<<endl;
            int mx=1;
            while(mp[s].mp[mx])mx++;
            string tmp=s+to_string(mx);
            while(used[tmp]){
                mx++;
                tmp=s+to_string(mx);
            }
            cout<<tmp<<endl;
            used[tmp]=1;
        }
    }
    return 0;
}
Copy
Registration System Rand()
GNU G++17
3091 ms
900 KB
Time Limit Exceeded