제출 #1257502

#제출 시각아이디문제언어결과실행 시간메모리
1257502inkvizytorExamination (JOI19_examination)C++20
100 / 100
232 ms85188 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long void add_children(int v, vector<int> &tr, vector<pair<int, int>> &s) { if (s[v].first != -1) { return; } s[v].first = tr.size(), s[v].second = tr.size()+1; tr.push_back(0); tr.push_back(0); s.push_back({-1, -1}); s.push_back({-1, -1}); } void add (int v, vector<int> &tr, vector<pair<int, int>> &s, int p, int k, int a) { tr[v]++; if (p == k) { return; } add_children(v, tr, s); if (a <= (p+k)/2) { add(s[v].first, tr, s, p, (p+k)/2, a); } else { add(s[v].second, tr, s, (p+k)/2+1, k, a); } } int query (int v, vector<int> &tr, vector<pair<int, int>> &s, int p, int k, int a, int b) { if (v == -1) { return 0; } if (a <= p && k <= b) { return tr[v]; } if (a > k || b < p) { return 0; } return query(s[v].first, tr, s, p, (p+k)/2, a, b)+query(s[v].second, tr, s, (p+k)/2+1, k, a, b); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, q; cin >> n >> q; vector<pair<int, pair<int, int>>> p (n); for (int i = 0; i < n; i++) { cin >> p[i].second.first >> p[i].second.second; p[i].first = p[i].second.first+p[i].second.second; } sort(p.begin(), p.end(), greater<pair<int, pair<int, int>>>()); vector<pair<pair<int, int>, pair<int, int>>> z (q); for (int i = 0; i < q; i++) { cin >> z[i].second.first >> z[i].second.second >> z[i].first.first; z[i].first.first = max(z[i].first.first, z[i].second.first+z[i].second.second); z[i].first.second = i; } sort(z.begin(), z.end(), greater<pair<pair<int, int>, pair<int, int>>>()); vector<int> tx = {0}, ty = {0}; vector<pair<int, int>> sx = {{-1, -1}}, sy = {{-1, -1}}; int in = 0; vector<int> w (q, 0); for (auto x : z) { while (in < n && p[in].first >= x.first.first) { add(0, tx, sx, 0, (1<<30)-1, p[in].second.first); add(0, ty, sy, 0, (1<<30)-1, p[in].second.second); in++; } w[x.first.second] = in-query(0, tx, sx, 0, (1<<30)-1, 0, x.second.first-1)-query(0, ty, sy, 0, (1<<30)-1, 0, x.second.second-1); } for (int i : w) { cout << 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...