alexjercan/bugnet huggingface dataset:
Problem p00946 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
bool b[229028];
int n, m;
vector<int> l;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    b[i] = false;
  for (int i = 0; i < m; i++) {
    int a;
    cin >> a;
    l.push_back(a);
  }
  for (int i = 1; i <= m; i++) {
    if (!b[l[m - i]])
      cout << l[m - i] << endl;
    b[l[m - i]] = true;
  }
  for (int i = 1; i <= n; i++)
    if (!b[i])
      cout << i << endl;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
bool b[114514];
int n, m;
vector<int> l;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    b[i] = false;
  for (int i = 0; i < m; i++) {
    int a;
    cin >> a;
    l.push_back(a);
  }
  for (int i = 1; i <= m; i++) {
    if (!b[l[m - i]])
      cout << l[m - i] << endl;
    b[l[m - i]] = true;
  }
  for (int i = 1; i <= n; i++)
    if (!b[i])
      cout << i << endl;
}
Problem p00947 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;

int main() {

  int d[100000];

  int dd[10][10];
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> dd[i][j];
    }
    d[i] = dd[0][i];
  }

  for (int i = 10; i < 100000; i++) {
    int a = i / 10;
    int b = i % 10;
    d[i] = dd[d[a]][b];
  }
  /*
  for (int i = 0; i < 100000; i++) {
          if (d[i] < 0 || 9 < d[i]) {
                  cout << i << ' ' << d[i] << endl;
          }
  }
  */
  int ans = 0;
  // cout << 'a' << endl;
  for (int i = 0; i < 10000; i++) {
    // cout << i << endl;
    int cos = 0;
    int kari = i * 10 + d[i];
    vector<int> p(5);
    p[0] = kari / 10000;
    kari %= 10000;
    p[1] = kari / 1000;
    kari %= 1000;
    p[2] = kari / 100;
    kari %= 100;
    p[3] = kari / 10;
    kari %= 10;
    p[4] = kari;

    kari = i * 10 + d[i];

    for (int j = 0; j < 5; j++) {
      vector<int> q(5);
      q = p;
      for (int k = 0; k < 10; k++) {
        q[j] = k;
        int n = 0;
        for (int l = 0; l < 5; l++) {
          n *= 10;
          n += q[l];
        }
        if (d[n] == 0 && n != kari) {
          cos++;
        }
      }
    }

    for (int j = 0; j < 4; j++) {
      vector<int> q(5);
      q = p;
      swap(q[j], q[j + 1]);
      int n = 0;
      for (int k = 0; k < 5; k++) {
        n *= 10;
        n += q[k];
      }
      if (d[n] == 0 && n != kari) {
        cos++;
      }
    }
    if (cos > 0) {
      ans++;
      // cout << i << endl;
    }
  }

  cout << ans << endl;
  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;

int main() {

  int d[100000];

  int dd[10][10];
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> dd[i][j];
    }
  }

  for (int i = 0; i < 100000; i++) {
    int a = i / 10;
    int b = i % 10;
    d[i] = dd[a][b];
  }
  int ans = 0;
  for (int i = 0; i < 100000; i++) {
    int cos = 0;
    int kari = i;
    vector<int> p(5);
    p[0] = i / 10000;
    kari %= 10000;
    p[1] = i / 1000;
    kari %= 1000;
    p[2] = i / 100;
    kari %= 100;
    p[3] = i / 10;
    kari %= 10;
    p[4] = kari;
    for (int j = 0; j < 5; j++) {
      vector<int> q(5);
      q = p;
      for (int k = 0; k < 10; k++) {
        q[j] = k;
        int n = 0;
        for (int l = 0; l < 5; l++) {
          n *= 10;
          n += q[l];
        }
        if (d[n] == 0) {
          cos++;
        }
      }
    }
    for (int j = 0; j < 4; j++) {
      vector<int> q(5);
      q = p;
      swap(q[j], q[j + 1]);
      int n = 0;
      for (int k = 0; k < 5; k++) {
        n *= 10;
        n += q[k];
      }
      if (d[n] == 0) {
        cos++;
      }
    }
    if (cos > 5) {
      ans++;
    }
  }

  cout << ans << endl;
  return 0;
}
Problem p00947 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>

