Submission #1148937

#TimeUsernameProblemLanguageResultExecution timeMemory
1148937weakweakweakExamination (JOI19_examination)C++20
0 / 100
3094 ms24972 KiB
#include <bits/stdc++.h> using namespace std; using arr = array<int,4>; using pii = pair<int,int>; #define fs first #define sc second int n, q, ans[888888], a[888888] = {0}; void modify (int i, int x) { for (; i <= 400000; i+=i&-i) a[i] += x; } int query (int i) { int res = 0; for (; i > 0; i-=i&-i) res += a[i]; return res; } vector<arr> cdq (vector<arr> a) { if (a.size() == 1) return a; int mid = a.size()/2; vector<arr> b(a.begin(), a.begin()+mid), c(a.begin()+mid, a.end()), d; b = cdq(b), c = cdq(c); int j1 = 0, j2 = 0, cnt = 0; vector<pii> whatidid; for (arr x : c) if (x[3] == 0) cnt++; for (int i = 0; i < a.size(); i++) { if (j2 == c.size() or (j1 != b.size() and b[j1][1] <= c[j2][1])) { if (b[j1][3] != 0) { // if (b[j1][3] == -1) cout << "!" << ' ' << query(400000) << ' ' << query(b[j1][2]-1) << '\n'; ans[-b[j1][3]] -= query(400000)-query(b[j1][2]-1); } d.push_back(b[j1]); j1++; } else { if (c[j2][3] == 0) { cnt--; modify(c[j2][2], 1); whatidid.push_back(make_pair(c[j2][2], 1)); } d.push_back(c[j2]); j2++; } } // for (auto x : b) cout << x[0] << ' ' << x[1] << ' ' << x[2] << ' ' << x[3] << '\n'; // cout << '\n'; // for (auto x : c) cout << x[0] << ' ' << x[1] << ' ' << x[2] << ' ' << x[3] << '\n'; // cout << '\n'; for (auto x : b) if (x[3] != 0) { // if (x[3] == -1) cout << "!" << query(400000) << ' ' << query(x[2]-1) << ' ' << whatidid.size() << '\n'; ans[-x[3]] += query(400000)-query(x[2]-1); } // cout << "------------------------------------\n\n\n"; for (auto p : whatidid) modify(p.fs, -p.sc); return d; } int main() { // ios_base::sync_with_stdio(false); cin.tie(0); vector<arr> v; cin >> n >> q; for (int i = 1; i <= n; i++) { int x, y; cin >> x >> y; v.push_back({x, y, x+y, 0}); } for (int i = 1; i <= q; i++) { int a, b, c; cin >> a >> b >> c; v.push_back({a, b, c, -i}); } sort(v.begin(), v.end()); cdq(v); 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...