Submission #946344

#TimeUsernameProblemLanguageResultExecution timeMemory
946344vqpahmadExamination (JOI19_examination)C++14
0 / 100
192 ms16324 KiB
#include<bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #ifdef ONPC #include"debug.h" #else #define debug(...) 42 #endif #define endl '\n' #define ll long long #define pii pair<int,int> #define F first #define S second #define pb push_back #define sz(a) (int)a.size() #define all(a) a.begin(),a.end() template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; } template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } const int mod = 1e9 + 7; const int MAXN = 1e6 + 15; const int inf = 0x3f3f3f3f; const ll INF = 0x3f3f3f3f3f3f3f3f; int ans[MAXN]; template<class T> using order_set = tree<T, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update>; struct point { int x, y; }; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n, q; cin >> n >> q; vector<point> a(n); vector<ll> b(n); for (int i = 0; i < n; i++){ cin >> a[i].x >> a[i].y; b[i] = a[i].x + a[i].y; } sort(all(b)); vector<array<int, 3>> queries(q); vector<array<int, 3>> queriesA(q); vector<array<int, 3>> queriesB(q); for (int i = 0; i < q; i++){ cin >> queries[i][0] >> queries[i][1] >> queries[i][2]; queries[i][2] = max(queries[i][2], queries[i][0] + queries[i][1]); queriesA[i] = {queries[i][2], queries[i][0], i}; queriesB[i] = {queries[i][2], queries[i][1], i}; ans[i] += lower_bound(all(b), queries[i][2]) - b.begin(); } sort(all(queriesA), greater<>()); sort(all(queriesB), greater<>()); sort(all(a), [](point lh, point rh){ return lh.x + lh.y > rh.x + rh.y; }); int p = 0; order_set<pii> st; for (int i = 0; i < q; i++){// solve for b while (p < n && a[p].x + a[p].y > queriesA[i][0]){ st.insert({a[p].x, p}); p++; } ans[queriesA[i][2]] += st.order_of_key({queriesA[i][1], -1}); } st.clear(); p = 0; for (int i = 0; i < q; i++){// solve for b while (p < n && a[p].x + a[p].y > queriesB[i][0]){ st.insert({a[p].y, p}); p++; } ans[queriesB[i][2]] += st.order_of_key({queriesB[i][1], -1}); } for (int i = 0; i < q; i++){ cout << n - ans[i] << endl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...