prithivMLmods/Coder-Stat huggingface dataset:
Problem p03221 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define p(s) std::cout << s;
#define pl(s) std::cout << s << endl;
#define printIf(j, s1, s2) cout << (j ? s1 : s2) << endl;
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;
#define all(v) v.begin(), v.end()
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
typedef long long int ll;

const ll longinf = 1LL << 60;

vector<int> g[100005];

int main() {
  int N, M;
  cin >> N >> M;

  vector<int> P(M), Y(M);
  REP(i, M) {
    cin >> P[i] >> Y[i];
    g[P[i]].push_back(Y[i]);
  }
  REP(i, M) sort(all(g[P[i]]));

  REP(i, M) {
    int d = (upper_bound(all(g[P[i]]), Y[i]) - g[P[i]].begin());
    printf("%06d%06d\n", P[i], d);
  }

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define p(s) std::cout << s;
#define pl(s) std::cout << s << endl;
#define printIf(j, s1, s2) cout << (j ? s1 : s2) << endl;
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;
#define all(v) v.begin(), v.end()
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
typedef long long int ll;

const ll longinf = 1LL << 60;

vector<int> g[100005];

int main() {
  int N, M;
  cin >> N >> M;

  vector<int> P(M), Y(M);
  REP(i, M) {
    cin >> P[i] >> Y[i];
    g[P[i]].push_back(Y[i]);
  }
  REP(i, N) if (!g[i + 1].empty()) sort(all(g[i + 1]));

  REP(i, M) {
    int d = (upper_bound(all(g[P[i]]), Y[i]) - g[P[i]].begin());
    printf("%06d%06d\n", P[i], d);
  }

  return 0;
}
Problem p03221 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(void) {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> city(m);
  vector<vector<int>> a(n);
  for (int i = 0; i < m; i++) {
    int p, y;
    cin >> p >> y;
    city[i].first = p;
    city[i].second = y;
    a[p - 1].push_back(y);
  }
  for (int i = 0; i < a.size(); i++) {
    sort(a[i].begin(), a[i].end());
  }
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < a[city[i].first - 1].size(); j++) {
      // ここを2分にする?
      if (city[i].second == a[city[i].first - 1][j]) {
        city[i].second = j + 1;
      }
    }
  }
  // 6桁にする
  vector<string> ans(m);
  for (int i = 0; i < m; i++) {
    ans[i] = "000000000000";
    int at = city[i].first;
    string s_at = to_string(at);
    int year = city[i].second;
    string s_year = to_string(year);
    ans[i].replace(6 - s_at.size(), s_at.size(), s_at);
    ans[i].replace(12 - s_year.size(), s_year.size(), s_year);
    cout << ans[i] << endl;
    ;
  }

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(void) {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> city(m);
  vector<vector<int>> a(n);
  for (int i = 0; i < m; i++) {
    int p, y;
    cin >> p >> y;
    city[i].first = p;
    city[i].second = y;
    a[p - 1].push_back(y);
  }
  for (int i = 0; i < a.size(); i++) {
    sort(a[i].begin(), a[i].end());
  }
  for (int i = 0; i < m; i++) {
    int now_f = city[i].first - 1; // 探す場所
    int now_s = city[i].second;    // 探したいもの
    auto Iter1 = upper_bound(a[now_f].begin(), a[now_f].end(), now_s);
    city[i].second = Iter1 - a[now_f].begin();
    // for(int j=0;j<a[city[i].first-1].size();j++){
    //     //ここを2分にする?
    //     if(city[i].second==a[city[i].first-1][j]){
    //         city[i].second = j+1;
    //     }
    // }
  }
  // 6桁にする
  vector<string> ans(m);
  for (int i = 0; i < m; i++) {
    ans[i] = "000000000000";
    int at = city[i].first;
    string s_at = to_string(at);
    int year = city[i].second;
    string s_year = to_string(year);
    ans[i].replace(6 - s_at.size(), s_at.size(), s_at);
    ans[i].replace(12 - s_year.size(), s_year.size(), s_year);
    cout << ans[i] << endl;
    ;
  }

  return 0;
}
Problem p03221 (C++)

Buggy submission (status: Runtime Error):
#define FOR(i, begin, end) for (int i = (begin); i < (end); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(), a.end())
#define SORTD(a) sort(a.rbegin(), a.rend());
#define ll long long
#define INF 1000000000000000000
#define INT_MAX 2147483647

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <ios>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <utility>
#include <vector>

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;

  int P[100001], Y[100001];
  vector<int> py[100001];

  REP(i, M) {
    cin >> P[i] >> Y[i];
    py[P[i]].push_back(Y[i]);
  }

  REP(i, N + 1) { SORT(py[i + 1]); }

  REP(i, M) {
    cout << setfill('0') << setw(6) << right << P[i];
    cout << setfill('0') << setw(6) << right
         << int(lower_bound(py[P[i]].begin(), py[P[i]].end(), Y[i]) -
                py[P[i]].begin()) +
                1
         << endl;
  }
}


Fixed submission:
#define FOR(i, begin, end) for (int i = (begin); i < (end); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(), a.end())
#define SORTD(a) sort(a.rbegin(), a.rend());
#define ll long long
#define INF 1000000000000000000
#define INT_MAX 2147483647

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <ios>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <utility>
#include <vector>

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;

  int P[100001], Y[100001];
  vector<int> py[100001];

  REP(i, M) {
    cin >> P[i] >> Y[i];
    py[P[i]].push_back(Y[i]);
  }

  REP(i, N + 1) { SORT(py[i]); }

  REP(i, M) {
    cout << setfill('0') << setw(6) << right << P[i];
    cout << setfill('0') << setw(6) << right
         << int(lower_bound(py[P[i]].begin(), py[P[i]].end(), Y[i]) -
                py[P[i]].begin()) +
                1
         << endl;
  }
}
Problem p03221 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define show(a, n)                                                             \
  rep(i, n) { cout << a[i] << ' '; }                                           \
  cout << endl;

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

