/*
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
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using ordered_set_less = tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>;
using ordered_set_equal = tree<int, null_type, less_equal<int>, rb_tree_tag,
tree_order_statistics_node_update>;
using ordered_map =
tree<int, int, less<int>, rb_tree_tag, tree_order_statistics_node_update>;
const int RANDOM =
chrono::high_resolution_clock::now().time_since_epoch().count();
struct chash {
int operator()(int x) const { return x ^ RANDOM; }
};
gp_hash_table<int, int, chash> table;
// #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 maxn = 1e5;
const int MAX = maxn + 5;
int cnt = 0;
struct sparsebit {
vector<gp_hash_table<int, int, chash>> fen;
int tot = 0;
void upd(int x, int y, int val) {
// debug("in upd");
tot++;
for (int i = x; i <= MAX; i += (i & -i)) {
for (int j = y; j <= MAX; j += (j & -j)) {
// debug(i, j, 1);
// cnt++;
fen[i][j] += val;
}
}
// debug("out upd");
}
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)) {
// cnt++;
ret += fen[i][j];
}
}
return ret;
}
int qry(int a, int b, int c, int d) {
// debug("in big qry");
int ret = 0;
ret += tot;
if (a) ret -= qry(a - 1, d);
if (b) ret -= qry(c, b - 1);
if (a and b) ret += qry(a - 1, b - 1);
// debug("out big qry");
return ret;
}
void init() { fen.resize(MAX + 1); }
};
// MPII comp;
gp_hash_table<int, int, chash> comp[2];
void compress(VII& vals, int ind) {
// compress math scores then informatics scores seperately
// debug("in");
sort(all(vals));
int cnt = 0;
for (int i = 0; i < sz(vals); i++) {
if (vals[i].y == 0) cnt++;
comp[ind][vals[i].x] = cnt + 1;
}
// debug("out");
// assert(sz(vals) <= maxn);
}
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);
VII cmp1, cmp2;
for (int i = 0; i < n; i++) {
int s, t;
cin >> s >> t;
vals[i] = {s + t, s, t};
cmp1.PB(MP(s, 1));
cmp2.PB(MP(t, 1));
}
for (int i = 0; i < q; i++) {
int x, y, z;
cin >> x >> y >> z;
qrys[i] = {z, x, y, i};
cmp1.PB(MP(x, 0));
cmp2.PB(MP(y, 0));
}
compress(cmp1, 0);
compress(cmp2, 1);
sort(all(vals));
sort(all(qrys));
sparsebit bit;
bit.init();
reverse(all(vals));
reverse(all(qrys));
int p1 = 0;
VI ret(q);
for (int i = 0; i < q; i++) {
while (p1 < n and vals[p1][0] >= qrys[i][0]) {
bit.upd(comp[0][vals[p1][1]], comp[1][vals[p1][2]], 1);
p1++;
}
// debug(i);
ret[qrys[i][3]] =
bit.qry(comp[0][qrys[i][1]], comp[1][qrys[i][2]], MAX, MAX);
}
for (int i = 0; i < q; i++) {
cout << ret[i] << '\n';
}
// debug(cnt);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
21484 KB |
Output is correct |
2 |
Correct |
23 ms |
21504 KB |
Output is correct |
3 |
Correct |
24 ms |
21484 KB |
Output is correct |
4 |
Correct |
24 ms |
21484 KB |
Output is correct |
5 |
Correct |
24 ms |
21484 KB |
Output is correct |
6 |
Correct |
23 ms |
21484 KB |
Output is correct |
7 |
Correct |
59 ms |
28268 KB |
Output is correct |
8 |
Correct |
61 ms |
28396 KB |
Output is correct |
9 |
Correct |
61 ms |
28652 KB |
Output is correct |
10 |
Correct |
57 ms |
25516 KB |
Output is correct |
11 |
Correct |
48 ms |
26540 KB |
Output is correct |
12 |
Correct |
44 ms |
22252 KB |
Output is correct |
13 |
Correct |
57 ms |
28396 KB |
Output is correct |
14 |
Correct |
58 ms |
28524 KB |
Output is correct |
15 |
Correct |
59 ms |
28396 KB |
Output is correct |
16 |
Correct |
41 ms |
25004 KB |
Output is correct |
17 |
Correct |
54 ms |
24108 KB |
Output is correct |
18 |
Correct |
43 ms |
21996 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2090 ms |
335432 KB |
Output is correct |
2 |
Correct |
2040 ms |
335476 KB |
Output is correct |
3 |
Correct |
2043 ms |
335020 KB |
Output is correct |
4 |
Correct |
1586 ms |
173000 KB |
Output is correct |
5 |
Correct |
774 ms |
188776 KB |
Output is correct |
6 |
Correct |
997 ms |
37324 KB |
Output is correct |
7 |
Correct |
1239 ms |
226756 KB |
Output is correct |
8 |
Correct |
1246 ms |
223172 KB |
Output is correct |
9 |
Correct |
1078 ms |
191428 KB |
Output is correct |
10 |
Correct |
438 ms |
93000 KB |
Output is correct |
11 |
Correct |
725 ms |
96532 KB |
Output is correct |
12 |
Correct |
521 ms |
36940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2090 ms |
335432 KB |
Output is correct |
2 |
Correct |
2040 ms |
335476 KB |
Output is correct |
3 |
Correct |
2043 ms |
335020 KB |
Output is correct |
4 |
Correct |
1586 ms |
173000 KB |
Output is correct |
5 |
Correct |
774 ms |
188776 KB |
Output is correct |
6 |
Correct |
997 ms |
37324 KB |
Output is correct |
7 |
Correct |
1239 ms |
226756 KB |
Output is correct |
8 |
Correct |
1246 ms |
223172 KB |
Output is correct |
9 |
Correct |
1078 ms |
191428 KB |
Output is correct |
10 |
Correct |
438 ms |
93000 KB |
Output is correct |
11 |
Correct |
725 ms |
96532 KB |
Output is correct |
12 |
Correct |
521 ms |
36940 KB |
Output is correct |
13 |
Correct |
2562 ms |
340248 KB |
Output is correct |
14 |
Correct |
2494 ms |
339672 KB |
Output is correct |
15 |
Correct |
2001 ms |
335504 KB |
Output is correct |
16 |
Correct |
1823 ms |
174764 KB |
Output is correct |
17 |
Correct |
1131 ms |
195460 KB |
Output is correct |
18 |
Correct |
1004 ms |
37708 KB |
Output is correct |
19 |
Correct |
2450 ms |
340164 KB |
Output is correct |
20 |
Correct |
2492 ms |
339524 KB |
Output is correct |
21 |
Correct |
1829 ms |
255148 KB |
Output is correct |
22 |
Correct |
452 ms |
93144 KB |
Output is correct |
23 |
Correct |
813 ms |
93640 KB |
Output is correct |
24 |
Correct |
578 ms |
36812 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
21484 KB |
Output is correct |
2 |
Correct |
23 ms |
21504 KB |
Output is correct |
3 |
Correct |
24 ms |
21484 KB |
Output is correct |
4 |
Correct |
24 ms |
21484 KB |
Output is correct |
5 |
Correct |
24 ms |
21484 KB |
Output is correct |
6 |
Correct |
23 ms |
21484 KB |
Output is correct |
7 |
Correct |
59 ms |
28268 KB |
Output is correct |
8 |
Correct |
61 ms |
28396 KB |
Output is correct |
9 |
Correct |
61 ms |
28652 KB |
Output is correct |
10 |
Correct |
57 ms |
25516 KB |
Output is correct |
11 |
Correct |
48 ms |
26540 KB |
Output is correct |
12 |
Correct |
44 ms |
22252 KB |
Output is correct |
13 |
Correct |
57 ms |
28396 KB |
Output is correct |
14 |
Correct |
58 ms |
28524 KB |
Output is correct |
15 |
Correct |
59 ms |
28396 KB |
Output is correct |
16 |
Correct |
41 ms |
25004 KB |
Output is correct |
17 |
Correct |
54 ms |
24108 KB |
Output is correct |
18 |
Correct |
43 ms |
21996 KB |
Output is correct |
19 |
Correct |
2090 ms |
335432 KB |
Output is correct |
20 |
Correct |
2040 ms |
335476 KB |
Output is correct |
21 |
Correct |
2043 ms |
335020 KB |
Output is correct |
22 |
Correct |
1586 ms |
173000 KB |
Output is correct |
23 |
Correct |
774 ms |
188776 KB |
Output is correct |
24 |
Correct |
997 ms |
37324 KB |
Output is correct |
25 |
Correct |
1239 ms |
226756 KB |
Output is correct |
26 |
Correct |
1246 ms |
223172 KB |
Output is correct |
27 |
Correct |
1078 ms |
191428 KB |
Output is correct |
28 |
Correct |
438 ms |
93000 KB |
Output is correct |
29 |
Correct |
725 ms |
96532 KB |
Output is correct |
30 |
Correct |
521 ms |
36940 KB |
Output is correct |
31 |
Correct |
2562 ms |
340248 KB |
Output is correct |
32 |
Correct |
2494 ms |
339672 KB |
Output is correct |
33 |
Correct |
2001 ms |
335504 KB |
Output is correct |
34 |
Correct |
1823 ms |
174764 KB |
Output is correct |
35 |
Correct |
1131 ms |
195460 KB |
Output is correct |
36 |
Correct |
1004 ms |
37708 KB |
Output is correct |
37 |
Correct |
2450 ms |
340164 KB |
Output is correct |
38 |
Correct |
2492 ms |
339524 KB |
Output is correct |
39 |
Correct |
1829 ms |
255148 KB |
Output is correct |
40 |
Correct |
452 ms |
93144 KB |
Output is correct |
41 |
Correct |
813 ms |
93640 KB |
Output is correct |
42 |
Correct |
578 ms |
36812 KB |
Output is correct |
43 |
Correct |
2625 ms |
347768 KB |
Output is correct |
44 |
Correct |
2562 ms |
351736 KB |
Output is correct |
45 |
Correct |
2550 ms |
350156 KB |
Output is correct |
46 |
Correct |
1844 ms |
184540 KB |
Output is correct |
47 |
Correct |
1163 ms |
198728 KB |
Output is correct |
48 |
Correct |
1085 ms |
37964 KB |
Output is correct |
49 |
Correct |
1721 ms |
258868 KB |
Output is correct |
50 |
Correct |
1815 ms |
257588 KB |
Output is correct |
51 |
Correct |
1618 ms |
243508 KB |
Output is correct |
52 |
Correct |
694 ms |
128576 KB |
Output is correct |
53 |
Correct |
982 ms |
104000 KB |
Output is correct |