//60 J O
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <memory>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include <array>
using namespace std;
template<typename T, typename = void> struct is_iterable : false_type {};
template<typename T> struct is_iterable<T, void_t<decltype(begin(declval<T>())),decltype(end(declval<T>()))>> : true_type {};
template<typename T> typename enable_if<is_iterable<T>::value&&!is_same<T, string>::value,ostream&>::type operator<<(ostream &cout, T const &v);
template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout << "(" << p.f << ", " << p.s << ")"; }
template<typename T> typename enable_if<is_iterable<T>::value&&!is_same<T, string>::value,ostream&>::type operator<<(ostream &cout, T const &v) {
cout << "[";
for (auto it = v.begin(); it != v.end();) {
cout << *it;
if (++it != v.end()) cout << ", ";
}
return cout << "]";
}
void dbg_out() { cout << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cout << ' ' << H; dbg_out(T...); }
#ifdef LOCAL
#define debug(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define debug(...) "zzz"
#endif
using ll = int;
using ld = long double;
using pii = pair<ll,ll>;
#define FOR(i, n) for(int i = 1; i<=n; i++)
#define F0R(i, n) for(int i = 0; i<n; i++)
#define all(x) x.begin(), x.end()
#define mp make_pair
#define pb push_back
#define f first
#define s second
template<typename T>
struct fen {
vector<T> tr;
ll mxn;
fen(ll sz) {
mxn = sz;
tr.assign(sz + 5, 0);
}
void upd(ll g, T k) {
g++;
assert(g != 0);
for (; g <= mxn; g += g&-g)
tr[g] += k;
}
T ge(ll g) {
g++;
T res = 0;
for (; g; g -= g&-g)
res += tr[g];
return res;
}
T rng(ll l, ll r) { return ge(r) - ge(l - 1); }
};
//var
ll T;
void solve() {
ll n, q;
cin >> n >> q;
vector<ll> ricky_y, ricky_x;
vector<array<ll, 3>> order;
F0R (i, n) {
ll x, y;
cin >> x >> y;
order.pb({1, x, y});
ricky_y.pb(y);
ricky_x.pb(x);
}
vector<ll> ans(q);
vector<array<ll, 3>> queries(q);
for (auto& [x, y, z] : queries)
cin >> x >> y >> z;
F0R (i, q) {
auto& [x, y, c] = queries[i];
order.pb({2, i, c});
ricky_y.pb(y);
ricky_x.pb(x);
}
sort(all(order), [&](const array<ll,3>& a, const array<ll,3>& b) {
ll ca = (a[0] == 1 ? a[1] + a[2] : a[2]);
ll cb = (b[0] == 1 ? b[1] + b[2] : b[2]);
if (ca == cb) return a[0] < b[0];
return ca > cb;
});
sort(all(ricky_y));
ricky_y.erase(unique(all(ricky_y)), ricky_y.end());
sort(all(ricky_x));
ricky_x.erase(unique(all(ricky_x)), ricky_x.end());
auto get_y = [&ricky_y](ll x) -> ll {
return lower_bound(all(ricky_y), x) - ricky_y.begin();
};
auto get_x = [&ricky_x](ll x) -> ll {
return lower_bound(all(ricky_x), x) - ricky_x.begin();
};
ll Y = (int)ricky_y.size();
ll X = (int)ricky_x.size();
debug(queries);
constexpr int B = 550;
vector active_points(X, vector<ll>());
for (ll query_start = 0; query_start < (int)order.size(); query_start += B) {
vector<array<ll, 3>> process_here;
for (int i = query_start; i < min((ll)order.size(), query_start + B); i++) {
process_here.pb(order[i]);
}
debug(process_here);
//local batch
for (int i = 0; i < (int)process_here.size(); i++) {
auto& [T1, a1, b1] = process_here[i];
for (int j = i + 1; j < (int)process_here.size(); j++) {
auto& [T2, a2, b2] = process_here[j];
if (T1 == 1 and T2 == 2) {
//T2 has a lesser line fo sho
auto& [gx, gy, line] = queries[a2];
if (a1 >= gx and b1 >= gy) {
ans[a2]++;
}
}
}
}
//global batch
//sort(all(active_points), greater<pii>());
int cur_pt = 0;
vector agg_by_x(X, vector<ll>());
for (auto [T, a1, b1] : process_here) if (T == 2) {
agg_by_x[get_x(queries[a1][0])].pb(a1);
}
fen<int> tree(Y);
ll big = 0;
for (int x = X - 1; x >= 0; x--) {
for (auto& y : active_points[x]) {
tree.upd(y, 1);
big++;
}
for (auto& qid : agg_by_x[x]) {
ll y = get_y(queries[qid][1]);
ans[qid] += big - tree.ge(y - 1);
}
}
//update global
for (auto& [T, a1, b1] : process_here) if (T == 1) {
active_points[get_x(a1)].pb(get_y(b1));
}
}
for (auto u : ans)
cout << u << '\n';
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
T = 1;
//cin >> T;
FOR(t, T)
solve();
cout.flush();
return 0;
}
Compilation message
examination.cpp: In function 'void solve()':
examination.cpp:44:20: warning: statement has no effect [-Wunused-value]
44 | #define debug(...) "zzz"
| ^~~~~
examination.cpp:144:5: note: in expansion of macro 'debug'
144 | debug(queries);
| ^~~~~
examination.cpp:44:20: warning: statement has no effect [-Wunused-value]
44 | #define debug(...) "zzz"
| ^~~~~
examination.cpp:154:9: note: in expansion of macro 'debug'
154 | debug(process_here);
| ^~~~~
examination.cpp:173:13: warning: unused variable 'cur_pt' [-Wunused-variable]
173 | int cur_pt = 0;
| ^~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
9 ms |
996 KB |
Output is correct |
8 |
Correct |
9 ms |
964 KB |
Output is correct |
9 |
Correct |
9 ms |
944 KB |
Output is correct |
10 |
Correct |
8 ms |
836 KB |
Output is correct |
11 |
Correct |
7 ms |
596 KB |
Output is correct |
12 |
Correct |
5 ms |
468 KB |
Output is correct |
13 |
Correct |
7 ms |
964 KB |
Output is correct |
14 |
Correct |
7 ms |
964 KB |
Output is correct |
15 |
Correct |
7 ms |
964 KB |
Output is correct |
16 |
Correct |
5 ms |
568 KB |
Output is correct |
17 |
Correct |
8 ms |
964 KB |
Output is correct |
18 |
Correct |
3 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1523 ms |
13804 KB |
Output is correct |
2 |
Correct |
1492 ms |
12744 KB |
Output is correct |
3 |
Correct |
1562 ms |
14136 KB |
Output is correct |
4 |
Correct |
708 ms |
13804 KB |
Output is correct |
5 |
Correct |
679 ms |
7676 KB |
Output is correct |
6 |
Correct |
209 ms |
7792 KB |
Output is correct |
7 |
Correct |
1399 ms |
11808 KB |
Output is correct |
8 |
Correct |
1508 ms |
12780 KB |
Output is correct |
9 |
Correct |
1297 ms |
11744 KB |
Output is correct |
10 |
Correct |
605 ms |
7552 KB |
Output is correct |
11 |
Correct |
511 ms |
13664 KB |
Output is correct |
12 |
Correct |
232 ms |
7280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1523 ms |
13804 KB |
Output is correct |
2 |
Correct |
1492 ms |
12744 KB |
Output is correct |
3 |
Correct |
1562 ms |
14136 KB |
Output is correct |
4 |
Correct |
708 ms |
13804 KB |
Output is correct |
5 |
Correct |
679 ms |
7676 KB |
Output is correct |
6 |
Correct |
209 ms |
7792 KB |
Output is correct |
7 |
Correct |
1399 ms |
11808 KB |
Output is correct |
8 |
Correct |
1508 ms |
12780 KB |
Output is correct |
9 |
Correct |
1297 ms |
11744 KB |
Output is correct |
10 |
Correct |
605 ms |
7552 KB |
Output is correct |
11 |
Correct |
511 ms |
13664 KB |
Output is correct |
12 |
Correct |
232 ms |
7280 KB |
Output is correct |
13 |
Correct |
1163 ms |
12760 KB |
Output is correct |
14 |
Correct |
1390 ms |
12740 KB |
Output is correct |
15 |
Correct |
1370 ms |
14084 KB |
Output is correct |
16 |
Correct |
668 ms |
12380 KB |
Output is correct |
17 |
Correct |
576 ms |
7792 KB |
Output is correct |
18 |
Correct |
210 ms |
7688 KB |
Output is correct |
19 |
Correct |
1239 ms |
12788 KB |
Output is correct |
20 |
Correct |
1378 ms |
12740 KB |
Output is correct |
21 |
Correct |
1139 ms |
12508 KB |
Output is correct |
22 |
Correct |
604 ms |
7544 KB |
Output is correct |
23 |
Correct |
520 ms |
13712 KB |
Output is correct |
24 |
Correct |
228 ms |
7296 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
9 ms |
996 KB |
Output is correct |
8 |
Correct |
9 ms |
964 KB |
Output is correct |
9 |
Correct |
9 ms |
944 KB |
Output is correct |
10 |
Correct |
8 ms |
836 KB |
Output is correct |
11 |
Correct |
7 ms |
596 KB |
Output is correct |
12 |
Correct |
5 ms |
468 KB |
Output is correct |
13 |
Correct |
7 ms |
964 KB |
Output is correct |
14 |
Correct |
7 ms |
964 KB |
Output is correct |
15 |
Correct |
7 ms |
964 KB |
Output is correct |
16 |
Correct |
5 ms |
568 KB |
Output is correct |
17 |
Correct |
8 ms |
964 KB |
Output is correct |
18 |
Correct |
3 ms |
468 KB |
Output is correct |
19 |
Correct |
1523 ms |
13804 KB |
Output is correct |
20 |
Correct |
1492 ms |
12744 KB |
Output is correct |
21 |
Correct |
1562 ms |
14136 KB |
Output is correct |
22 |
Correct |
708 ms |
13804 KB |
Output is correct |
23 |
Correct |
679 ms |
7676 KB |
Output is correct |
24 |
Correct |
209 ms |
7792 KB |
Output is correct |
25 |
Correct |
1399 ms |
11808 KB |
Output is correct |
26 |
Correct |
1508 ms |
12780 KB |
Output is correct |
27 |
Correct |
1297 ms |
11744 KB |
Output is correct |
28 |
Correct |
605 ms |
7552 KB |
Output is correct |
29 |
Correct |
511 ms |
13664 KB |
Output is correct |
30 |
Correct |
232 ms |
7280 KB |
Output is correct |
31 |
Correct |
1163 ms |
12760 KB |
Output is correct |
32 |
Correct |
1390 ms |
12740 KB |
Output is correct |
33 |
Correct |
1370 ms |
14084 KB |
Output is correct |
34 |
Correct |
668 ms |
12380 KB |
Output is correct |
35 |
Correct |
576 ms |
7792 KB |
Output is correct |
36 |
Correct |
210 ms |
7688 KB |
Output is correct |
37 |
Correct |
1239 ms |
12788 KB |
Output is correct |
38 |
Correct |
1378 ms |
12740 KB |
Output is correct |
39 |
Correct |
1139 ms |
12508 KB |
Output is correct |
40 |
Correct |
604 ms |
7544 KB |
Output is correct |
41 |
Correct |
520 ms |
13712 KB |
Output is correct |
42 |
Correct |
228 ms |
7296 KB |
Output is correct |
43 |
Correct |
2096 ms |
22588 KB |
Output is correct |
44 |
Correct |
2109 ms |
22636 KB |
Output is correct |
45 |
Correct |
2577 ms |
22476 KB |
Output is correct |
46 |
Correct |
1043 ms |
22260 KB |
Output is correct |
47 |
Correct |
625 ms |
11252 KB |
Output is correct |
48 |
Correct |
169 ms |
8556 KB |
Output is correct |
49 |
Correct |
2315 ms |
27344 KB |
Output is correct |
50 |
Correct |
2052 ms |
27504 KB |
Output is correct |
51 |
Correct |
2223 ms |
27232 KB |
Output is correct |
52 |
Correct |
547 ms |
11244 KB |
Output is correct |
53 |
Correct |
896 ms |
24216 KB |
Output is correct |