void print_num(int n) {
  if (n < 10)
    cout << "00000" << n;
  else if (n < 100)
    cout << "0000" << n;
  else if (n < 1000)
    cout << "000" << n;
  else if (n < 10000)
    cout << "00" << n;
  else if (n < 100000)
    cout << "0" << n;
  else
    cout << n;
}

int main() {
  int n, m;
  cin >> n >> m;
  int p[N], y[N];
  pii yp[N];
  rep(i, m) {
    cin >> p[i] >> y[i];
    yp[i] = pii(y[i], p[i]);
  }
  sort(yp, yp + m);
  int pc[N]; // pref to count
  rep(i, N) pc[i] = 0;
  int yo[N]; // year to order
  rep(i, m) {
    int ty = yp[i].first;
    int tp = yp[i].second;
    pc[tp]++;
    yo[ty] = pc[tp];
  }
  rep(i, m) {
    print_num(p[i]);
    print_num(yo[y[i]]);
    cout << endl;
  }
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define show(a, n)                                                             \
  rep(i, n) { cout << a[i] << ' '; }                                           \
  cout << endl;

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

void print_num(int n) {
  if (n < 10)
    cout << "00000" << n;
  else if (n < 100)
    cout << "0000" << n;
  else if (n < 1000)
    cout << "000" << n;
  else if (n < 10000)
    cout << "00" << n;
  else if (n < 100000)
    cout << "0" << n;
  else
    cout << n;
}

int main() {
  int n, m;
  cin >> n >> m;
  int p[N], y[N];
  pii yp[N];
  rep(i, m) {
    cin >> p[i] >> y[i];
    yp[i] = pii(y[i], p[i]);
  }
  sort(yp, yp + m);
  int pc[N]; // pref to count
  rep(i, N) pc[i] = 0;
  map<int, int> yo;
  rep(i, m) {
    int ty = yp[i].first;
    int tp = yp[i].second;
    pc[tp]++;
    yo[ty] = pc[tp];
  }
  rep(i, m) {
    print_num(p[i]);
    print_num(yo[y[i]]);
    cout << endl;
  }
}
Problem p03221 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int N, M;
  int *P, *Y;
  std::vector<int> *yd;
  cin >> N >> M;
  yd = new std::vector<int>[N];
  P = new int[M];
  Y = new int[M];

  for (int i = 0; i < M; i++) {
    cin >> P[i] >> Y[i];
    yd[P[i] - 1].push_back(Y[i]);
  }

  for (int i = 0; i < N; i++) {
    sort(yd[i].begin(), yd[i].end());
  }

  for (int i = 0; i < M; i++) {
    int rank = 0;
    for (int j = 0; j < yd[P[i] - 1].size(); j++) {
      if (yd[P[i] - 1][j] == Y[i]) {
        rank = j + 1;
        break;
      }
    }
    printf("%06d%06d\n", P[i], rank);
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int N, M;
  int *P, *Y;
  std::vector<int> *yd;
  cin >> N >> M;
  yd = new std::vector<int>[N];
  P = new int[M];
  Y = new int[M];

  for (int i = 0; i < M; i++) {
    cin >> P[i] >> Y[i];
    yd[P[i] - 1].push_back(Y[i]);
  }

  for (int i = 0; i < N; i++) {
    sort(yd[i].begin(), yd[i].end());
  }

  for (int i = 0; i < M; i++) {
    int index = P[i] - 1;
    int rank = int(lower_bound(yd[index].begin(), yd[index].end(), Y[i]) -
                   yd[index].begin()) +
               1;
    printf("%06d%06d\n", P[i], rank);
  }

  return 0;
}
Problem p03221 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#include <cctype>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) (v).begin(), (v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int, int>

int main() {
  int N, M;
  cin >> N >> M;
  int P[M], Y[M];
  unordered_map<int, vector<int>> YM;
  rep(i, M) {
    cin >> P[i] >> Y[i];
    YM[P[i]].push_back(Y[i]);
  }

  // rep(i,N+1) sort(all(YM.at(i)));
  rep(i, M) { sort(all(YM.at(P[i]))); }

  rep(i, M) {
    auto x = lower_bound(all(YM.at(P[i])), Y[i]) - YM.at(P[i]).begin();
    printf("%06d", P[i]);
    printf("%06d\n", int(x) + 1);
  }

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#include <cctype>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) (v).begin(), (v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int, int>

int main() {
  int N, M;
  cin >> N >> M;
  int P[M], Y[M];
  unordered_map<int, vector<int>> YM;
  rep(i, M) {
    cin >> P[i] >> Y[i];
    YM[P[i]].push_back(Y[i]);
  }

  // rep(i,N+1) sort(all(YM.at(i)));
  for (auto i = YM.begin(); i != YM.end(); i++) {
    sort(all(i->second));
  }

  rep(i, M) {
    auto x = lower_bound(all(YM.at(P[i])), Y[i]) - YM.at(P[i]).begin();
    printf("%06d", P[i]);
    printf("%06d\n", int(x) + 1);
  }

  return 0;
}
Problem p03221 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

void solve() {
  int N, M;
  cin >> N >> M;
  vector<int> P(M), Y(M);
  vector<vector<int>> yd(M + 1, vector<int>(0));
  for (int i = 0; i < M; i++) {
    cin >> P[i] >> Y[i];
    yd[P[i]].push_back(Y[i]);
  }
  for (int i = 0; i < N; i++) {
    sort(yd[i + 1].begin(), yd[i + 1].end());
  }
  for (int i = 0; i < M; i++) {
    cout << setfill('0') << setw(6) << P[i] << setfill('0') << setw(6)
         << (int)(lower_bound(yd[P[i]].begin(), yd[P[i]].end(), Y[i]) -
                  yd[P[i]].begin()) +
                1
         << endl;
  }
}

int main() {
  solve();
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;

void solve() {
  int N, M;
  cin >> N >> M;
  vector<int> P(M), Y(M);
  vector<vector<int>> yd(N + 1, vector<int>(0));
  for (int i = 0; i < M; i++) {
    cin >> P[i] >> Y[i];
    yd[P[i]].push_back(Y[i]);
  }
  for (int i = 0; i < N; i++) {
    sort(yd[i + 1].begin(), yd[i + 1].end());
  }
  for (int i = 0; i < M; i++) {
    cout << setfill('0') << setw(6) << P[i] << setfill('0') << setw(6)
         << (int)(lower_bound(yd[P[i]].begin(), yd[P[i]].end(), Y[i]) -
                  yd[P[i]].begin()) +
                1
         << endl;
  }
}

int main() {
  solve();
  return 0;
}
Problem p03221 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int p[maxn], y[maxn];
vector<int> a[maxn];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &p[i], &y[i]);
    a[p[i]].push_back(y[i]);
    sort(a[p[i]].begin(), a[p[i]].end());
  }
  for (int i = 0; i < m; i++) {
    int pos =
        lower_bound(a[p[i]].begin(), a[p[i]].end(), y[i]) - a[p[i]].begin();
    printf("%06d%06d\n", p[i], pos + 1);
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int p[maxn], y[maxn];
vector<int> a[maxn];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &p[i], &y[i]);
    a[p[i]].push_back(y[i]);
  }
  for (int i = 1; i <= n; i++) {
    if (a[i].size() > 0)
      sort(a[i].begin(), a[i].end());
  }
  for (int i = 0; i < m; i++) {
    int pos =
        lower_bound(a[p[i]].begin(), a[p[i]].end(), y[i]) - a[p[i]].begin();
    printf("%06d%06d\n", p[i], pos + 1);
  }
}
Problem p03221 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

