제출 #839415

#제출 시각아이디문제언어결과실행 시간메모리
839415vjudge1Examination (JOI19_examination)C++17
100 / 100
688 ms42124 KiB
#include <bits/stdc++.h> #define pb push_back #define fi first #define se second using namespace std; typedef long long ll; const int maxn = 2e5 + 5; int n, q; vector<pair<pair<int, int>, int>> s; vector<int> poi; vector<int> poi1; struct BIT2D { vector<int> po[maxn]; vector<int> bit[maxn]; void pre_upd(int x, int y) { for (int i = x; i >= 1; i -= i & (-i)) { po[i].pb(y); } } void pre_get(int x, int y) { for (int i = x; i <= (int)(poi.size()); i += i & (-i)) { po[i].pb(y); } } void init() { for (int i = 1; i <= (int)(poi.size()); i++) { sort(po[i].begin(), po[i].end()); po[i].resize(unique(po[i].begin(), po[i].end()) - po[i].begin()); bit[i].resize(po[i].size() + 1, 0); } } void upd(int x, int y) { for (int i = x; i >= 1; i -= i & (-i)) { int id = lower_bound(po[i].begin(), po[i].end(), y) - po[i].begin() + 1; for (int j = id; j >= 1; j -= j & (-j)) { bit[i][j] += 1; } } } int calc(int x, int y) { int res = 0; for (int i = x; i <= (int)(poi.size()); i += i & (-i)) { int id = lower_bound(po[i].begin(), po[i].end(), y) - po[i].begin() + 1; for (int j = id; j < (int)(bit[i].size()); j += j & (-j)) { res += bit[i][j]; } } return res; } } DS; bool cmp(pair<pair<int, int>, int> a, pair<pair<int, int>, int> b) { if (a.fi.fi == b.fi.fi) return a.se > b.se; return a.fi.fi < b.fi.fi; } int X[maxn]; int Y[maxn]; int A[maxn], B[maxn], C[maxn]; int ans[maxn]; signed main() { // freopen("input.inp", "r", stdin); // freopen("output.out", "w", stdout); cin.tie(0), cout.tie(0)->sync_with_stdio(0); cin >> n >> q; for (int i = 1; i <= n; i++) { int x, y; cin >> x >> y; poi.pb(y); poi1.pb(x + y); X[i] = x; Y[i] = y; s.pb({{x, i}, 0}); } for (int i = 1; i <= q; i++) { int a, b, c; cin >> a >> b >> c; A[i] = a; B[i] = b; C[i] = c; poi.pb(b); poi1.pb(c); s.pb({{a, i}, 1}); } sort(poi.begin(), poi.end()); sort(poi1.begin(), poi1.end()); poi.resize(unique(poi.begin(), poi.end()) - poi.begin()); poi1.resize(unique(poi1.begin(), poi1.end()) - poi1.begin()); for (int i = 1; i <= n; i++) { int c = lower_bound(poi.begin(), poi.end(), Y[i]) - poi.begin() + 1; int d = lower_bound(poi1.begin(), poi1.end(), X[i]+Y[i]) - poi1.begin() + 1; DS.pre_upd(c, d); } for (int i = 1; i <= q; i++) { int b = lower_bound(poi.begin(), poi.end(), B[i]) - poi.begin() + 1; int c = lower_bound(poi1.begin(), poi1.end(), C[i]) - poi1.begin() + 1; DS.pre_get(b, c); } sort(s.begin(), s.end(),cmp); DS.init(); for (int i = (int)(s.size()) - 1; i >= 0; i--) { int id = s[i].fi.se; int type = s[i].se; if (type == 0) { int c = lower_bound(poi.begin(), poi.end(), Y[id]) - poi.begin() + 1; int d = lower_bound(poi1.begin(), poi1.end(), X[id]+Y[id]) - poi1.begin() + 1; DS.upd(c, d); } else { int b = lower_bound(poi.begin(), poi.end(), B[id]) - poi.begin() + 1; int c = lower_bound(poi1.begin(), poi1.end(), C[id]) - poi1.begin() + 1; ans[id] = DS.calc(b, c); } } for (int i = 1; i <= q; i++) { cout << ans[i] << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...