alexjercan/bugnet huggingface dataset:
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#define int long long
using namespace std;
const int INF = 3e5 + 5;
struct _node_data {
  int x, y;
} aa[INF], bb[INF];
int h, w, m, cntx[INF], cnty[INF], ans;
map<int, map<int, bool>> Map;
bool cmp1(_node_data xx, _node_data yy) { return xx.x > yy.x; }
int fzx_max(int x, int y) { return x < y ? y : x; }
signed main() {
  scanf("%lld %lld %lld", &h, &w, &m);
  for (int i = 1; i <= m; i++) {
    int x = 0, y = 0;
    scanf("%lld %lld", &x, &y);
    Map[x][y] = 1;
    cntx[x]++;
    cnty[y]++;
  }
  for (int i = 1; i <= h; i++) {
    aa[i].x = cntx[i];
    aa[i].y = i;
  }
  for (int i = 1; i <= w; i++) {
    bb[i].x = cnty[i];
    bb[i].y = i;
  }
  sort(aa + 1, aa + 1 + h, cmp1);
  sort(bb + 1, bb + 1 + w, cmp1);
  for (int i = 1; i <= h; i++) {
    bool flag = true;
    for (int j = 1; j <= w; j++) {
      if (aa[i].x + bb[j].x <= ans)
        break;
      flag = false;
      ans = fzx_max(ans, aa[i].x + bb[j].x - Map[aa[i].y][bb[j].y]);
    }
    if (flag)
      break;
  }
  cout << ans << "\\n";
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#define int long long
using namespace std;
const int INF = 3e5 + 5;
struct _node_data {
  int x, y;
} aa[INF], bb[INF];
int h, w, m, cntx[INF], cnty[INF], ans;
map<int, map<int, bool>> Map;
bool cmp1(_node_data xx, _node_data yy) { return xx.x > yy.x; }
int fzx_max(int x, int y) { return x < y ? y : x; }
signed main() {
  scanf("%lld %lld %lld", &h, &w, &m);
  for (int i = 1; i <= m; i++) {
    int x = 0, y = 0;
    scanf("%lld %lld", &x, &y);
    Map[x][y] = 1;
    cntx[x]++;
    cnty[y]++;
  }
  for (int i = 1; i <= h; i++) {
    aa[i].x = cntx[i];
    aa[i].y = i;
  }
  for (int i = 1; i <= w; i++) {
    bb[i].x = cnty[i];
    bb[i].y = i;
  }
  sort(aa + 1, aa + 1 + h, cmp1);
  sort(bb + 1, bb + 1 + w, cmp1);
  for (int i = 1; i <= h; i++)
    for (int j = 1; j <= w; j++) {
      // if (aa[i].x+bb[j].x<=ans) break;
      ans = fzx_max(ans, aa[i].x + bb[j].x - Map[aa[i].y][bb[j].y]);
    }
  cout << ans << "\\n";
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

int cnty[300001];
int cntx[300001];

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

  int h, w, m, y, x;
  set<pair<int, int>> p;
  cin >> h >> w >> m;

  for (int i = 0; i < m; i++) {
    cin >> y >> x;
    p.insert(make_pair(y, x));
    cnty[y]++;
    cntx[x]++;
  }

  vector<int> sy, sx;
  int Maxy = 0;
  int Maxx = 0;

  for (int i = 1; i <= h; i++) {
    Maxy = max(Maxy, cnty[i]);
  }
  for (int i = 1; i <= w; i++) {
    Maxx = max(Maxx, cntx[i]);
  }

  for (int i = 1; i <= h; i++) {
    if (Maxy == cnty[i]) {
      sy.push_back(i);
    }
  }
  for (int i = 1; i <= w; i++) {
    if (Maxx == cntx[i]) {
      sx.push_back(i);
    }
  }

  int res = 0;

  for (int i = 0; i < min(10, (int)(sy.size())); i++) {
    int y = sy[i];
    for (auto x : sx) {
      int num = cnty[y] + cntx[x];
      if (p.find(make_pair(y, x)) != p.end()) {
        num -= 1;
      }
      res = max(res, num);
    }
  }

  for (int i = 0; i < min(10, (int)(sx.size())); i++) {
    int x = sx[i];
    for (auto y : sy) {
      int num = cnty[y] + cntx[x];
      if (p.find(make_pair(y, x)) != p.end()) {
        num -= 1;
      }
      res = max(res, num);
    }
  }

  cout << res << '\\n';

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int cnty[300001];
int cntx[300001];

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

  int h, w, m, y, x;
  set<pair<int, int>> p;
  cin >> h >> w >> m;

  for (int i = 0; i < m; i++) {
    cin >> y >> x;
    p.insert(make_pair(y, x));
    cnty[y]++;
    cntx[x]++;
  }

  vector<int> sy, sx;
  int Maxy = 0;
  int Maxx = 0;

  for (int i = 1; i <= h; i++) {
    Maxy = max(Maxy, cnty[i]);
  }
  for (int i = 1; i <= w; i++) {
    Maxx = max(Maxx, cntx[i]);
  }

  for (int i = 1; i <= h; i++) {
    if (Maxy == cnty[i]) {
      sy.push_back(i);
    }
  }
  for (int i = 1; i <= w; i++) {
    if (Maxx == cntx[i]) {
      sx.push_back(i);
    }
  }

  int res = 0;

  for (auto y : sy) {
    for (auto x : sx) {
      int num = cnty[y] + cntx[x];
      if (p.find(make_pair(y, x)) != p.end()) {
        num -= 1;
      }
      res = max(res, num);
    }
  }

  cout << res << '\\n';

  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define ff first
#define ss second
#define pb push_back
#define pii pair<int, int>

ll const lim = 3e5;
ll const mod = 1e9 + 7;

ll n, m, t, ans, mxw, mxh;
ll fql[lim + 5], fqr[lim + 5];

void solve() {
  cin >> n >> m >> t;
  vector<pair<ll, ll>> arr;
  map<pair<ll, ll>, ll> mp;
  for (int i = 1; i <= t; i++) {
    ll w, h;
    cin >> w >> h;
    arr.pb({w, h});
    fql[w] += 1;
    fqr[h] += 1;
    mxw = max(mxw, fql[w]);
    mxh = max(mxh, fqr[h]);
    mp[{w, h}] = 1;
  }

  ans = mxw + mxh;
  vector<ll> row, col;
  for (int i = 0; i <= n; i++)
    if (fql[i] == mxw)
      row.pb(i);
  for (int i = 0; i <= m; i++)
    if (fqr[i] == mxh)
      col.pb(i);

  bool flag = true;
  for (auto x : row) {
    for (auto y : col) {
      if (!mp.count({x, y})) {
        flag = false;
        break;
      }
    }
    if (!flag)
      break;
  }
  if (flag)
    ans -= 1;
  cout << ans << endl;
}

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

  int t = 1, no = 0;
  while (t--) {
    solve();
  }
  return 0;
}

Error: TLE

Fixed submission:

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

#define ff first
#define ss second
#define pb push_back
#define pii pair<int, int>

ll const lim = 3e5;
ll const mod = 1e9 + 7;

int n, m, t;
int fql[lim + 5], fqr[lim + 5];

void solve() {
  cin >> n >> m >> t;
  vector<pii> vec;
  vector<int> col, row;
  map<pii, int> mp;
  for (int i = 1; i <= t; i++) {
    int w, h;
    cin >> w >> h;
    vec.pb({w, h});
    fql[w] += 1;
    fqr[h] += 1;
    mp[{w, h}] += 1;
  }
  int mxl = *max_element(fql, fql + lim + 2);
  int mxr = *max_element(fqr, fqr + lim + 2);

  set<int> lhs, rhs;
  for (int i = 0; i < vec.size(); i++) {
    if (fql[vec[i].ff] == mxl)
      lhs.insert(vec[i].ff);
    if (fqr[vec[i].ss] == mxr)
      rhs.insert(vec[i].ss);
  }
  vector<int> arr, brr;
  for (auto x : lhs)
    arr.pb(x);
  for (auto x : rhs)
    brr.pb(x);

  int ans = 0;
  for (auto x : arr) {
    for (auto y : brr) {
      int val = fql[x] + fqr[y];
      if (mp[{x, y}])
        val -= 1;
      ans = max(ans, val);
    }
  }
  cout << ans << endl;
}

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

  int t = 1, no = 0;
  while (t--) {
    solve();
  }
  return 0;
}