using namespace std;

int number[10];
int table[15][15];

bool check(int x) {
  for (int i = 4; i >= 1; --i)
    number[i] = x % 10, x /= 10;

  number[5] = 0; // check number

  for (int i = 1; i <= 4; ++i)
    number[5] = table[number[5]][number[i]];

  /*
  cout << "number" << endl;
  for (int i = 1; i <= 5; ++i)
          cout << number[i] << " ";
  cout << endl;
  */

  //	error1

  for (int i = 1; i <= 5; ++i)
    for (int j = 0; j < 10; ++j)
      if (j != number[i]) {
        int tmp = 0;

        for (int k = 1; k <= 5; ++k) {
          if (k == i)
            tmp = table[tmp][j];
          else
            tmp = table[tmp][number[k]];
        }

        if (!tmp)
          return true;
      }

  //	error2

  for (int i = 1, j = 2; i <= 4; ++i, ++j)
    if (number[i] != number[j]) {
      int tmp = 0;

      for (int k = 1; k <= 5; ++k) {
        if (k == i)
          tmp = table[tmp][number[j]];
        else if (k == j)
          tmp = table[tmp][number[i]];
        else
          tmp = table[tmp][number[k]];
      }

      if (!tmp)
        return true;
    }

  return false;
}

signed main(void) {
  for (int i = 0; i < 10; ++i)
    for (int j = 0; j < 10; ++j)
      cin >> table[i][j];

  int answer = 0;

  for (int i = 0; i < 10000; ++i)
    if (check(i))
      ++answer;

  cout << answer << endl;
}

Error: 0
sh: 1: pause: not found


Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>

using namespace std;

int number[10];
int table[15][15];

bool check(int x) {
  for (int i = 4; i >= 1; --i)
    number[i] = x % 10, x /= 10;

  number[5] = 0; // check number

  for (int i = 1; i <= 4; ++i)
    number[5] = table[number[5]][number[i]];

  /*
  cout << "number" << endl;
  for (int i = 1; i <= 5; ++i)
          cout << number[i] << " ";
  cout << endl;
  */

  //	error1

  for (int i = 1; i <= 4; ++i)
    for (int j = 0; j < 10; ++j)
      if (j != number[i]) {
        int tmp = 0;

        for (int k = 1; k <= 5; ++k) {
          if (k == i)
            tmp = table[tmp][j];
          else
            tmp = table[tmp][number[k]];
        }

        if (!tmp)
          return true;
      }

  //	error2

  for (int i = 1, j = 2; i <= 4; ++i, ++j)
    if (number[i] != number[j]) {
      int tmp = 0;

      for (int k = 1; k <= 5; ++k) {
        if (k == i)
          tmp = table[tmp][number[j]];
        else if (k == j)
          tmp = table[tmp][number[i]];
        else
          tmp = table[tmp][number[k]];
      }

      if (!tmp)
        return true;
    }

  return false;
}

signed main(void) {
  for (int i = 0; i < 10; ++i)
    for (int j = 0; j < 10; ++j)
      cin >> table[i][j];

  int answer = 0;

  for (int i = 0; i < 10000; ++i)
    if (check(i))
      ++answer;

  cout << answer << endl;

  system("pause");
}
Problem p00948 (C++) — buggy submission, verdict: Time Limit Exceeded

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

const int MAXN = 200000 + 10;
int sta[MAXN], end[MAXN];

struct Arm {
  int x;
  int Num;
} arm[MAXN];

bool cmp(const Arm a1, const Arm a2) { return a1.x <= a2.x; }

