Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;
// Driver function to sort the vector elements 
// by second element of pairs 
bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
} 

void ans(ll i, ll j) {
    cout << setfill('0') << right << setw(6) << i; 
    cout << setfill('0') << right << setw(6) << j << endl;

}

int main() {
    ll N,M;
    cin >> N >> M;
    vector<pair<pair<ll,ll>,ll>> vec;
    for (ll i = 0;i<M;i++) {
        ll p,y;
        cin >> p >> y;
        pair<pair<ll,ll>,ll> pp;
        pp = make_pair(make_pair(p,y),i);
        vec.push_back(pp);
    }
    sort(vec.begin(),vec.end());
    ll city = vec.at(0).first.first; //初めの市
    ll cnt = 1;
    for (ll i = 0;i<M;i++) {
        if (vec.at(i).first.first == city) {
            vec.at(i).first.second = cnt;
            cnt++;
        }
        else {
            cnt = 1;
            city = vec.at(i).first.first;
            vec.at(i).first.second = 1;
        }
    }
    sort(vec.begin(),vec.end(),sortbysec);

    for (ll i = 0;i<M;i++) {
        ans(vec.at(i).first.first,vec.at(i).first.second);
    }
}


Compiler output:
In file included from /usr/include/c++/14/bits/stl_algobase.h:71,
                 from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/predefined_ops.h: In instantiation of 'constexpr bool __gnu_cxx::__ops::_Iter_comp_iter<_Compare>::operator()(_Iterator1, _Iterator2) [with _Iterator1 = __gnu_cxx::__normal_iterator<std::pair<std::pair<long long int, long long int>, long long int>*, std::vector<std::pair<std::pair<long long int, long long int>, long long int> > >; _Iterator2 = __gnu_cxx::__normal_iterator<std::pair<std::pair<long long int, long long int>, long long int>*, std::vector<std::pair<std::pair<long long int, long long int>, long long int> > >; _Compare = bool (*)(const std::pair<int, int>&, const std::pair<int, int>&)]':
/usr/include/c++/14/bits/stl_algo.h:1777:14:   required from 'void std::__insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<pair<pair<long long int, long long int>, long long int>*, vector<pair<pair<long long int, long long int>, long long int> > >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(const pair<int, int>&, const pair<int, int>&)>]'
 1777 |           if (__comp(__i, __first))
      |               ~~~~~~^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1817:25:   required from 'void std::__final_insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<pair<pair<long long int, long long int>, long long int>*, vector<pair<pair<long long int, long long int>, long long int> > >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(const pair<int, int>&, const pair<int, int>&)>]'
 1817 |           std::__insertion_sort(__first, __first + int(_S_threshold), __comp);
      |           ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1908:31:   required from 'void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<pair<pair<long long int, long long int>, long long int>*, vector<pair<pair<long long int, long long int>, long long int> > >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(const pair<int, int>&, const pair<int, int>&)>]'
 1908 |           std::__final_insertion_sort(__first, __last, __comp);
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:4805:18:   required from 'void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator<pair<pair<long long int, long long int>, long long int>*, vector<pair<pair<long long int, long long int>, long long int> > >; _Compare = bool (*)(const pair<int, int>&, const pair<int, int>&)]'
 4805 |       std::__sort(__first, __last, __gnu_cxx::__ops::__iter_comp_iter(__comp));
      |       ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:49:9:   required from here
   49 |     sort(vec.begin(),vec.end(),sortbysec);
      |     ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/predefined_ops.h:158:30: error: invalid initialization of reference of type 'const std::pair<int, int>&' from expression of type 'std::pair<std::pair<long long int, long long int>, long long int>'
  158 |         { return bool(_M_comp(*__it1, *__it2)); }
      |                       ~~~~~~~^~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/predefined_ops.h: In instantiation of 'bool __gnu_cxx::__ops::_Val_comp_iter<_Compare>::operator()(_Value&, _Iterator) [with _Value = std::pair<std::pair<long long int, long long int>, long long int>; _Iterator = __gnu_cxx::__normal_iterator<std::pair<std::pair<long long int, long long int>, long long int>*, std::vector<std::pair<std::pair<long long int, long long int>, long long int> > >; _Compare = bool (*)(const std::pair<int, int>&, const std::pair<int, int>&)]':
