답안 #329245

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
329245 2020-11-20T00:24:09 Z VROOM_VARUN Examination (JOI19_examination) C++14
2 / 100
3000 ms 183916 KB
/*
ID: varunra2
LANG: C++
TASK: exam
*/

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

#ifdef DEBUG
#include "lib/debug.h"
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define debug_arr(...) \
  cerr << "[" << #__VA_ARGS__ << "]:", debug_arr(__VA_ARGS__)
#pragma GCC diagnostic ignored "-Wsign-compare"
//#pragma GCC diagnostic ignored "-Wunused-parameter"
//#pragma GCC diagnostic ignored "-Wunused-variable"
#else
#define debug(...) 42
#endif

#define int long long

#define EPS 1e-9
#define IN(A, B, C) assert(B <= A && A <= C)
#define INF (int)1e9
#define MEM(a, b) memset(a, (b), sizeof(a))
#define MOD 1000000007
#define MP make_pair
#define PB push_back
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define x first
#define y second

const double PI = acos(-1.0);
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef map<int, int> MPII;
typedef multiset<int> MSETI;
typedef set<int> SETI;
typedef set<string> SETS;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef vector<string> VS;

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto& a : x)
#define sz(x) (int)(x).size()
typedef pair<int, int> pii;
typedef vector<int> vi;
#pragma GCC diagnostic ignored "-Wsign-compare"
// util functions

const int MAX = 2 * INF;

struct sparsebit {
  map<int, MPII> fen;
  void upd(int x, int y, int val) {
    for (int i = x; i <= MAX; i += (i & -i)) {
      for (int j = y; j <= MAX; j += (j & -j)) {
        debug(i, j, 1);
        fen[i][j] += val;
      }
    }
  }

  int qry(int x, int y) {
    int ret = 0;
    for (int i = x; i > 0; i -= (i & -i)) {
      for (int j = y; j > 0; j -= (j & -j)) {
        ret += fen[i][j];
      }
    }
    return ret;
  }

  int qry(int a, int b, int c, int d) {
    int ret = 0;
    ret += qry(c, d);
    if (a) ret -= qry(a - 1, d);
    if (b) ret -= qry(c, b - 1);
    if (a and b) ret += qry(a - 1, b - 1);
    return ret;
  }
};

int32_t main() {
// #ifndef ONLINE_JUDGE
  // freopen("exam.in", "r", stdin);
  // freopen("exam.out", "w", stdout);
// #endif
  cin.sync_with_stdio(0);
  cin.tie(0);

  int n, q;
  cin >> n >> q;

  VVI vals(n);
  VVI qrys(q);

  for (int i = 0; i < n; i++) {
    int s, t;
    cin >> s >> t;
    vals[i] = {s + t + 2, s + 1, t + 1};
  }

  for (int i = 0; i < q; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    qrys[i] = {z + 2, x + 1, y + 1, i};
  }

  sort(all(vals));
  sort(all(qrys));

  sparsebit bit;

  reverse(all(vals));
  reverse(all(qrys));

  int p1 = 0;

  VI ret(q, 0);

  for (int i = 0; i < q; i++) {
    while (p1 < n and vals[p1][0] >= qrys[i][0]) {
      bit.upd(vals[p1][1], vals[p1][2], 1);
      p1++;
    }
    ret[qrys[i][3]] = bit.qry(qrys[i][1], qrys[i][2], MAX - 100, MAX - 100);
  }

  for (int i = 0; i < q; i++) {
    cout << ret[i] << '\n';
  }

  return 0;
}

Compilation message

examination.cpp: In member function 'void sparsebit::upd(long long int, long long int, long long int)':
examination.cpp:19:20: warning: statement has no effect [-Wunused-value]
   19 | #define debug(...) 42
      |                    ^~
examination.cpp:64:9: note: in expansion of macro 'debug'
   64 |         debug(i, j, 1);
      |         ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 2 ms 492 KB Output is correct
4 Correct 2 ms 1004 KB Output is correct
5 Correct 2 ms 1004 KB Output is correct
6 Correct 2 ms 1004 KB Output is correct
7 Correct 870 ms 153708 KB Output is correct
8 Correct 889 ms 154432 KB Output is correct
9 Correct 907 ms 154656 KB Output is correct
10 Correct 427 ms 95852 KB Output is correct
11 Correct 677 ms 91244 KB Output is correct
12 Correct 138 ms 1132 KB Output is correct
13 Correct 831 ms 154348 KB Output is correct
14 Correct 809 ms 153452 KB Output is correct
15 Correct 807 ms 154220 KB Output is correct
16 Correct 560 ms 91372 KB Output is correct
17 Correct 427 ms 96192 KB Output is correct
18 Correct 145 ms 1004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3086 ms 183916 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3086 ms 183916 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 2 ms 492 KB Output is correct
4 Correct 2 ms 1004 KB Output is correct
5 Correct 2 ms 1004 KB Output is correct
6 Correct 2 ms 1004 KB Output is correct
7 Correct 870 ms 153708 KB Output is correct
8 Correct 889 ms 154432 KB Output is correct
9 Correct 907 ms 154656 KB Output is correct
10 Correct 427 ms 95852 KB Output is correct
11 Correct 677 ms 91244 KB Output is correct
12 Correct 138 ms 1132 KB Output is correct
13 Correct 831 ms 154348 KB Output is correct
14 Correct 809 ms 153452 KB Output is correct
15 Correct 807 ms 154220 KB Output is correct
16 Correct 560 ms 91372 KB Output is correct
17 Correct 427 ms 96192 KB Output is correct
18 Correct 145 ms 1004 KB Output is correct
19 Execution timed out 3086 ms 183916 KB Time limit exceeded
20 Halted 0 ms 0 KB -