int main() {
  int N, M;
  scanf("%d%d", &N, &M);
  int x, d;
  for (int i = 1; i <= N; i++)
    sta[i] = end[i] = i;
  for (int i = 1; i <= M; i++) {
    scanf("%d%d", &x, &d);
    arm[i].x = x;
    arm[i].Num = d;
  }
  sort(arm + 1, arm + 1 + M, cmp);
  for (int i = 1; i <= M; i++) {
    d = arm[i].Num;
    sta[d + 1] = sta[d] = min(sta[d + 1], sta[d]);
    end[d + 1] = end[d] = max(end[d + 1], end[d]);
  }
  for (int i = 1; i <= N; i++) {
    printf("%d", end[i] - sta[i] + 1);
    if (i != N)
      printf(" ");
  }
  printf("\\n");
  return 0;
}

Error: TLE

Fixed submission:

/*#include<bits/stdc++.h>
using namespace std;
struct apair {
        int x, y;
}p[100009];
bool cmp(const apair &a, const apair &b) {
        return a.x < b.x;
}
int main()
{
        int n, m; scanf("%d%d", &n, &m);
        for (int i = 0; i < m; i++)scanf("%d%d", &p[i].x, p[i].y);
        sort(p, p + m, cmp);
}
*/
#include <bits/stdc++.h>
using namespace std;
int up;
vector<int> pos[200009];
int l, r;
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  int t1, t2;
  int flag = true;
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &t1, &t2);
    pos[t2].push_back(t1);
  }
  for (int i = 0; i < 200000; i++) {
    if (pos[i].size() > 1)
      sort(pos[i].begin(), pos[i].end());
  }
  for (int i = 0; i < n; i++) {
    if (i > 1 && pos[i - 1].size() && pos[i].size() &&
        pos[i - 1][pos[i - 1].size() - 1] < pos[i][pos[i].size() - 1])
      ;
    else if (i) {
      l = i;
      if (pos[i].size()) {
        int k = i;
        up = 2000000;
        while (pos[k].size() && k > 0 && pos[k][0] < up) {
          int t = pos[k].size();
          while (t > 0 && pos[k][t - 1] > up)
            t--;
          up = pos[k][t - 1];
          k--;
          l--;
        }
      }
    }
    if (i < n) {
      r = i;
      if (pos[i + 1].size()) {
        int k = i + 1;
        up = 2000000;
        while (pos[k].size() && k < n && pos[k][0] < up) {
          int t = pos[k].size();
          while (t > 0 && pos[k][t - 1] > up)
            t--;
          up = pos[k][t - 1];
          k++;
          r++;
        }
      }
    }
    if (!flag)
      printf(" ");
    else
      flag = false;
    printf("%d", r - l + 1);
  }
  printf("\\n");
}
Problem p00948 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <cstdio>
#include <utility>

using namespace std;

int n, m;
pair<int, int> arm[200005];
int accept[200005][3]; // higher, self, lower
bitset<200005> trans;

int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i)
    accept[i][1] = 1;
  for (int i = 0; i != m; ++i)
    scanf("%d%d", &arm[i].first, &arm[i].second);
  sort(arm, arm + m);
  for (int i = 0; i != m; ++i) {
    int l = arm[i].second, h = l + 1;
    if (!trans.test(l)) {
      accept[l][2] = accept[h][1];
      accept[h][0] = accept[l][1];
      trans.set(l);
    }
    accept[l][2] += accept[h][2];
    accept[h][1] += accept[h][2];
    accept[h][2] = 0;
    accept[h][0] += accept[l][0];
    accept[l][1] += accept[l][0];
    accept[l][0] = 0;
  }
  for (int i = 1; i != n; ++i)
    printf("%d ", accept[i][0] + accept[i][1] + accept[i][2]);
  printf("%d\\n", accept[n][0] + accept[n][1] + accept[n][2]);
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cstdio>
#include <utility>

using namespace std;

int n, m;
pair<int, int> arm[200005];
int accept[100005][3]; // higher, self, lower
bitset<100005> trans;