int main() {
  int N, M;
  cin >> N >> M;

  pair<pair<int, int>, int> p[N];
  for (int i = 0; i < M; i++) {
    cin >> p[i].first.first >> p[i].first.second;
    p[i].second = i;
  }

  sort(p, p + M);

  /*for(int i=0;i<M;i++){
    cout << p[i].first.first << " ";
    cout << p[i].first.second << " ";
    cout << p[i].second << endl;
  }*/

  int id[M];
  id[0] = 1;
  for (int i = 1; i < M; i++) {
    if (p[i].first.first != p[i - 1].first.first) {
      id[i] = 1;
    } else {
      id[i] = id[i - 1] + 1;
    }
  }

  pair<int, pair<int, int>> pp[M];
  for (int i = 0; i < M; i++) {
    pp[i].first = p[i].second;
    pp[i].second.first = p[i].first.first;
    pp[i].second.second = id[i];
  }

  sort(pp, pp + M);

  for (int i = 0; i < M; i++) {
    printf("%06d%06d\n", pp[i].second.first, pp[i].second.second);
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

int main() {
  int N, M;
  cin >> N >> M;

  pair<pair<int, int>, int> p[M];
  for (int i = 0; i < M; i++) {
    cin >> p[i].first.first >> p[i].first.second;
    p[i].second = i;
  }

  sort(p, p + M);

  /*for(int i=0;i<M;i++){
    cout << p[i].first.first << " ";
    cout << p[i].first.second << " ";
    cout << p[i].second << endl;
  }*/

  int id[M];
  id[0] = 1;
  for (int i = 1; i < M; i++) {
    if (p[i].first.first != p[i - 1].first.first) {
      id[i] = 1;
    } else {
      id[i] = id[i - 1] + 1;
    }
  }

  pair<int, pair<int, int>> pp[M];
  for (int i = 0; i < M; i++) {
    pp[i].first = p[i].second;
    pp[i].second.first = p[i].first.first;
    pp[i].second.second = id[i];
  }

  sort(pp, pp + M);

  for (int i = 0; i < M; i++) {
    printf("%06d%06d\n", pp[i].second.first, pp[i].second.second);
  }
  return 0;
}
Problem p03221 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <chrono>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>

using namespace std;

int main(int argc, const char *argv[]) {

  ios::sync_with_stdio(false);
  cin.tie(0);

  int n, m;
  cin >> n >> m;
  vector<vector<int>> yp(m, vector<int>(3));
  vector<int> cnt(n + 1, 0);
  for (int i = 0; i < m; i++) {
    cin >> yp[i][0] >> yp[i][1];
    yp[i][2] = i;
    cnt[yp[i][0]]++;
  }
  sort(yp.begin(), yp.end());

  map<int, string> ID;

  int p = 0;
  for (int i = 1; i <= n; i++) {
    while (cnt[i] == 0)
      i++;

    string pid = to_string(i);
    pid = string(6 - pid.size(), '0') + pid;

    for (int j = 0; j < cnt[i]; j++) {
      string xid = to_string(j + 1);
      xid = string(6 - xid.size(), '0') + xid;
      ID.emplace(yp[p][2], pid + xid);
      p++;
    }
  }

  for (auto &iter : ID) {
    cout << iter.second << endl;
  }

  return 0;
}


Fixed submission:
#include <algorithm>
#include <chrono>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>

using namespace std;

int main(int argc, const char *argv[]) {

  ios::sync_with_stdio(false);
  cin.tie(0);

  int n, m;
  cin >> n >> m;
  vector<vector<int>> yp(m, vector<int>(3));
  vector<int> cnt(n + 1, 0);
  for (int i = 0; i < m; i++) {
    cin >> yp[i][0] >> yp[i][1];
    yp[i][2] = i;
    cnt[yp[i][0]]++;
  }
  sort(yp.begin(), yp.end());

  map<int, string> ID;

  int p = 0;
  for (int i = 1; i <= n; i++) {
    string pid = to_string(i);
    pid = string(6 - pid.size(), '0') + pid;

    for (int j = 0; j < cnt[i]; j++) {
      string xid = to_string(j + 1);
      xid = string(6 - xid.size(), '0') + xid;
      ID.emplace(yp[p][2], pid + xid);
      p++;
    }
  }

  for (auto &iter : ID) {
    cout << iter.second << endl;
  }

  return 0;
}
Problem p03221 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ll n, m;
  cin >> n >> m;
  ll p[m], y[m];
  vector<ll> py[m * 2];
  for (int i = 0; i < m; i++)
    cin >> p[i] >> y[i];

  for (int i = 0; i < m; i++)
    py[p[i]].push_back(y[i]);
  for (int i = 0; i < n; i++)
    sort(py[i + 1].begin(), py[i + 1].end());
  for (int i = 0; i < m; i++) {
    printf("%012lld\n",
           ll(p[i]) * 1000000 +
               int(lower_bound(py[p[i]].begin(), py[p[i]].end(), y[i]) -
                   py[p[i]].begin()) +
               1);
  }

  /*	for(int i=0;i<m;i++){
                  printf("%lld\n",*lower_bound(py[p[i]].begin(),py[p[i]].end(),y[i]));
          }*/
  //	for(int i=0;i<m;i++)num[y[i]]=i;
  // sort(y,y+m);
  /*for( vector<ll>::iterator i=begin(py);i!=end(py);++i) {
       std::cout << i << std::endl;
    }*/
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ll n, m;
  cin >> n >> m;
  ll p[m], y[m];
  vector<ll> py[n + 1];
  for (int i = 0; i < m; i++)
    cin >> p[i] >> y[i];

  for (int i = 0; i < m; i++)
    py[p[i]].push_back(y[i]);
  for (int i = 0; i < n; i++)
    sort(py[i + 1].begin(), py[i + 1].end());
  for (int i = 0; i < m; i++) {
    printf("%012lld\n",
           ll(p[i]) * 1000000 +
               int(lower_bound(py[p[i]].begin(), py[p[i]].end(), y[i]) -
                   py[p[i]].begin()) +
               1);
  }

  /*	for(int i=0;i<m;i++){
                  printf("%lld\n",*lower_bound(py[p[i]].begin(),py[p[i]].end(),y[i]));
          }*/
  //	for(int i=0;i<m;i++)num[y[i]]=i;
  // sort(y,y+m);
  /*for( vector<ll>::iterator i=begin(py);i!=end(py);++i) {
       std::cout << i << std::endl;
    }*/
}
Problem p03221 (C++)

Buggy submission (status: Runtime Error):

#include <algorithm>
#include <iostream>
#include <random>
#include <string>
#include <vector>

using std::cerr;
using std::cin;
using std::cout;
using std::endl;

#define NNN (10000)
#define MMM (10000)
void funcC() {
  int N;
  int M;
  std::vector<int> A[NNN + 1];
  int P[NNN];
  int Y[NNN];

  cin >> N;
  cin >> M;

  for (int m = 0; m < M; ++m) {
    int p;
    int y;
    cin >> p;
    cin >> y;
    P[m] = p;
    Y[m] = y;
  }
  for (int m = 0; m < M; ++m) {
    A[P[m]].push_back(Y[m]);
  }
  for (int n = 1; n < N + 1; ++n) {
    std::sort(A[n].begin(), A[n].end());
  }

  for (int m = 0; m < M; ++m) {
    int p = P[m];
    int y = Y[m];

    int idx = std::lower_bound(A[p].begin(), A[p].end(), y) - A[p].begin();
    printf("%.6d%.6d\n", p, idx + 1);
    /*
    int idx = -1;
    for (int i = 0; i < A[p].size(); ++i) {
            if (A[p][i] == y) {
                    //cerr << p << "," << i + 1 << endl;
                    printf("%.6d%.6d\n", p, i + 1);
            }
    }
    */
  }
}

int main() {
  // funcB();
  funcC();
}


Fixed submission:

#include <algorithm>
#include <iostream>
#include <random>
#include <string>
#include <vector>

using std::cerr;
using std::cin;
using std::cout;
using std::endl;

#define NNN (100000)
#define MMM (10000)
void funcC() {
  int N;
  int M;
  std::vector<int> A[NNN + 1];
  int P[NNN];
  int Y[NNN];

  cin >> N;
  cin >> M;

  for (int m = 0; m < M; ++m) {
    int p;
    int y;
    cin >> p;
    cin >> y;
    P[m] = p;
    Y[m] = y;
  }
  for (int m = 0; m < M; ++m) {
    A[P[m]].push_back(Y[m]);
  }
  for (int n = 1; n < N + 1; ++n) {
    std::sort(A[n].begin(), A[n].end());
  }

  for (int m = 0; m < M; ++m) {
    int p = P[m];
    int y = Y[m];

    int idx = std::lower_bound(A[p].begin(), A[p].end(), y) - A[p].begin();
    printf("%.6d%.6d\n", p, idx + 1);
    /*
    int idx = -1;
    for (int i = 0; i < A[p].size(); ++i) {
            if (A[p][i] == y) {
                    //cerr << p << "," << i + 1 << endl;
                    printf("%.6d%.6d\n", p, i + 1);
            }
    }
    */
  }
}

int main() {
  // funcB();
  funcC();
}
Problem p03221 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#pragma comment(linker, "/stck:1024000000,1024000000")
#define lowbit(x) (x & (-x))
#define max(x, y) (x >= y ? x : y)
#define min(x, y) (x <= y ? x : y)
// #define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.1415926535897932384626433832
#define ios() ios::sync_with_stdio(true)
#define INF (1 << 31) - 1;
#define mem(a) (memset(a, 0, sizeof(a)))
#define ALL(a) (a).begin(), (a).end()
struct P {
  int x, y;
} H[200000];
vector<int> G[100005];
int main() {
  set<int> s;
  int N, M;
  int x, y;
  cin >> N >> M;
  for (int i = 1; i <= M; i++) {
    cin >> x >> y;
    H[i].x = x;
    H[i].y = y;
    G[x].push_back(y);
    // s.insert(x);
  }
  for (int i = 1; i <= M; i++) {
    sort(G[H[i].x].begin(), G[H[i].x].end());
  }

  for (int i = 1; i <= M; i++) {
    cout << setw(6) << setfill('0') << H[i].x;
    cout << setw(6) << setfill('0')
         << lower_bound(ALL(G[H[i].x]), H[i].y) - G[H[i].x].begin() + 1 << endl;
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#pragma comment(linker, "/stck:1024000000,1024000000")
#define lowbit(x) (x & (-x))
#define max(x, y) (x >= y ? x : y)
#define min(x, y) (x <= y ? x : y)
// #define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.1415926535897932384626433832
#define ios() ios::sync_with_stdio(true)
#define INF (1 << 31) - 1;
#define mem(a) (memset(a, 0, sizeof(a)))
#define ALL(a) (a).begin(), (a).end()
struct P {
  int x, y;
} H[200000];
vector<int> G[100005];
int main() {
  set<int> s;
  int N, M;
  int x, y;
  cin >> N >> M;
  for (int i = 1; i <= M; i++) {
    cin >> x >> y;
    H[i].x = x;
    H[i].y = y;
    G[x].push_back(y);
    // s.insert(x);
  }
  for (int i = 1; i <= N; i++) {
    sort(G[i].begin(), G[i].end());
  }

  for (int i = 1; i <= M; i++) {
    cout << setw(6) << setfill('0') << H[i].x;
    cout << setw(6) << setfill('0')
         << lower_bound(ALL(G[H[i].x]), H[i].y) - G[H[i].x].begin() + 1 << endl;
  }
  return 0;
}
Problem p03221 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> yd(n + 1);
  vector<int> p(n);
  vector<int> y(n);

  for (int i = 0; i < m; i++) {
    cin >> p[i] >> y[i];
    yd[p[i]].push_back(y[i]);
  }
  for (int i = 0; i < n; i++) {
    sort(yd[i + 1].begin(), yd[i + 1].end());
  }

  for (int i = 0; i < m; i++) {
    int num =
        lower_bound(yd[p[i]].begin(), yd[p[i]].end(), y[i]) - yd[p[i]].begin();
    printf("%06d%06d\n", p[i], num + 1);
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> yd(n + 1);
  vector<int> p(m);
  vector<int> y(m);

  for (int i = 0; i < m; i++) {
    cin >> p[i] >> y[i];
    yd[p[i]].push_back(y[i]);
  }
  for (int i = 0; i < n; i++) {
    sort(yd[i + 1].begin(), yd[i + 1].end());
  }

  for (int i = 0; i < m; i++) {
    int num =
        lower_bound(yd[p[i]].begin(), yd[p[i]].end(), y[i]) - yd[p[i]].begin();
    printf("%06d%06d\n", p[i], num + 1);
  }
}
Problem p03221 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <vector>
using namespace std;

int main() {
  int N, M;
  cin >> N >> M;

  vector<int> P(M);
  vector<int> Y(M);
  map<int, vector<int>> PY;

  for (auto i = 0; i < M; i++) {
    cin >> P[i] >> Y[i];
    if (PY.find(P[i]) == PY.end()) {
      vector<int> tmp;
      PY[P[i]] = tmp;
    }
    PY[P[i]].push_back(Y[i]);
  }

  for (auto iter = PY.begin(); iter != PY.end(); iter++)
    sort(iter->second.begin(), iter->second.end());

  for (auto i = 0; i < M; i++) {
    cout << setw(6) << setfill('0') << P[i];
    cout << setw(6) << setfill('0')
         << find(PY[P[i]].begin(), PY[P[i]].end(), Y[i]) - PY[P[i]].begin() + 1
         << endl;
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <vector>
using namespace std;

int main() {
  int N, M;
  cin >> N >> M;

  vector<int> P(M);
  vector<int> Y(M);
  map<int, vector<int>> PY;

  for (auto i = 0; i < M; i++) {
    cin >> P[i] >> Y[i];
    if (PY.find(P[i]) == PY.end()) {
      vector<int> tmp;
      PY[P[i]] = tmp;
    }
    PY[P[i]].push_back(Y[i]);
  }

  for (auto iter = PY.begin(); iter != PY.end(); iter++)
    sort(iter->second.begin(), iter->second.end());

  for (auto i = 0; i < M; i++) {
    cout << setw(6) << setfill('0') << P[i];
    cout << setw(6) << setfill('0')
         << lower_bound(PY[P[i]].begin(), PY[P[i]].end(), Y[i]) -
                PY[P[i]].begin() + 1
         << endl;
  }

  return 0;
}
Problem p03221 (C++)

Buggy submission (status: Runtime Error):
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <string>
#include <vector>
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)

using namespace std;
using ll = long long;
typedef pair<ll, ll> p;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const long long mod = 1e9 + 7;
ll gcd(ll a, ll b);
ll lcm(ll a, ll b);

int main() {

  ll N, M;

  cin >> N >> M;

  vector<p> C, ans;
  vector<vector<ll>> H(N + 1);

  ll P, Y;

  rep(i, M) {
    cin >> P >> Y;
    C.emplace_back(P, Y);
    H[P].push_back(Y);
  }

  rep(i, M) { sort(H[i].begin(), H[i].end()); }

  rep(i, M) {
    P = C[i].first;
    Y = find(H[P].begin(), H[P].end(), C[i].second) - H[P].begin() + 1;
    ans.emplace_back(P, Y);
  }

  char fillSaved = cout.fill('0');

  rep(i, M) {
    cout << setw(6) << ans[i].first << setw(6) << ans[i].second << endl;
  }

  cout.fill(fillSaved);

  return 0;
}

ll gcd(ll a, ll b) {
  if (a % b == 0)
    return (b);
  else
    return (gcd(b, a % b));
}
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

Fixed submission:
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <string>
#include <vector>
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)

using namespace std;
using ll = long long;
typedef pair<ll, ll> p;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const long long mod = 1e9 + 7;
ll gcd(ll a, ll b);
ll lcm(ll a, ll b);

int main() {

  ll N, M;

  cin >> N >> M;

  vector<p> C, ans;
  vector<vector<ll>> H(N + 1);

  ll P, Y;

  rep(i, M) {
    cin >> P >> Y;
    C.emplace_back(P, Y);
    H[P].push_back(Y);
  }

  rep(i, N + 1) { sort(H[i].begin(), H[i].end()); }

  rep(i, M) {
    P = C[i].first;
    Y = find(H[P].begin(), H[P].end(), C[i].second) - H[P].begin() + 1;
    ans.emplace_back(P, Y);
  }

  char fillSaved = cout.fill('0');

  rep(i, M) {
    cout << setw(6) << ans[i].first << setw(6) << ans[i].second << endl;
  }

  cout.fill(fillSaved);

  return 0;
}

ll gcd(ll a, ll b) {
  if (a % b == 0)
    return (b);
  else
    return (gcd(b, a % b));
}
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
Problem p03221 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using ll = long long;
using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> p(n), y(n);
  for (int i = 0; i < m; i++)
    cin >> p[i] >> y[i];

  vector<vector<int>> cor(n + 1); // cor[p[i]] = 県p[i]に属する市の誕生年の配列
  for (int i = 0; i < m; i++)
    cor[p[i]].push_back(y[i]);
  for (int i = 1; i <= n; i++)
    sort(cor[i].begin(), cor[i].end());
  for (int i = 0; i < m; i++) {
    int num = lower_bound(cor[p[i]].begin(), cor[p[i]].end(), y[i]) -
              cor[p[i]].begin() + 1;
    printf("%06d%06d\n", p[i], num);
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using ll = long long;
using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> p(m), y(m);
  for (int i = 0; i < m; i++)
    cin >> p[i] >> y[i];

  vector<vector<int>> cor(n + 1); // cor[p[i]] = 県p[i]に属する市の誕生年の配列
  for (int i = 0; i < m; i++)
    cor[p[i]].push_back(y[i]);
  for (int i = 1; i <= n; i++)
    sort(cor[i].begin(), cor[i].end());
  for (int i = 0; i < m; i++) {
    int num = lower_bound(cor[p[i]].begin(), cor[p[i]].end(), y[i]) -
              cor[p[i]].begin() + 1;
    printf("%06d%06d\n", p[i], num);
  }
  return 0;
}
Problem p03221 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

string add0(int X) {
  string S = to_string(X);
  while (S.size() < 6) {
    S = '0' + S;
  }
  return S;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N, M;
  cin >> N >> M;
  vector<int> P(M), Y(M);
  vector<vector<int>> V(N);
  for (int i = 0; i < M; ++i) {
    cin >> P.at(i) >> Y.at(i);
    V.at(P.at(i) - 1).push_back(Y.at(i));
  }
  for (auto &A : V) {
    sort(A.begin(), A.end());
  }
  for (int i = 0; i < M; ++i) {
    auto A = V.at(P.at(i) - 1);
    int res = lower_bound(A.begin(), A.end(), Y.at(i)) - A.begin() + 1;
    cout << setfill('0') << right << setw(6) << P.at(i);
    cout << setfill('0') << right << setw(6) << res << endl;
  }

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

string add0(int X) {
  string S = to_string(X);
  while (S.size() < 6) {
    S = '0' + S;
  }
  return S;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N, M;
  cin >> N >> M;
  vector<int> P(M), Y(M);
  vector<vector<int>> V(N);
  for (int i = 0; i < M; ++i) {
    cin >> P.at(i) >> Y.at(i);
    V.at(P.at(i) - 1).push_back(Y.at(i));
  }
  for (auto &A : V) {
    sort(A.begin(), A.end());
  }
  for (int i = 0; i < M; ++i) {
    auto &A = V.at(P.at(i) - 1);
    int res = lower_bound(A.begin(), A.end(), Y.at(i)) - A.begin() + 1;
    cout << setfill('0') << right << setw(6) << P.at(i);
    cout << setfill('0') << right << setw(6) << res << endl;
  }

  return 0;
}
Problem p03221 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define RREP(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, k, n) for (int i = (k); i < (int)(n); i++)
#define all(i, n) (i), (i + n)

int dx4[4] = {1, 0, -1, 0};
int dy4[4] = {0, -1, 0, 1};
int dx8[8] = {1, 0, -1, 1, -1, 1, 0, -1};
int dy8[8] = {1, 1, 1, 0, 0, -1, -1, -1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6 + 1;
const ll mod = 1000000007;

// --------------------------------------
int n, m;
priority_queue<P, vector<P>, greater<P>> que;
vector<vector<int>> v;
vector<P> pv;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n >> m;
  v.reserve(n + 1);

  REP(i, m) {
    int a, b;
    cin >> a >> b;
    v[a].push_back(b);
    pv.push_back(make_pair(a, b));
  }

  FOR(i, 1, n + 1) {
    if (v[i].size() > 0) {
      sort(v[i].begin(), v[i].end());
    }
  }

  REP(i, m) {
    P p = pv[i];
    auto pp = find(v[p.first].begin(), v[p.first].end(), p.second);
    cout << setw(6) << setfill('0') << p.first;
    cout << setw(6) << setfill('0') << (pp - v[p.first].begin() + 1) << endl;
  }
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define RREP(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, k, n) for (int i = (k); i < (int)(n); i++)
#define all(i, n) (i), (i + n)

int dx4[4] = {1, 0, -1, 0};
int dy4[4] = {0, -1, 0, 1};
int dx8[8] = {1, 0, -1, 1, -1, 1, 0, -1};
int dy8[8] = {1, 1, 1, 0, 0, -1, -1, -1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6 + 1;
const ll mod = 1000000007;

// --------------------------------------
int n, m;
priority_queue<P, vector<P>, greater<P>> que;
vector<vector<int>> v;
vector<P> pv;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n >> m;
  v.reserve(n + 1);

  REP(i, m) {
    int a, b;
    cin >> a >> b;
    v[a].push_back(b);
    pv.push_back(make_pair(a, b));
  }

  FOR(i, 1, n + 1) {
    if (v[i].size() > 0) {
      sort(v[i].begin(), v[i].end());
    }
  }

  REP(i, m) {
    P p = pv[i];
    auto pp = lower_bound(v[p.first].begin(), v[p.first].end(), p.second);
    cout << setw(6) << setfill('0') << p.first;
    cout << setw(6) << setfill('0') << (pp - v[p.first].begin() + 1) << endl;
  }
}
Problem p03221 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

void solve() {
  int n, m;
  cin >> n >> m;
  unordered_map<int, vector<int>> mp;
  vector<pair<int, int>> a(m);
  for (int i = 0; i < m; i++) {
    int p, y;
    cin >> p >> y;
    mp[p].push_back(y);
    a[i].first = p;
    a[i].second = y;
  }
  for (auto t = mp.begin(); t != mp.end(); t++) {
    sort((*t).second.begin(), (*t).second.end());
  }
  for (int i = 0; i < m; i++) {
    int p = a[i].first;
    int y = a[i].second;
    string s = to_string(p);
    for (int j = 0; j < 6 - (int)s.size(); j++) {
      cout << 0;
    }
    cout << s;
    auto x = mp[p];
    int l = 0, r = x.size() - 1;
    string s2;
    while (l <= r) {
      int mid = l + (r - l);
      if (x[mid] == y) {
        s2 = to_string(mid + 1);
        break;
      } else if (x[mid] > y) {
        r = mid - 1;
      } else {
        l = mid + 1;
      }
    }
    for (int j = 0; j < 6 - (int)s2.size(); j++) {
      cout << 0;
    }
    cout << s2 << "\n";
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  solve();
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;

void solve() {
  int n, m;
  cin >> n >> m;
  unordered_map<int, vector<int>> mp;
  vector<pair<int, int>> a(m);
  for (int i = 0; i < m; i++) {
    int p, y;
    cin >> p >> y;
    mp[p].push_back(y);
    a[i].first = p;
    a[i].second = y;
  }
  for (auto t = mp.begin(); t != mp.end(); t++) {
    sort((*t).second.begin(), (*t).second.end());
  }
  for (int i = 0; i < m; i++) {
    int p = a[i].first;
    int y = a[i].second;
    printf("%06d", p);
    int l = lower_bound(mp[p].begin(), mp[p].end(), y) - mp[p].begin();
    printf("%06d\n", l + 1);
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  solve();
  return 0;
}
Problem p03221 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;

typedef int64_t ll;
const ll INF = 1000000000000000000;
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define vll vector<ll>
#define all(v) v.begin(), v.end()

int main() {

  ll N, M;
  cin >> N >> M;
  vll P(M), Y(M);
  rep(i, M) cin >> P[i] >> Y[i];

  map<ll, vll> pref;
  rep(i, M) pref[P[i]].push_back(Y[i]);
  for (auto &p : pref)
    sort(all(p.second));

  rep(i, M) {
    auto it = find(all(pref[P[i]]), Y[i]);
    cout << setw(6) << setfill('0') << P[i];
    cout << setw(6) << setfill('0') << (it - pref[P[i]].begin() + 1) << endl;
    ;
  }
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;

typedef int64_t ll;
const ll INF = 1000000000000000000;
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define vll vector<ll>
#define all(v) v.begin(), v.end()

int main() {

  ll N, M;
  cin >> N >> M;
  vll P(M), Y(M);
  rep(i, M) cin >> P[i] >> Y[i];

  map<ll, vll> pref;
  rep(i, M) pref[P[i]].push_back(Y[i]);
  for (auto &p : pref)
    sort(all(p.second));

  rep(i, M) {
    // auto it = find(all(pref[P[i]]), Y[i]);
    ll ok = pref[P[i]].size();
    ll ng = -1;
    while (abs(ok - ng) > 1) {
      ll mid = (ok + ng) / 2;
      if (pref[P[i]][mid] < Y[i])
        ng = mid;
      else if (pref[P[i]][mid] > Y[i])
        ok = mid;
      else {
        cout << setw(6) << setfill('0') << P[i];
        cout << setw(6) << setfill('0') << mid + 1 << endl;
        break;
      }
    }
  }
}
Problem p03221 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <list>
#include <stdio.h>
#include <utility>
#include <vector>

using namespace std;

struct City {
  int y;
  int p;
  int n;
};

int main() {
  vector<City> city;
  int N, M;

  cin >> N >> M;

  for (int i = 0; i < M; i++) {
    int p, y;
    City tmp;
    cin >> p >> y;
    tmp.y = y;
    tmp.p = p;
    tmp.n = i;
    city.push_back(tmp);
  }

  std::sort(city.begin(), city.end(),
            [](City a, City b) -> bool { return a.y < b.y; });

  int id;
  for (int p = 1; p <= N; p++) {
    id = 1;
    for (int i = 0; i < city.size(); i++) {
      if (city[i].p == p) {
        city[i].y = id;
        id++;
      }
    }
  }

  std::sort(city.begin(), city.end(),
            [](City a, City b) -> bool { return a.n < b.n; });

  for (int i = 0; i < city.size(); i++) {
    printf("%06d%06d\n", city[i].p, city[i].y);
  }
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <list>
#include <stdio.h>
#include <utility>
#include <vector>

using namespace std;

struct City {
  int y;
  int p;
  int n;
};

int main() {
  vector<City> city;
  int N, M;

  cin >> N >> M;

  for (int i = 0; i < M; i++) {
    int p, y;
    City tmp;
    cin >> p >> y;
    tmp.y = y;
    tmp.p = p;
    tmp.n = i;
    city.push_back(tmp);
  }

  std::sort(city.begin(), city.end(),
            [](City a, City b) -> bool { return a.y < b.y; });

  vector<int> id(N + 1, 1);
  for (int i = 0; i < city.size(); i++) {
    city[i].y = id[city[i].p];
    id[city[i].p]++;
  }

  std::sort(city.begin(), city.end(),
            [](City a, City b) -> bool { return a.n < b.n; });

  for (int i = 0; i < city.size(); i++) {
    printf("%06d%06d\n", city[i].p, city[i].y);
  }
}
Problem p03221 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <string>
using namespace std;
struct ci {
  int order;
  int p;
  int y;
  bool operator<(const ci &another) const {
    return y < another.y; // 年齢を比較
  };
  int id;
};
bool cmp(const ci &a, const ci &b) { return a.order < b.order; }
int main(void) {
  int N, M;
  struct ci c[1000];
  int c_num[1000];
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    cin >> c[i].p >> c[i].y;
    c[i].order = i;
  }
  for (int i = 0; i < N; i++)
    c_num[i] = 1;
  sort(c, c + M);
  for (int i = 0; i < M; i++) {
    c[i].id = c_num[c[i].p - 1];
    c_num[c[i].p - 1]++;
  }
  sort(c, c + M, cmp);
  for (int i = 0; i < M; i++) {
    printf("%06d%06d\n", c[i].p, c[i].id);
  }

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <string>
using namespace std;
struct ci {
  int order;
  int p;
  int y;
  bool operator<(const ci &another) const {
    return y < another.y; // 年齢を比較
  };
  int id;
};
bool cmp(const ci &a, const ci &b) { return a.order < b.order; }
int main(void) {
  int N, M;
  struct ci c[100000];
  int c_num[100000];
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    cin >> c[i].p >> c[i].y;
    c[i].order = i;
  }
  for (int i = 0; i < N; i++)
    c_num[i] = 1;
  sort(c, c + M);
  for (int i = 0; i < M; i++) {
    c[i].id = c_num[c[i].p - 1];
    c_num[c[i].p - 1]++;
  }
  sort(c, c + M, cmp);
  for (int i = 0; i < M; i++) {
    printf("%06d%06d\n", c[i].p, c[i].id);
  }

  return 0;
}
Problem p03221 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> v(n);
  vector<pair<int, int>> per(n);
  rep(i, m) {
    int x, y;
    cin >> x >> y;
    x--;
    v[x].push_back(y);
    per[i] = {x + 1, y};
  }
  rep(i, n) {
    if (v[i].size() == 0)
      continue;
    sort(v[i].begin(), v[i].end());
  }
  rep(i, m) {
    int x, y;
    x = per[i].first;
    y = per[i].second;
    printf("%06d", x);
    printf("%06d\n", int(lower_bound(v[x - 1].begin(), v[x - 1].end(), y) -
                         v[x - 1].begin()) +
                         1);
  }
  // printf("%06d",100000);

  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> v(n);
  vector<pair<int, int>> per(m);
  rep(i, m) {
    int x, y;
    cin >> x >> y;
    x--;
    v[x].push_back(y);
    per[i] = {x + 1, y};
  }
  rep(i, n) {
    if (v[i].size() == 0)
      continue;
    sort(v[i].begin(), v[i].end());
  }
  rep(i, m) {
    int x, y;
    x = per[i].first;
    y = per[i].second;
    printf("%06d", x);
    printf("%06d\n", int(lower_bound(v[x - 1].begin(), v[x - 1].end(), y) -
                         v[x - 1].begin()) +
                         1);
  }
  // printf("%06d",100000);

  return 0;
}
Problem p03221 (C++)

Buggy submission (status: Runtime Error):
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair

using ll = long long;
using namespace std;

void solve() {
  int n, m;
  cin >> n >> m;
  vector<int> pre[10000];
  int p[10000], y[10000];
  for (int i = 0; i < m; i++)
    cin >> p[i] >> y[i], pre[p[i]].push_back(y[i]);
  for (int i = 0; i < n; i++)
    sort(pre[i + 1].begin(), pre[i + 1].end());
  for (int i = 0; i < m; i++) {
    ll final = (ll)p[i] * 1000000 +
               ll(lower_bound(pre[p[i]].begin(), pre[p[i]].end(), y[i]) -
                  pre[p[i]].begin()) +
               1;
    printf("%012lld\n", final);
  }
}

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(NULL);
  int test;
  test = 1;
  while (test--) {
    solve();
  }
  return 0;
}

Fixed submission:
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair

using ll = long long;
using namespace std;

void solve() {
  int n, m;
  cin >> n >> m;
  vector<int> pre[100001];
  int p[100000], y[100000];
  for (int i = 0; i < m; i++)
    cin >> p[i] >> y[i], pre[p[i]].push_back(y[i]);
  for (int i = 0; i < n; i++)
    sort(pre[i + 1].begin(), pre[i + 1].end());
  for (int i = 0; i < m; i++) {
    ll final = (ll)p[i] * 1000000 +
               ll(lower_bound(pre[p[i]].begin(), pre[p[i]].end(), y[i]) -
                  pre[p[i]].begin()) +
               1;
    printf("%012lld\n", final);
  }
}

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(NULL);
  int test;
  test = 1;
  while (test--) {
    solve();
  }
  return 0;
}