Submission #1237585

#TimeUsernameProblemLanguageResultExecution timeMemory
1237585orzngaihaExamination (JOI19_examination)C++20
43 / 100
494 ms51012 KiB
#include <bits/stdc++.h> #define int long long using namespace std; const int N = 1e5 + 5; int n, q, m; pair<int, int> a[N], c[N]; struct Edge { int l, r, z, id; }; vector<Edge> d; int kq[N]; bool cmp(pair<int, int>& a, pair<int, int>& b) { return a.first + a.second > b.first + b.second; } bool cmp1(Edge& a, Edge& b) { return a.z > b.z; } vector<int> pos[N], bit[N]; void Add1(int x, int y) { for (int i = x; i <= m; i += i & -i) pos[i].push_back(y); } void Get1(int x, int y) { for (int i = x; i > 0; i -= i & -i) pos[i].push_back(y); } void pre() { for (int i = 1; i <= m; i++) { pos[i].push_back(0); sort(pos[i].begin(), pos[i].end()); pos[i].erase(unique(pos[i].begin(), pos[i].end()), pos[i].end()); bit[i].assign(pos[i].size(), 0); } } void update(int x, int y, int v) { for (int i = x; i <= m; i += i & -i) { int j = lower_bound(pos[i].begin(), pos[i].end(), y) - pos[i].begin(); for (; j < bit[i].size(); j += j & -j) { bit[i][j] += v; } } } int get(int x, int y) { int res = 0; for (int i = x; i > 0; i -= i & -i) { int j = lower_bound(pos[i].begin(), pos[i].end(), y) - pos[i].begin(); for (; j > 0; j -= j & -j) { res += bit[i][j]; } } return res; } signed main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> q; vector<int> b; for (int i = 1; i <= n; i++) { cin >> a[i].first >> a[i].second; b.push_back(a[i].first); b.push_back(a[i].second); } d.resize(q + 1); for (int i = 1; i <= q; i++) { cin >> d[i].l >> d[i].r >> d[i].z; d[i].id = i; b.push_back(d[i].l); b.push_back(d[i].r); } sort(a + 1, a + 1 + n, cmp); sort(b.begin(), b.end()); b.erase(unique(b.begin(), b.end()), b.end()); m = b.size(); for (int i = 1; i <= n; i++) { int x = lower_bound(b.begin(), b.end(), a[i].first) - b.begin() + 1; int y = lower_bound(b.begin(), b.end(), a[i].second) - b.begin() + 1; c[i].first = m - x + 1; c[i].second = m - y + 1; Add1(c[i].first, c[i].second); } for (int i = 1; i <= q; i++) { int x = lower_bound(b.begin(), b.end(), d[i].l) - b.begin() + 1; int y = lower_bound(b.begin(), b.end(), d[i].r) - b.begin() + 1; d[i].l = m - x + 1; d[i].r = m - y + 1; Get1(d[i].l, d[i].r); } pre(); sort(d.begin() + 1, d.end(), cmp1); int t = 1; for (int i = 1; i <= q; i++) { while (t <= n && a[t].first + a[t].second >= d[i].z) { update(c[t].first, c[t].second, 1); t++; } kq[d[i].id] = get(d[i].l, d[i].r); } for (int i = 1; i <= q; i++) cout << kq[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...