Problem p03030 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef std::pair<int, int> pii;
typedef std::pair<ll, ll> pll;
typedef std::pair<double, double> pdd;
using namespace std;

#define fastio()                                                               \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define loop(i, a, b) for (ll i = a; i < b; i++)
#define loope(i, a, b) for (ll i = a; i <= b; i++)
#define test()                                                                 \
  ull testcase;                                                                \
  cin >> testcase;                                                             \
  while (testcase--)
#define pb push_back
#define mp make_pair
#define nl cout << "\n"
#define prime 1000000007
#define debug(x) cout << (#x) << " : " << x, nl
#define debug2(x, y) cout << (#x) << " : " << x << " " << (#y) << " : " << y, nl
#define debug3(x, y, z)                                                        \
  cout << (#x) << " : " << x << " " << (#y) << " : " << y << " " << (#z)       \
       << " : " << z,                                                          \
      nl
#define f first
#define s second
#define oa(a, n)                                                               \
  loop(i, 0, n) cout << a[i] << " ";                                           \
  nl;
#define ov(a)                                                                  \
  loop(i, 0, a.size()) cout << a[i] << " ";                                    \
  nl;
#define MOD(a) (((a % prime) + prime) % prime)

int main() {

#ifndef ONLINE_JUDGE
  // for getting input from input.txt
  freopen("input.txt", "r", stdin);
  // for writing output to output.txt
  freopen("output.txt", "w", stdout);
#endif

  vector<pair<string, ll>> v;
  map<ll, ll> m;

  ll n, i;

  cin >> n;

  loop(i, 1, n + 1) {
    string s;
    ll u;
    cin >> s >> u;
    v.pb(mp(s, u));
    m[u] = i;
  }

  sort(v.begin(), v.end());

  string s1 = v[0].first;

  vector<ll> v1;

  // loop(i,0,v.size())
  //     cout << v[i].first << " " << v[i].second << endl;

  loop(i, 0, n) {
    if (s1 == v[i].first) {
      v1.pb(v[i].second);
      // cout << s1 << " " << m[v[i].second] << endl;
    } else {
      sort(v1.begin(), v1.end(), greater<ll>());
      for (ll j = 0; j < v1.size(); j++)
        cout << m[v1[j]] << endl;
      v1.clear();
      v1.pb(v[i].second);
      s1 = v[i].first;
    }
  }
  sort(v1.begin(), v1.end(), greater<ll>());
  for (ll j = 0; j < v1.size(); j++)
    cout << m[v1[j]] << endl;
}

Fixed submission:
#include <bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef std::pair<int, int> pii;
typedef std::pair<ll, ll> pll;
typedef std::pair<double, double> pdd;
using namespace std;

#define fastio()                                                               \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define loop(i, a, b) for (ll i = a; i < b; i++)
#define loope(i, a, b) for (ll i = a; i <= b; i++)
#define test()                                                                 \
  ull testcase;                                                                \
  cin >> testcase;                                                             \
  while (testcase--)
#define pb push_back
#define mp make_pair
#define nl cout << "\n"
#define prime 1000000007
#define debug(x) cout << (#x) << " : " << x, nl
#define debug2(x, y) cout << (#x) << " : " << x << " " << (#y) << " : " << y, nl
#define debug3(x, y, z)                                                        \
  cout << (#x) << " : " << x << " " << (#y) << " : " << y << " " << (#z)       \
       << " : " << z,                                                          \
      nl
#define f first
#define s second
#define oa(a, n)                                                               \
  loop(i, 0, n) cout << a[i] << " ";                                           \
  nl;
#define ov(a)                                                                  \
  loop(i, 0, a.size()) cout << a[i] << " ";                                    \
  nl;
#define MOD(a) (((a % prime) + prime) % prime)

int main() {

  vector<pair<string, ll>> v;
  map<ll, ll> m;

  ll n, i;

  cin >> n;

  loop(i, 1, n + 1) {
    string s;
    ll u;
    cin >> s >> u;
    v.pb(mp(s, u));
    m[u] = i;
  }

  sort(v.begin(), v.end());

  string s1 = v[0].first;

  vector<ll> v1;

  // loop(i,0,v.size())
  //     cout << v[i].first << " " << v[i].second << endl;

  loop(i, 0, n) {
    if (s1 == v[i].first) {
      v1.pb(v[i].second);
      // cout << s1 << " " << m[v[i].second] << endl;
    } else {
      sort(v1.begin(), v1.end(), greater<ll>());
      for (ll j = 0; j < v1.size(); j++)
        cout << m[v1[j]] << endl;
      v1.clear();
      v1.pb(v[i].second);
      s1 = v[i].first;
    }
  }
  sort(v1.begin(), v1.end(), greater<ll>());
  for (ll j = 0; j < v1.size(); j++)
    cout << m[v1[j]] << endl;
}