#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>
using namespace std;
// BEGIN NO SAD
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
typedef vector<int> vi;
#define f first
#define s second
// END NO SAD
template<class Fun>
class y_combinator_result {
Fun fun_;
public:
template<class T>
explicit y_combinator_result(T &&fun): fun_(std::forward<T>(fun)) {}
template<class ...Args>
decltype(auto) operator()(Args &&...args) {
return fun_(std::ref(*this), std::forward<Args>(args)...);
}
};
template<class Fun>
decltype(auto) y_combinator(Fun &&fun) {
return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun));
}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<vector<ll>> matrix;
struct koosaga {
vector<vector<int>> ragetree;
int SZ;
koosaga(int n) {
SZ = 1;
while(SZ < n) SZ *= 2;
ragetree.resize(2*SZ);
}
void upd(int idx, int val) {
idx += SZ;
while(idx) {
ragetree[idx].pb(val);
idx /= 2;
}
}
int qry(const vector<int>& v, int x) {
return ub(all(v), x) - v.begin();
}
int qry(int lhs, int rhs, int x) {
int ret = 0;
lhs += SZ;
rhs += SZ;
while(lhs <= rhs) {
if(lhs%2) ret += qry(ragetree[lhs++], x);
if(rhs%2==0) ret += qry(ragetree[rhs--], x);
lhs /= 2;
rhs /= 2;
}
return ret;
}
};
void gen(koosaga& koo, vector<pii>& v) {
sort(all(v));
for(auto[y,x]: v) {
koo.upd(x, y);
}
}
void solve() {
int n, q;
cin >> n >> q;
vector<pii> sump, yp;
vector<int> xs;
for(int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
xs.pb(x);
sump.eb(x+y, x);
yp.eb(y, x);
}
sort(all(xs));
xs.erase(unique(all(xs)), xs.end());
koosaga ykoo(sz(xs)), sumkoo(sz(xs));
for(auto& [_, x]: sump) x = lb(all(xs), x) - xs.begin();
for(auto& [_, x]: yp) x = lb(all(xs), x) - xs.begin();
gen(ykoo, yp);
gen(sumkoo, sump);
while(q--) {
int x, y, z;
cin >> x >> y >> z;
if(x+y >= z) {
// the boring case
int ret = n;
int xidx = ub(all(xs), x-1) - xs.begin();
ret -= ykoo.qry(0, xidx-1, 2e9);
ret -= ykoo.qry(xidx, sz(xs)-1, y-1);
cout << ret << "\n";
}
else {
int ret = n;
int xidx = ub(all(xs), x-1) - xs.begin();
ret -= ykoo.qry(0, xidx-1, 2e9);
int xidx2 = ub(all(xs), z-y) - xs.begin();
ret -= sumkoo.qry(xidx, xidx2-1, z-1);
ret -= ykoo.qry(xidx2, sz(xs)-1, y-1);
cout << ret << "\n";
}
}
}
// what would chika do
// are there edge cases (N=1?)
// are array sizes proper (scaled by proper constant, for example 2* for koosaga tree)
// integer overflow?
// DS reset properly between test cases
// are you doing geometry in floating points
// are you not using modint when you should
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
8 ms |
1476 KB |
Output is correct |
8 |
Correct |
8 ms |
1520 KB |
Output is correct |
9 |
Correct |
7 ms |
1484 KB |
Output is correct |
10 |
Correct |
7 ms |
1496 KB |
Output is correct |
11 |
Correct |
4 ms |
704 KB |
Output is correct |
12 |
Correct |
3 ms |
588 KB |
Output is correct |
13 |
Correct |
7 ms |
1484 KB |
Output is correct |
14 |
Correct |
7 ms |
1496 KB |
Output is correct |
15 |
Correct |
7 ms |
1484 KB |
Output is correct |
16 |
Correct |
3 ms |
460 KB |
Output is correct |
17 |
Correct |
6 ms |
1484 KB |
Output is correct |
18 |
Correct |
2 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
349 ms |
31824 KB |
Output is correct |
2 |
Correct |
357 ms |
31664 KB |
Output is correct |
3 |
Correct |
357 ms |
31804 KB |
Output is correct |
4 |
Correct |
286 ms |
31792 KB |
Output is correct |
5 |
Correct |
109 ms |
10044 KB |
Output is correct |
6 |
Correct |
75 ms |
9388 KB |
Output is correct |
7 |
Correct |
330 ms |
31800 KB |
Output is correct |
8 |
Correct |
337 ms |
31856 KB |
Output is correct |
9 |
Correct |
305 ms |
31748 KB |
Output is correct |
10 |
Correct |
63 ms |
5424 KB |
Output is correct |
11 |
Correct |
226 ms |
31572 KB |
Output is correct |
12 |
Correct |
43 ms |
4728 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
349 ms |
31824 KB |
Output is correct |
2 |
Correct |
357 ms |
31664 KB |
Output is correct |
3 |
Correct |
357 ms |
31804 KB |
Output is correct |
4 |
Correct |
286 ms |
31792 KB |
Output is correct |
5 |
Correct |
109 ms |
10044 KB |
Output is correct |
6 |
Correct |
75 ms |
9388 KB |
Output is correct |
7 |
Correct |
330 ms |
31800 KB |
Output is correct |
8 |
Correct |
337 ms |
31856 KB |
Output is correct |
9 |
Correct |
305 ms |
31748 KB |
Output is correct |
10 |
Correct |
63 ms |
5424 KB |
Output is correct |
11 |
Correct |
226 ms |
31572 KB |
Output is correct |
12 |
Correct |
43 ms |
4728 KB |
Output is correct |
13 |
Correct |
440 ms |
31792 KB |
Output is correct |
14 |
Correct |
400 ms |
31788 KB |
Output is correct |
15 |
Correct |
366 ms |
31792 KB |
Output is correct |
16 |
Correct |
363 ms |
31792 KB |
Output is correct |
17 |
Correct |
140 ms |
9904 KB |
Output is correct |
18 |
Correct |
81 ms |
9260 KB |
Output is correct |
19 |
Correct |
464 ms |
31732 KB |
Output is correct |
20 |
Correct |
438 ms |
31920 KB |
Output is correct |
21 |
Correct |
431 ms |
31780 KB |
Output is correct |
22 |
Correct |
64 ms |
5400 KB |
Output is correct |
23 |
Correct |
227 ms |
31748 KB |
Output is correct |
24 |
Correct |
41 ms |
4784 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
8 ms |
1476 KB |
Output is correct |
8 |
Correct |
8 ms |
1520 KB |
Output is correct |
9 |
Correct |
7 ms |
1484 KB |
Output is correct |
10 |
Correct |
7 ms |
1496 KB |
Output is correct |
11 |
Correct |
4 ms |
704 KB |
Output is correct |
12 |
Correct |
3 ms |
588 KB |
Output is correct |
13 |
Correct |
7 ms |
1484 KB |
Output is correct |
14 |
Correct |
7 ms |
1496 KB |
Output is correct |
15 |
Correct |
7 ms |
1484 KB |
Output is correct |
16 |
Correct |
3 ms |
460 KB |
Output is correct |
17 |
Correct |
6 ms |
1484 KB |
Output is correct |
18 |
Correct |
2 ms |
460 KB |
Output is correct |
19 |
Correct |
349 ms |
31824 KB |
Output is correct |
20 |
Correct |
357 ms |
31664 KB |
Output is correct |
21 |
Correct |
357 ms |
31804 KB |
Output is correct |
22 |
Correct |
286 ms |
31792 KB |
Output is correct |
23 |
Correct |
109 ms |
10044 KB |
Output is correct |
24 |
Correct |
75 ms |
9388 KB |
Output is correct |
25 |
Correct |
330 ms |
31800 KB |
Output is correct |
26 |
Correct |
337 ms |
31856 KB |
Output is correct |
27 |
Correct |
305 ms |
31748 KB |
Output is correct |
28 |
Correct |
63 ms |
5424 KB |
Output is correct |
29 |
Correct |
226 ms |
31572 KB |
Output is correct |
30 |
Correct |
43 ms |
4728 KB |
Output is correct |
31 |
Correct |
440 ms |
31792 KB |
Output is correct |
32 |
Correct |
400 ms |
31788 KB |
Output is correct |
33 |
Correct |
366 ms |
31792 KB |
Output is correct |
34 |
Correct |
363 ms |
31792 KB |
Output is correct |
35 |
Correct |
140 ms |
9904 KB |
Output is correct |
36 |
Correct |
81 ms |
9260 KB |
Output is correct |
37 |
Correct |
464 ms |
31732 KB |
Output is correct |
38 |
Correct |
438 ms |
31920 KB |
Output is correct |
39 |
Correct |
431 ms |
31780 KB |
Output is correct |
40 |
Correct |
64 ms |
5400 KB |
Output is correct |
41 |
Correct |
227 ms |
31748 KB |
Output is correct |
42 |
Correct |
41 ms |
4784 KB |
Output is correct |
43 |
Correct |
472 ms |
41440 KB |
Output is correct |
44 |
Correct |
480 ms |
41084 KB |
Output is correct |
45 |
Correct |
458 ms |
41188 KB |
Output is correct |
46 |
Correct |
389 ms |
41180 KB |
Output is correct |
47 |
Correct |
117 ms |
10032 KB |
Output is correct |
48 |
Correct |
80 ms |
9260 KB |
Output is correct |
49 |
Correct |
481 ms |
40952 KB |
Output is correct |
50 |
Correct |
457 ms |
41008 KB |
Output is correct |
51 |
Correct |
527 ms |
40872 KB |
Output is correct |
52 |
Correct |
74 ms |
5420 KB |
Output is correct |
53 |
Correct |
244 ms |
41140 KB |
Output is correct |