int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i)
    accept[i][1] = 1;
  for (int i = 0; i != m; ++i)
    scanf("%d%d", &arm[i].first, &arm[i].second);
  sort(arm, arm + m);
  for (int i = 0; i != m; ++i) {
    int l = arm[i].second, h = l + 1;
    if (!trans.test(l)) {
      int mix = accept[l][1] + accept[h][1];
      accept[l][2] = accept[h][1];
      accept[h][0] = accept[l][1];
      trans.set(l);
    }
    accept[l][2] += accept[h][2];
    accept[h][1] += accept[h][2];
    accept[h][2] = 0;
    accept[h][0] += accept[l][0];
    accept[l][1] += accept[l][0];
    accept[l][0] = 0;
  }
  for (int i = 1; i != n; ++i)
    printf("%d ", accept[i][0] + accept[i][1] + accept[i][2]);
  printf("%d\\n", accept[n][0] + accept[n][1] + accept[n][2]);
  return 0;
}
Problem p00948 (C++) — buggy submission, verdict: Runtime Error

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

int n, m;
pair<int, int> p[100010];
int a[200010];
int b[200010];

int cmp(pair<int, int> q, pair<int, int> w) { return q < w; }

int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 1; i <= m; i++)
    cin >> p[i].first >> p[i].second;
  sort(p + 1, p + m + 1, cmp);
  for (int i = 1; i <= n; i++)
    a[i] = b[i] = i;
  for (int i = 1; i <= m; i++) {
    a[p[i].second] = min(a[p[i].second], a[p[i].second + 1]);
    a[p[i].second + 1] = min(a[p[i].second], a[p[i].second + 1]);

    b[p[i].second] = max(b[p[i].second], b[p[i].second + 1]);
    b[p[i].second + 1] = max(b[p[i].second + 1], b[p[i].second]);
  }
  cout << b[1] - a[1] + 1;
  for (int i = 2; i <= n; i++)
    cout << " " << b[i] - a[i] + 1;
  cout << endl;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <set>
#include <stdio.h>
using namespace std;
struct node {
  int x, y;
} rob[100007];
set<int> s[100007];
set<int> uni;
bool cmp(const node a, const node b) { return a.x < b.x; }
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++)
    scanf("%d %d", &rob[i].x, &rob[i].y);
  sort(rob, rob + m, cmp);
  for (int i = 1; i <= n; i++)
    s[i].insert(i);
  for (int i = 0; i < m; i++) {
    set_union(s[rob[i].y].begin(), s[rob[i].y].end(), s[rob[i].y + 1].begin(),
              s[rob[i].y + 1].end(), inserter(uni, uni.begin()));
    s[rob[i].y] = uni;
    s[rob[i].y + 1] = uni;
    uni.clear();
  }
  for (int i = 1; i <= n; i++) {
    printf("%d%c", s[i].size(), (i == n) ? '\\n' : ' ');
  }
  return 0;
}
Problem p00948 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define ll long long
#define MAX 2147483647
#define fi first
#define se second
#define mid (l + r >> 1)
#define fo(i, a, b) for (int i = (a); i <= (b); ++i)
#define fodown(i, a, b) for (int i = (a); i >= (b); i--)
using namespace std;
int n, m;
pair<int, int> num[200001];
struct node {
  int x, y;
} a[100001];
int read() {
  int x = 0, tmp = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      tmp = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * tmp;
}
int cmp(node a, node b) { return a.x < b.x; }
int main() {
  // freopen(" .in","r",stdin);
  // freopen(" .out","w",stdout);
  n = read();
  m = read();
  fo(i, 1, m) {
    a[i].x = read();
    a[i].y = read();
  }
  sort(a + 1, a + m + 1, cmp);
  fo(i, 1, n) num[i].fi = i, num[i].se = i;
  int y;
  for (int i = 1; i <= m; i++) {
    y = a[i].y;
    num[y].fi = num[y + 1].fi = min(num[y].fi, num[y + 1].fi);
    num[y].se = num[y + 1].se = max(num[y].se, num[y + 1].se);
  }
  fo(i, 1, n - 1) { printf("%d ", num[i].se - num[i].fi + 1); }
  cout << num[n].se - num[n].fi + 1 << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
#define N 100005
int f[N][3], num[N];
struct xx {
  int x, y;

} x[N];
bool cmp(const xx &a, const xx &b) { return a.x < b.x; }
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;

  for (int i = 1; i <= m; ++i) {
    scanf("%d%d", &x[i].x, &x[i].y);
    // cout<<x[i].y;
  }
  sort(x + 1, x + m + 1, cmp);
  for (int i = 1; i <= n; ++i)
    f[i][0] = f[i][1] = i;
  for (int i = 1; i <= m; ++i) {
    int y1 = x[i].y;
    int y2 = y1 + 1;
    int r = max(f[y2][1], f[y1][1]);
    int l = min(f[y2][0], f[y1][0]);

    f[y2][0] = f[y1][0] = l;
    f[y2][1] = f[y1][1] = r;
    // cout<<y1<<endl;
    //	cout<<num[y1];
  }
  for (int i = 1; i <= n; ++i) {
    printf("%d", f[i][1] - f[i][0] + 1);
    if (i != n)
      printf(" ");
  }
  printf("\\n");
}
Problem p00948 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;