/*
4 5 11
1 3
1 5
2 3
3 1
3 2
3 4
3 5
4 1
4 3
4 4
4 5
*/
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

struct Point {
  ll x;
  ll y;
};
bool operator==(const Point &lhs, const Point &rhs) {
  return lhs.x == rhs.x && lhs.y == rhs.y;
}
bool operator<(const Point &lhs, const Point &rhs) {
  if (lhs.x < rhs.x) {
    return true;
  }
  if (lhs.x == rhs.x && lhs.y < rhs.y) {
    return true;
  }
  return false;
}

int main() {
  ll h, w, m;
  map<ll, ll> mx;
  map<ll, ll> my;
  vector<Point> v;
  map<Point, ll> mp;
  cin >> h >> w >> m;
  vector<ll> sh(m);
  vector<ll> sw(m);
  for (ll i = 0; i < m; i++) {
    cin >> sh[i] >> sw[i];
    mx[sh[i]]++;
    my[sw[i]]++;
    Point p = {sh[i], sw[i]};
    v.push_back(p);
    mp[p]++;
  }
  vector<ll> max_x_idx;
  ll max_x = 0;
  vector<ll> max_y_idx;
  ll max_y = 0;
  for (auto e : mx) {
    if (max_x < e.second) {
      max_x_idx.clear();
    }
    if (max_x <= e.second) {
      max_x = e.second;
      max_x_idx.push_back(e.first);
    }
  }
  for (auto e : my) {
    if (max_y < e.second) {
      max_y_idx.clear();
    }
    if (max_y <= e.second) {
      max_y = e.second;
      max_y_idx.push_back(e.first);
    }
  }
  for (auto ex : max_x_idx) {
    for (auto ey : max_y_idx) {
      Point item = {ex, ey};
      if (!mp[item]) {
        cout << max_x + max_y << endl;
        return 0;
      }
      // if (find(v.begin(), v.end(), item) == v.end()) {
      //     cout << max_x + max_y << endl;
      //     return 0;
      // }
    }
  }
  cout << max_x + max_y - 1 << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

struct Point {
  ll x;
  ll y;
};
bool operator==(const Point &lhs, const Point &rhs) {
  return lhs.x == rhs.x && lhs.y == rhs.y;
}

int main() {
  ll h, w, m;
  map<ll, ll> mx;
  map<ll, ll> my;
  vector<Point> v;
  cin >> h >> w >> m;
  vector<ll> sh(m);
  vector<ll> sw(m);
  for (ll i = 0; i < m; i++) {
    cin >> sh[i] >> sw[i];
    mx[sh[i]]++;
    my[sw[i]]++;
    v.push_back({sh[i], sw[i]});
  }
  vector<ll> max_x_idx;
  ll max_x = 0;
  vector<ll> max_y_idx;
  ll max_y = 0;
  for (auto e : mx) {
    if (max_x < e.second) {
      max_x_idx.clear();
    }
    if (max_x <= e.second) {
      max_x = e.second;
      max_x_idx.push_back(e.first);
    }
  }
  for (auto e : my) {
    if (max_y < e.second) {
      max_y_idx.clear();
    }
    if (max_y <= e.second) {
      max_y = e.second;
      max_y_idx.push_back(e.first);
    }
  }
  for (auto ex : max_x_idx) {
    for (auto ey : max_y_idx) {
      Point item = {ex, ey};
      if (find(v.begin(), v.end(), item) == v.end()) {
        cout << max_x + max_y << endl;
        return 0;
      }
    }
  }
  cout << max_x + max_y - 1 << endl;
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr long long MOD = 1000000007;
constexpr long long INF = 1LL << 60;
const long double PI = acosl(-1.0);
constexpr long double EPS = 1e-11;
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;
}
int main() {
  ll h, w, m;
  cin >> h >> w >> m;
  vector<ll> H(m), W(m);
  for (ll i = 0; i < m; i++)
    cin >> H[i] >> W[i];
  map<pair<ll, ll>, ll> bomb;
  for (ll i = 0; i < m; i++) {
    bomb[{H[i] - 1, W[i] - 1}]++;
  }
  vector<ll> mpx(h, 0), mpy(w, 0);
  for (ll i = 0; i < m; i++)
    mpx[H[i] - 1]++;
  for (ll i = 0; i < m; i++)
    mpy[W[i] - 1]++;
  ll xkey = 0;
  ll tmp = -INF;
  for (ll i = 0; i < h; i++) {
    if (chmax(tmp, mpx[i]))
      xkey = i;
  }
  tmp = -INF;
  ll ykey = 0;
  for (ll i = 0; i < w; i++) {
    if (chmax(tmp, mpy[i]))
      ykey = i;
  }
  vector<ll> xkouho, ykouho;
  for (ll i = 0; i < h; i++) {
    if (mpx[i] == mpx[xkey])
      xkouho.push_back(i);
  }
  for (ll i = 0; i < w; i++) {
    if (mpy[i] == mpy[ykey])
      ykouho.push_back(i);
  }
  ll ans = 0;
  for (auto i : xkouho) {
    for (auto j : ykouho) {
      ll tmp = mpx[i] + mpy[j];
      if (bomb[{i, j}] == 0) {
        ans = tmp;
        goto okok;
      }
    }
  }
okok:
  if (ans == 0)
    ans = mpx[xkey] + mpy[ykey] - 1;
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr long long MOD = 1000000007;
constexpr long long INF = 1LL << 60;
const long double PI = acosl(-1.0);
constexpr long double EPS = 1e-11;
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;
}
int main() {
  ll h, w, m;
  cin >> h >> w >> m;
  vector<ll> H(m), W(m);
  for (ll i = 0; i < m; i++)
    cin >> H[i] >> W[i];
  map<pair<ll, ll>, ll> bomb;
  for (ll i = 0; i < m; i++) {
    bomb[{H[i] - 1, W[i] - 1}]++;
  }
  vector<ll> mpx(h, 0), mpy(w, 0);
  for (ll i = 0; i < m; i++)
    mpx[H[i] - 1]++;
  for (ll i = 0; i < m; i++)
    mpy[W[i] - 1]++;
  ll xkey = 0;
  ll tmp = -INF;
  for (ll i = 0; i < h; i++) {
    if (chmax(tmp, mpx[i]))
      xkey = i;
  }
  tmp = -INF;
  ll ykey = 0;
  for (ll i = 0; i < w; i++) {
    if (chmax(tmp, mpy[i]))
      ykey = i;
  }
  vector<ll> xkouho, ykouho;
  for (ll i = 0; i < h; i++) {
    if (mpx[i] == mpx[xkey])
      xkouho.push_back(i);
  }
  for (ll i = 0; i < w; i++) {
    if (mpy[i] == mpy[ykey])
      ykouho.push_back(i);
  }
  ll ans = 0;
  for (auto i : xkouho) {
    for (auto j : ykouho) {
      ll tmp = mpx[i] + mpy[j];
      if (bomb[{i, j}] != 0)
        tmp--;
      chmax(ans, tmp);
    }
  }
  cout << ans << endl;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {

  int H, W, M;
  cin >> H >> W >> M;

  vector<int> g(H), r(W);
  map<pair<int, int>, int> mp;
  int gm = 0, rm = 0;

  for (int i = 0; i < M; i++) {
    int h, w;
    cin >> h >> w;
    g[h - 1]++;
    r[w - 1]++;
    mp[make_pair(h - 1, w - 1)]++;
    gm = max(gm, g[h - 1]);
    rm = max(rm, r[w - 1]);
  }

  vector<int> cg(0), cr(0);
  for (int i = 0; i < H; i++) {
    if (g[i] == gm)
      cg.push_back(i);
  }

  for (int i = 0; i < W; i++) {
    if (r[i] == rm)
      cr.push_back(i);
  }

  int ans = 0;
  for (int G : cg) {
    for (int R : cr) {
      ans = max(ans, gm + rm - mp[make_pair(G, R)]);
      if (!mp[make_pair(G, R)])
        break;
    }
  }

  cout << ans << endl;
}


Error: TLE

Fixed submission:

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

int main() {

  int H, W, M;
  cin >> H >> W >> M;

  vector<int> g(H), r(W);
  map<pair<int, int>, int> mp;
  int gm = 0, rm = 0;

  for (int i = 0; i < M; i++) {
    int h, w;
    cin >> h >> w;
    g[h - 1]++;
    r[w - 1]++;
    mp[make_pair(h - 1, w - 1)]++;
    gm = max(gm, g[h - 1]);
    rm = max(rm, r[w - 1]);
  }

  vector<int> cg(0), cr(0);
  for (int i = 0; i < H; i++) {
    if (g[i] == gm)
      cg.push_back(i);
  }

  for (int i = 0; i < W; i++) {
    if (r[i] == rm)
      cr.push_back(i);
  }

  int ans = 0;
  for (int G : cg) {
    for (int R : cr) {
      ans = max(ans, gm + rm - mp[make_pair(G, R)]);
    }
  }

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

#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;

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

  ll h, w, m;
  cin >> h >> w >> m;

  vector<ll> a(m), b(m);
  vector<ll> hcnt(h + 10, 0), wcnt(w + 10, 0);
  ll hmx = 0;
  ll wmx = 0;
  map<pair<int, int>, int> grid;
  rep(i, m) {
    cin >> a[i] >> b[i];
    --a[i];
    --b[i];
    grid[{a[i], b[i]}] = 1;

    ++hcnt[a[i]];
    ++wcnt[b[i]];
    if (hcnt[a[i]] > hmx) {
      hmx = hcnt[a[i]];
    }
    if (wcnt[b[i]] > wmx) {
      wmx = wcnt[b[i]];
    }
  }

  vector<int> hmxs, wmxs;
  rep(i, h) {
    if (hcnt[i] == hmx)
      hmxs.push_back(i);
  }
  rep(i, w) {
    if (wcnt[i] == wmx)
      wmxs.push_back(i);
  }

  int hh = hmxs[0];
  int ww = wmxs[0];
  bool found = false;
  for (auto hi : hmxs)
    for (auto wj : wmxs) {
      if (grid[{hi, wj}] == 0) {
        hh = hi;
        ww = wj;
        found = true;
        break;
      }
    }

  if (found)
    cout << hcnt[hh] + wcnt[ww] << endl;
  else
    cout << hcnt[hh] + wcnt[ww] - 1 << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;

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

  ll h, w, m;
  cin >> h >> w >> m;

  vector<ll> a(m), b(m);
  vector<ll> hcnt(h + 10, 0), wcnt(w + 10, 0);
  ll hmx = 0;
  ll wmx = 0;
  vector<vector<int>> grid(h, vector<int>(w, 0));
  rep(i, m) {
    cin >> a[i] >> b[i];
    --a[i];
    --b[i];
    grid[a[i]][b[i]] = 1;

    ++hcnt[a[i]];
    ++wcnt[b[i]];
    if (hcnt[a[i]] > hmx) {
      hmx = hcnt[a[i]];
    }
    if (wcnt[b[i]] > wmx) {
      wmx = wcnt[b[i]];
    }
  }

  vector<int> hmxs, wmxs;
  rep(i, h) {
    if (hcnt[i] == hmx)
      hmxs.push_back(i);
  }
  rep(i, w) {
    if (wcnt[i] == wmx)
      wmxs.push_back(i);
  }

  int hh = hmxs[0];
  int ww = wmxs[0];
  bool found = false;
  for (auto hi : hmxs)
    for (auto wj : wmxs) {
      if (grid[hi][wj] == 0) {
        hh = hi;
        ww = wj;
        found = true;
        break;
      }
    }

  if (found)
    cout << hcnt[hh] + wcnt[ww] << endl;
  else
    cout << hcnt[hh] + wcnt[ww] - 1 << endl;

  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (long long i = 0; i < (long long)(n); ++i)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const double pi = acos(-1);
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, -1, 1, 1, -1};
int ddx[5] = {2, 1, 0, -1, -2};
int ddy[5] = {2, 1, 0, -1, -2};

const int MAX = 510000;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int h, w, m;
  cin >> h >> w >> m;
  vector<int> a(h), b(w);
  set<P> st;
  rep(i, m) {
    int y, x;
    cin >> y >> x;
    y--;
    x--;
    a[y]++;
    b[x]++;
    st.insert(P(y, x));
  }
  int ymax = *max_element(a.begin(), a.end());
  int xmax = *max_element(b.begin(), b.end());

  int cnty = 0, cntx = 0;
  rep(i, h) if (a[i] == ymax) cnty++;
  rep(i, w) if (b[i] == xmax) cntx++;

  int num = cnty * cntx;
  for (auto s : st) {
    if (a[s.first] == ymax && b[s.second] == xmax)
      num--;
  }
  int ans = ymax + xmax;
  if (num == 0)
    ans--;
  cout << ans << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (long long i = 0; i < (long long)(n); ++i)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const double pi = acos(-1);
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, -1, 1, 1, -1};
int ddx[5] = {2, 1, 0, -1, -2};
int ddy[5] = {2, 1, 0, -1, -2};

const int MAX = 510000;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int h, w, m;
  cin >> h >> w >> m;
  vector<int> a(m), b(m);
  rep(i, m) cin >> a[i] >> b[i];

  vector<vector<int>> num(h, vector<int>(w, 0));
  rep(i, m) {
    a[i]--;
    b[i]--;
    num[a[i]][b[i]]++;
  }
  vector<vector<int>> s(h + 1, vector<int>(w + 1, 0));
  rep(i, h) rep(j, w) {
    s[i + 1][j + 1] = s[i][j + 1] + s[i + 1][j] - s[i][j] + num[i][j];
  }
  int ymax = 0, xmax = 0;
  rep(i, h) ymax = max(ymax, s[i + 1][w] - s[i][w]);
  rep(j, w) xmax = max(xmax, s[h][j + 1] - s[h][j]);

  int ans = ymax + xmax;
  int num1 = 0, num2 = 0, cnt = 0;
  rep(i, h) if (s[i + 1][w] - s[i][w] == ymax) num1++;
  rep(j, w) if (s[h][j + 1] - s[h][j] == xmax) num2++;
  cnt = num1 * num2;
  rep(i, m) {
    if (ymax == s[a[i] + 1][b[i]] - s[a[i]][b[i]] &&
        xmax == s[a[i]][b[i] + 1] - s[a[i]][b[i]])
      cnt--;
  }
  if (cnt)
    cout << ans << endl;
  else
    cout << ans - 1 << endl;
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

/*
    Mbak Sana Dong
    Mbak Chaeyoung Dong
*/
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int tarx[400300], tary[400300];
vector<pair<int, int>> vi[400300];
int seg[1200900];
void update(int idx, int l, int r, int index, int val) {
  if (l > index || r < index)
    return;
  if (l == r && l == index) {
    seg[idx] += val;
    return;
  }
  int mid = (l + r) / 2;
  update(idx * 2, l, mid, index, val);
  update(idx * 2 + 1, mid + 1, r, index, val);
  seg[idx] = max(seg[idx * 2], seg[idx * 2 + 1]);
}
int main() {
  int n, i, j, k, x, y, ans, curr, temp, m;
  int tc;
  int r, c;
  n = 3e5;
  cin >> r >> c >> m;
  for (i = 1; i <= m; i++) {
    scanf("%d %d", &x, &y);
    tarx[x]++;
    tary[y]++;
    update(1, 1, n, y, 1);
    vi[x].push_back({x, y});
  }
  int chaeng = 0;
  for (i = 1; i <= 300000; i++) {
    for (auto x : vi[i]) {
      update(1, 1, n, x.second, -1);
    }
    chaeng = max(chaeng, tarx[i] + seg[1]);
    for (auto x : vi[i]) {
      update(1, 1, n, x.second, 1);
    }
  }
  cout << chaeng << endl;
  return 0;
}


Error: 0

Fixed submission:

/*
    Mbak Sana Dong
    Mbak Chaeyoung Dong
*/
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int tarx[300300], tary[300300];
vector<pair<int, int>> vi[300300];
int seg[900900];
void update(int idx, int l, int r, int index, int val) {
  if (l > index || r < index)
    return;
  if (l == r && l == index) {
    seg[idx] += val;
    return;
  }
  int mid = (l + r) / 2;
  update(idx * 2, l, mid, index, val);
  update(idx * 2 + 1, mid + 1, r, index, val);
  seg[idx] = max(seg[idx * 2], seg[idx * 2 + 1]);
}
int main() {
  int n, i, j, k, x, y, ans, curr, temp, m;
  int tc;
  int r, c;
  n = 3e5;
  cin >> r >> c >> m;
  multiset<int> ms;
  for (i = 1; i <= m; i++) {
    cin >> x >> y;
    tarx[x]++;
    tary[y]++;
    update(1, 1, n, y, 1);
    vi[x].push_back({x, y});
  }
  int chaeng = 0;
  for (i = 1; i <= 300000; i++) {
    for (auto x : vi[i]) {
      update(1, 1, n, x.second, -1);
    }
    chaeng = max(chaeng, tarx[i] + seg[1]);
    for (auto x : vi[i]) {
      update(1, 1, n, x.second, 1);
    }
  }
  cout << chaeng << endl;
  return 0;
}