#include "bits/stdc++.h"
// @JASPER'S BOILERPLATE
using namespace std;
using ll = long long;
#define fi first
#define se second
#ifdef JASPER
#include "debug.h"
#else
#define debug(...) 166
#endif
#define int long long
using pii = pair < int, int >;
const int INF = 2e9;
const int MOD = 1e9 + 7;
const int N = 2e5 + 5;
struct Fenwick {
int n;
vector <int> f;
void init (int _n) {
n = _n;
f.resize(_n + 1);
}
int get(int x) {
int ans = 0;
for (; x >= 1; x -= x & -x)
ans += f[x];
return ans;
}
void upd(int x, int val) {
for (; x <= n; x += x & -x)
f[x] += val;
}
int qry(int l) { return get(n) - get(l - 1); }
} fen;
int n, q;
int ans[N];
vector <vector <int>> queries;
void dnc(int l, int r) {
if (l == r) return;
int m = (l + r) / 2;
dnc(l, m);
dnc(m + 1, r);
vector <vector <int>> qs;
// Solving queries in the left
for (int i = l; i <= m; ++i) {
auto x = queries[i];
if (x[3] == -1)
qs.push_back({x[1], x[2], -1});
}
// Al < Am < Ar -> only take student in right to update
for (int i = m + 1; i <= r; ++i) {
auto x = queries[i];
if (x[3] != -1)
qs.push_back({x[1], x[2], x[3]});
}
sort(qs.begin(), qs.end());
// Sort by Informatics points
for (auto& x : qs) {
if (x[2] == -1)
fen.upd(x[1], 1);
else
ans[x[2]] += fen.get(x[1]);
}
// Undoing changes
for (auto& x : qs) {
if (x[2] == -1)
fen.upd(x[1], -1);
}
}
void run_case() {
cin >> n >> q;
vector <int> val;
int Q = n + q;
for (int i = 1; i <= n; ++i) {
int s, t;
cin >> s >> t;
queries.push_back({s, t, s + t, -1});
val.push_back(s);
val.push_back(t);
val.push_back(s + t);
}
for (int i = 1; i <= q; ++i) {
int x, y, z;
cin >> x >> y >> z;
queries.push_back({x, y, z, i});
val.push_back(x);
val.push_back(y);
val.push_back(z);
}
for (int& x : val) x = -x;
sort(val.begin(), val.end());
val.resize(unique(val.begin(), val.end()) - val.begin());
int sz = val.size();
fen.init(N * 4 + 1);
for (auto& x : queries) {
for (int i = 0; i < (int) x.size() - 1; ++i) {
x[i] = lower_bound(val.begin(), val.end(), -x[i]) - val.begin() + 1;
// cout << x[i] << "\n";
}
}
// // sort by Maths points
sort(queries.begin(), queries.end());
dnc(0, Q - 1);
for (int i = 1; i <= q; ++i)
cout << ans[i] << "\n";
}
signed main() {
cin.tie(0) -> sync_with_stdio(0);
int Test = 1;
//cin >> Test;
for (int test = 1; test <= Test; test++){
run_case();
}
}
Compilation message
examination.cpp: In function 'void run_case()':
examination.cpp:112:9: warning: unused variable 'sz' [-Wunused-variable]
112 | int sz = val.size();
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
6492 KB |
Output is correct |
2 |
Correct |
2 ms |
6492 KB |
Output is correct |
3 |
Correct |
2 ms |
6492 KB |
Output is correct |
4 |
Correct |
2 ms |
6492 KB |
Output is correct |
5 |
Correct |
2 ms |
6608 KB |
Output is correct |
6 |
Correct |
2 ms |
6604 KB |
Output is correct |
7 |
Correct |
13 ms |
7452 KB |
Output is correct |
8 |
Correct |
13 ms |
7452 KB |
Output is correct |
9 |
Correct |
13 ms |
7452 KB |
Output is correct |
10 |
Correct |
12 ms |
7452 KB |
Output is correct |
11 |
Correct |
12 ms |
7452 KB |
Output is correct |
12 |
Correct |
11 ms |
7500 KB |
Output is correct |
13 |
Correct |
12 ms |
7452 KB |
Output is correct |
14 |
Correct |
12 ms |
7564 KB |
Output is correct |
15 |
Correct |
12 ms |
7544 KB |
Output is correct |
16 |
Correct |
10 ms |
7512 KB |
Output is correct |
17 |
Correct |
12 ms |
7452 KB |
Output is correct |
18 |
Correct |
10 ms |
7452 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
536 ms |
37328 KB |
Output is correct |
2 |
Correct |
550 ms |
35996 KB |
Output is correct |
3 |
Correct |
518 ms |
37576 KB |
Output is correct |
4 |
Correct |
516 ms |
36172 KB |
Output is correct |
5 |
Correct |
438 ms |
35480 KB |
Output is correct |
6 |
Correct |
427 ms |
36760 KB |
Output is correct |
7 |
Correct |
510 ms |
41724 KB |
Output is correct |
8 |
Correct |
510 ms |
36224 KB |
Output is correct |
9 |
Correct |
491 ms |
43080 KB |
Output is correct |
10 |
Correct |
399 ms |
36992 KB |
Output is correct |
11 |
Correct |
485 ms |
36240 KB |
Output is correct |
12 |
Correct |
408 ms |
31632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
536 ms |
37328 KB |
Output is correct |
2 |
Correct |
550 ms |
35996 KB |
Output is correct |
3 |
Correct |
518 ms |
37576 KB |
Output is correct |
4 |
Correct |
516 ms |
36172 KB |
Output is correct |
5 |
Correct |
438 ms |
35480 KB |
Output is correct |
6 |
Correct |
427 ms |
36760 KB |
Output is correct |
7 |
Correct |
510 ms |
41724 KB |
Output is correct |
8 |
Correct |
510 ms |
36224 KB |
Output is correct |
9 |
Correct |
491 ms |
43080 KB |
Output is correct |
10 |
Correct |
399 ms |
36992 KB |
Output is correct |
11 |
Correct |
485 ms |
36240 KB |
Output is correct |
12 |
Correct |
408 ms |
31632 KB |
Output is correct |
13 |
Correct |
586 ms |
37780 KB |
Output is correct |
14 |
Correct |
567 ms |
37148 KB |
Output is correct |
15 |
Correct |
519 ms |
37052 KB |
Output is correct |
16 |
Correct |
542 ms |
37692 KB |
Output is correct |
17 |
Correct |
505 ms |
34856 KB |
Output is correct |
18 |
Correct |
443 ms |
35892 KB |
Output is correct |
19 |
Correct |
560 ms |
37452 KB |
Output is correct |
20 |
Correct |
592 ms |
37176 KB |
Output is correct |
21 |
Correct |
569 ms |
42660 KB |
Output is correct |
22 |
Correct |
437 ms |
35120 KB |
Output is correct |
23 |
Correct |
488 ms |
35732 KB |
Output is correct |
24 |
Correct |
414 ms |
32116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
6492 KB |
Output is correct |
2 |
Correct |
2 ms |
6492 KB |
Output is correct |
3 |
Correct |
2 ms |
6492 KB |
Output is correct |
4 |
Correct |
2 ms |
6492 KB |
Output is correct |
5 |
Correct |
2 ms |
6608 KB |
Output is correct |
6 |
Correct |
2 ms |
6604 KB |
Output is correct |
7 |
Correct |
13 ms |
7452 KB |
Output is correct |
8 |
Correct |
13 ms |
7452 KB |
Output is correct |
9 |
Correct |
13 ms |
7452 KB |
Output is correct |
10 |
Correct |
12 ms |
7452 KB |
Output is correct |
11 |
Correct |
12 ms |
7452 KB |
Output is correct |
12 |
Correct |
11 ms |
7500 KB |
Output is correct |
13 |
Correct |
12 ms |
7452 KB |
Output is correct |
14 |
Correct |
12 ms |
7564 KB |
Output is correct |
15 |
Correct |
12 ms |
7544 KB |
Output is correct |
16 |
Correct |
10 ms |
7512 KB |
Output is correct |
17 |
Correct |
12 ms |
7452 KB |
Output is correct |
18 |
Correct |
10 ms |
7452 KB |
Output is correct |
19 |
Correct |
536 ms |
37328 KB |
Output is correct |
20 |
Correct |
550 ms |
35996 KB |
Output is correct |
21 |
Correct |
518 ms |
37576 KB |
Output is correct |
22 |
Correct |
516 ms |
36172 KB |
Output is correct |
23 |
Correct |
438 ms |
35480 KB |
Output is correct |
24 |
Correct |
427 ms |
36760 KB |
Output is correct |
25 |
Correct |
510 ms |
41724 KB |
Output is correct |
26 |
Correct |
510 ms |
36224 KB |
Output is correct |
27 |
Correct |
491 ms |
43080 KB |
Output is correct |
28 |
Correct |
399 ms |
36992 KB |
Output is correct |
29 |
Correct |
485 ms |
36240 KB |
Output is correct |
30 |
Correct |
408 ms |
31632 KB |
Output is correct |
31 |
Correct |
586 ms |
37780 KB |
Output is correct |
32 |
Correct |
567 ms |
37148 KB |
Output is correct |
33 |
Correct |
519 ms |
37052 KB |
Output is correct |
34 |
Correct |
542 ms |
37692 KB |
Output is correct |
35 |
Correct |
505 ms |
34856 KB |
Output is correct |
36 |
Correct |
443 ms |
35892 KB |
Output is correct |
37 |
Correct |
560 ms |
37452 KB |
Output is correct |
38 |
Correct |
592 ms |
37176 KB |
Output is correct |
39 |
Correct |
569 ms |
42660 KB |
Output is correct |
40 |
Correct |
437 ms |
35120 KB |
Output is correct |
41 |
Correct |
488 ms |
35732 KB |
Output is correct |
42 |
Correct |
414 ms |
32116 KB |
Output is correct |
43 |
Correct |
624 ms |
39892 KB |
Output is correct |
44 |
Correct |
615 ms |
39852 KB |
Output is correct |
45 |
Correct |
636 ms |
40348 KB |
Output is correct |
46 |
Correct |
556 ms |
39064 KB |
Output is correct |
47 |
Correct |
482 ms |
37632 KB |
Output is correct |
48 |
Correct |
430 ms |
35792 KB |
Output is correct |
49 |
Correct |
570 ms |
45216 KB |
Output is correct |
50 |
Correct |
590 ms |
40336 KB |
Output is correct |
51 |
Correct |
570 ms |
44984 KB |
Output is correct |
52 |
Correct |
459 ms |
38624 KB |
Output is correct |
53 |
Correct |
495 ms |
35672 KB |
Output is correct |