Submission #1307758

#TimeUsernameProblemLanguageResultExecution timeMemory
1307758mikolaj00Examination (JOI19_examination)C++20
0 / 100
3107 ms441096 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; ll const MAX_VAL = 2e9+1; struct BIT_2D { BIT_2D(int size) : arr(size) {} void update(ll x, ll y) { for (ll i = x; i <= arr.size(); i |= i+1) for (ll j = y; j <= MAX_VAL; j |= j+1) arr[i][j]++; } ll query_pref(ll x, ll y) { ll res = 0; for (ll i = x; i >= 0; i = (i & (i+1))-1) for (ll j = y; j >= 0; j = (j & (j+1))-1) { res += arr[i][j]; } return res; } ll query(ll i, ll j) { ll res = query_pref(arr.size()-1, MAX_VAL); if (i > 0) res -= query_pref(i-1, MAX_VAL); if (j > 0) res -= query_pref(arr.size()-1, j-1); if (i > 0 && j > 0) res += query_pref(i-1, j-1); return res; } vector<unordered_map<ll, ll>> arr; }; struct Sweep { ll x, y, z; int idx; friend bool operator<(Sweep const& s1, Sweep const& s2) { return make_pair(s1.z, -s1.idx) > make_pair(s2.z, -s2.idx); } }; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n, q; cin >> n >> q; set<ll> x_vals; vector<ll> s(n), t(n); for (int i = 0; i < n; i++) { cin >> s[i] >> t[i]; x_vals.insert(s[i]); } vector<ll> x(q), y(q), z(q); for (int i = 0; i < q; i++) { cin >> x[i] >> y[i] >> z[i]; x_vals.insert(x[i]); } int cnt = 0; map<ll, int> val_to_id; for (auto x_vals_i : x_vals) val_to_id[x_vals_i] = cnt++; vector<Sweep> sweep; sweep.reserve(n+q); for (int i = 0; i < n; i++) sweep.push_back({s[i], t[i], s[i]+t[i], -1}); for (int i = 0; i < q; i++) sweep.push_back({x[i], y[i], z[i], i}); sort(sweep.begin(), sweep.end()); BIT_2D bit(x_vals.size()); vector<ll> ans(q); for (auto s : sweep) { if (s.idx == -1) { bit.update(val_to_id[s.x], s.y); } else ans[s.idx] = bit.query(val_to_id[s.x], s.y); } for (auto ans_i : ans) 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...