const int N = 200010, M = 100010;
int n, m;
int ff[N], have[N];

struct edges {
  int x, y;
} e[M];

int cmp(edges a, edges b) { return a.x < b.x; }

int main() {
  scanf("%d%d", &n, &m);
  int x, y;
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d", &x, &y);
    e[i] = (edges){x, y};
  }
  sort(e + 1, e + m + 1, cmp);
  for (int i = 1; i <= n; ++i)
    have[i] = 1;
  for (int i = 1; i <= m; ++i) {
    y = e[i].y;
    have[y] = have[y + 1] = have[y] + have[y + 1] - ff[y];
    ff[y] = have[y];
  }
  printf("%d", have[1]);
  for (int i = 2; i <= n; ++i) {
    printf(" %d", have[i]);
  }
  printf("\\n");
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;

const int N = 200000 + 10, M = 100010;
int n, m, mi;
int from_up[N], from_down[N];
int f[N];
bool vis[M << 1];

struct node {
  int next, to, x;
} nd[M << 1];

void add(int x, int u, int v) {
  nd[++mi] = (node){f[u], v, x};
  f[u] = mi;
}

void go(int from, int u, int x) {
  for (int p = f[u]; p; p = nd[p].next) {
    if (nd[p].x <= x)
      continue;
    if (vis[p])
      continue;
    vis[p] = true;
    int v = nd[p].to;
    go(from, v, nd[p].x);
  }
  from_up[u] = min(from_up[u], from);
  from_down[u] = max(from_down[u], from);
}

int main() {
  scanf("%d%d", &n, &m);
  mi = 0;
  int x, y;
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d", &x, &y);
    add(x, y, y + 1);
    add(x, y + 1, y);
  }
  memset(from_up, 1000000, sizeof(from_up));
  memset(from_down, -1, sizeof(from_down));
  for (int i = 1; i <= n; ++i) {
    memset(vis, false, sizeof(vis));
    go(i, i, 0);
  }
  printf("%d", from_down[1] - from_up[1] + 1);
  for (int i = 2; i <= n; ++i) {
    printf(" %d", from_down[i] - from_up[i] + 1);
  }
  printf("\\n");
  return 0;
}
Problem p00948 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