/usr/include/c++/14/bits/stl_algo.h:1757:20:   required from 'void std::__unguarded_linear_insert(_RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<pair<pair<long long int, long long int>, long long int>*, vector<pair<pair<long long int, long long int>, long long int> > >; _Compare = __gnu_cxx::__ops::_Val_comp_iter<bool (*)(const pair<int, int>&, const pair<int, int>&)>]'
 1757 |       while (__comp(__val, __next))
      |              ~~~~~~^~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1785:36:   required from 'void std::__insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<pair<pair<long long int, long long int>, long long int>*, vector<pair<pair<long long int, long long int>, long long int> > >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(const pair<int, int>&, const pair<int, int>&)>]'
 1785 |             std::__unguarded_linear_insert(__i,
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
 1786 |                                 __gnu_cxx::__ops::__val_comp_iter(__comp));
      |                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1817:25:   required from 'void std::__final_insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<pair<pair<long long int, long long int>, long long int>*, vector<pair<pair<long long int, long long int>, long long int> > >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(const pair<int, int>&, const pair<int, int>&)>]'
 1817 |           std::__insertion_sort(__first, __first + int(_S_threshold), __comp);
      |           ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1908:31:   required from 'void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<pair<pair<long long int, long long int>, long long int>*, vector<pair<pair<long long int, long long int>, long long int> > >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(const pair<int, int>&, const pair<int, int>&)>]'
 1908 |           std::__final_insertion_sort(__first, __last, __comp);
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:4805:18:   required from 'void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator<pair<pair<long long int, long long int>, long long int>*, vector<pair<pair<long long int, long long int>, long long int> > >; _Compare = bool (*)(const pair<int, int>&, const pair<int, int>&)]'
 4805 |       std::__sort(__first, __last, __gnu_cxx::__ops::__iter_comp_iter(__comp));
      |       ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:49:9:   required from here
   49 |     sort(vec.begin(),vec.end(),sortbysec);
      |     ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/predefined_ops.h:240:30: error: invalid initialization of reference of type 'const std::pair<int, int>&' from expression of type 'std::pair<std::pair<long long int, long long int>, long long int>'
  240 |         { return bool(_M_comp(__val, *__it)); }
      |                       ~~~~~~~^~~~~~~~~~~~~~
/usr/include/c++/14/bits/predefined_ops.h: In instantiation of 'bool __gnu_cxx::__ops::_Iter_comp_val<_Compare>::operator()(_Iterator, _Value&) [with _Iterator = __gnu_cxx::__normal_iterator<std::pair<std::pair<long long int, long long int>, long long int>*, std::vector<std::pair<std::pair<long long int, long long int>, long long int> > >; _Value = std::pair<std::pair<long long int, long long int>, long long int>; _Compare = bool (*)(const std::pair<int, int>&, const std::pair<int, int>&)]':
/usr/include/c++/14/bits/stl_heap.h:140:48:   required from 'void std::__push_heap(_RandomAccessIterator, _Distance, _Distance, _Tp, _Compare&) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<pair<pair<long long int, long long int>, long long int>*, vector<pair<pair<long long int, long long int>, long long int> > >; _Distance = long int; _Tp = pair<pair<long long int, long long int>, long long int>; _Compare = __gnu_cxx::__ops::_Iter_comp_val<bool (*)(const pair<int, int>&, const pair<int, int>&)>]'
  140 |       while (__holeIndex > __topIndex && __comp(__first + __parent, __value))
      |                                          ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_heap.h:247:23:   required from 'void std::__adjust_heap(_RandomAccessIterator, _Distance, _Distance, _Tp, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<pair<pair<long long int, long long int>, long long int>*, vector<pair<pair<long long int, long long int>, long long int> > >; _Distance = long int; _Tp = pair<pair<long long int, long long int>, long long int>; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(const pair<int, int>&, const pair<int, int>&)>]'
  247 |       std::__push_heap(__first, __holeIndex, __topIndex,
      |       ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  248 |                        _GLIBCXX_MOVE(__value), __cmp);
      |                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_heap.h:356:22:   required from 'void std::__make_heap(_RandomAccessIterator, _RandomAccessIterator, _Compare&) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<pair<pair<long long int, long long int>, long long int>*, vector<pair<pair<long long int, long long int>, long long int> > >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(const pair<int, int>&, const pair<int, int>&)>]'
  356 |           std::__adjust_heap(__first, __parent, __len, _GLIBCXX_MOVE(__value),
      |           ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  357 |                              __comp);
      |                              ~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1593:23:   required from 'void std::__heap_select(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare) [with _Ra