int main() {
  long long int n, m;
  cin >> n >> m;
  vector<set<int>> VSI(n);
  vector<int> imosmax(n), imosmin(n);
  for (int i = 0; i < n; i++) {
    VSI[i].insert(i);
    imosmax[i] = 1;
    imosmin[i] = 1;
  }
  vector<pair<long long int, long long int>> xy(m);
  for (int i = 0; i < m; i++) {
    cin >> xy[i].first >> xy[i].second;
  }
  sort(xy.begin(), xy.end());
  for (int i = 0; i < m; i++) {
    int y = xy[i].second;
    imosmax[y] += imosmax[y - 1];
    imosmax[y - 1] = 0;
    imosmin[y - 1] += imosmin[y];
    imosmin[y] = 0;
  }
  vector<int> imos(n + 1);

  for (int i = 0; i < n; i++) {
    imos[i] += imosmin[i];
    imos[i + 1] += imos[i];
    imos[i + 1] -= imosmax[i];
    cout << imos[i] << (i == n - 1 ? "\\n" : " ");
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {
  long long int n, m;
  cin >> n >> m;
  vector<set<int>> VSI(n);
  for (int i = 0; i < n; i++) {
    VSI[i].insert(i);
  }
  vector<pair<long long int, long long int>> xy(m);
  for (int i = 0; i < m; i++) {
    cin >> xy[i].first >> xy[i].second;
  }
  sort(xy.begin(), xy.end());
  for (int i = 0; i < m; i++) {
    if (VSI[xy[i].second].size() > VSI[xy[i].second - 1].size()) {
      for (auto x : VSI[xy[i].second - 1]) {
        VSI[xy[i].second].emplace(x);
      }
      // VSI[xy[i].second].emplace(VSI[xy[i].second-1].begin(),
      // VSI[xy[i].second-1].end());
      VSI[xy[i].second - 1] = VSI[xy[i].second];
    } else {
      for (auto x : VSI[xy[i].second]) {
        VSI[xy[i].second - 1].emplace(x);
      }
      // VSI[xy[i].second-1].emplace(VSI[xy[i].second].begin(),
      // VSI[xy[i].second].end());
      VSI[xy[i].second] = VSI[xy[i].second - 1];
    }
  }
  for (int i = 0; i < n; i++) {
    cout << VSI[i].size() << (i == n - 1 ? "\\n" : " ");
  }
}
Problem p00948 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#define dump(val) cerr << __LINE__ << ":\\t" << #val << " = " << (val) << endl

using namespace std;

typedef long long int lli;
typedef pair<int, int> pii;

int main() {
  int n, m;
  cin >> n >> m;
  vector<pii> v(n);
  REP(i, 0, n) v[i].first = v[i].second = i;
  vector<pii> p(m);
  REP(i, 0, m) { cin >> p[i].first >> p[i].second; }
  sort(begin(p), end(p));
  REP(i, 0, m) {
    int y = p[i].second - 1;
    v[y + 1].first = v[y].first;
    v[y].second = v[y + 1].second;
  }
  REP(i, 0, n) { cout << v[i].second - v[i].first + 1 << " \\n"[i == n - 1]; }
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <functional>
#include <iostream>
#include <string>
#include <utility>
#include <vector>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#define dump(val) cerr << __LINE__ << ":\\t" << #val << " = " << (val) << endl

using namespace std;

typedef long long int lli;
typedef pair<int, int> pii;

int main() {
  int n, m;
  cin >> n >> m;
  vector<pii> v(n);
  REP(i, 0, n) v[i].first = v[i].second = i;
  vector<pii> p(m);
  REP(i, 0, m) { cin >> p[i].first >> p[i].second; }
  sort(begin(p), end(p), greater<pii>());
  REP(i, 0, m) {
    REP(j, 0, n) {
      int x = p[i].second - 1;
      int y = x + 1;
      if (v[j].first == y)
        v[j].first--;
      if (v[j].second == x)
        v[j].second++;
    }
  }
  REP(i, 0, n) { cout << v[i].second - v[i].first + 1 << " \\n"[i == n - 1]; }
  return 0;
}
Problem p00948 (C++) — buggy submission, verdict: Runtime Error

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

typedef pair<int, int> P;

P merge(P a, P b) {
  int left = min(a.first, b.first);
  int right = max(a.second, b.second);
  return P(left, right);
}

int n, m;

vector<int> G[200005];

P ans[200005];

int main() {
  scanf("%d %d", &n, &m);

  for (int i = 0; i < m; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    G[x].push_back(y);
  }

  for (int i = 0; i < n; i++) {
    ans[i] = P(i, i);
  }

  for (int x = 0; x < 100005; x++) {
    for (int i = 0; i < (int)G[x].size(); i++) {
      int y = G[x][i];
      ans[y] = ans[y - 1] = merge(ans[y], ans[y - 1]);
    }
  }

  for (int i = 0; i < n; i++) {
    if (i)
      printf(" ");
    printf("%d", ans[i].second - ans[i].first + 1);
  }
  printf("\\n");
  return 0;
}

Error: 0

Fixed submission:

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

typedef pair<int, int> P;

P merge(P a, P b) {
  int left = min(a.first, b.first);
  int right = max(a.second, b.second);
  return P(left, right);
}

int n, m;

vector<int> G[100005];

P ans[100005];

int main() {
  scanf("%d %d", &n, &m);

  for (int i = 0; i < m; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    G[x].push_back(y);
  }

  for (int i = 0; i < n; i++) {
    ans[i] = P(i, i);
  }

  for (int x = 0; x < 100005; x++) {
    for (int i = 0; i < (int)G[x].size(); i++) {
      int y = G[x][i];
      ans[y] = ans[y - 1] = merge(ans[y], ans[y - 1]);
    }
  }

  for (int i = 0; i < n; i++) {
    if (i)
      printf(" ");
    printf("%d", ans[i].second - ans[i].first + 1);
  }
  printf("\\n");
  return 0;
}
Problem p00948 (C++) — buggy submission, verdict: Time Limit Exceeded

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

typedef pair<int, int> P;

int main() {
  int N, M;
  cin >> N >> M;
  vector<P> arm(M);
  for (int i = 0; i < M; i++) {
    cin >> arm[i].first >> arm[i].second;
  }
  sort(arm.begin(), arm.end());

  vector<int> s1(N), s2(N);
  for (int i = 0; i < N; i++)
    s1[i] = 1, s2[i] = 1;

  for (int i = 0; i < M; i++) {
    int y = arm[i].second;

    s1[y - 1] += s1[y];
    s1[y] = 0;
    s2[y] += s2[y - 1];
    s2[y - 1] = 0;
  }

  vector<int> sum(N + 1);
  for (int i = 0; i < N; i++) {
    sum[i] += s1[i];
    sum[i + 1] -= s2[i];
  }

  for (int i = 0; i < N - 1; i++) {
    cout << sum[i] << " ";
    sum[i + 1] += sum[i];
  }
  cout << sum[N - 1] << endl;

  return 0;
}

Error: TLE

Fixed submission:

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

typedef pair<int, int> P;

int main() {
  int N, M;
  cin >> N >> M;
  vector<P> arm(M);
  for (int i = 0; i < M; i++) {
    cin >> arm[i].first >> arm[i].second;
  }
  sort(arm.begin(), arm.end());

  vector<set<int>> s1(N), s2(N);
  for (int i = 0; i < N; i++)
    s1[i].insert(i), s2[i].insert(i);

  for (int i = 0; i < M; i++) {
    int y = arm[i].second;

    s1[y - 1].insert(s1[y].begin(), s1[y].end());
    s1[y].clear();
    s2[y].insert(s2[y - 1].begin(), s2[y - 1].end());
    s2[y - 1].clear();
  }

  vector<int> sum(N + 1);
  for (int i = 0; i < N; i++) {
    sum[i] += s1[i].size();
    sum[i + 1] -= s2[i].size();
  }

  for (int i = 0; i < N - 1; i++) {
    cout << sum[i] << " ";
    sum[i + 1] += sum[i];
  }
  cout << sum[N - 1] << endl;

  return 0;
}