Submission #1278808

#TimeUsernameProblemLanguageResultExecution timeMemory
1278808shidou26Examination (JOI19_examination)C++20
100 / 100
234 ms14224 KiB
#include <bits/stdc++.h> using namespace std; #define endl '\n' #define fi first #define se second #define sz(v) (int)v.size() #define all(v) v.begin(), v.end() #define filter(v) v.resize(unique(all(v)) - v.begin()) #define dbg(x) "[" #x << " = " << (x) << "]" mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); template<typename T> bool maximize(T &a, T b) { if(a < b) { a = b; return true; }else return false; } template<typename T> bool minimize(T &a, T b) { if(a > b) { a = b; return true; }else return false; } template<typename T1, typename T2> T2 rnd(T1 l, T2 r) { return uniform_int_distribution<T2>(l, r)(rng); } typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, int> pli; typedef pair<ll, ll> pll; typedef tuple<int, int, int> tpl; const int N = 1e5 + 3; int n, q; pii pic[N]; tpl query[N]; void input() { cin >> n >> q; for(int i = 1; i <= n; i++) { cin >> pic[i].fi >> pic[i].se; } for(int i = 1; i <= q; i++) { int x, y, z; cin >> x >> y >> z; query[i] = {x, y, z}; } } namespace subtask_1 { bool approve() { return max(n, q) <= 3000; } void execute() { for(int i = 1; i <= q; i++) { int x, y, z; tie(x, y, z) = query[i]; int answer = 0; for(int j = 1; j <= n; j++) { int s, t; tie(s, t) = pic[j]; if(s + t >= z && s >= x && t >= y) answer++; } cout << answer << endl; } } } namespace subtask_4 { bool approve() { return true; } struct FenwickTree { vector<int> bit; FenwickTree (int n) : bit(n + 3) {} void update(int p, int v) { for(; p > 0; p -= p & -p) bit[p] += v; } int get(int p) { int total = 0; for(; p < sz(bit); p += p & -p) total += bit[p]; return total; } }; struct Deeto { int z, id, x, y; }; bool cmp(Deeto a, Deeto b) { if(a.z == b.z) { return a.id < b.id; }else return a.z > b.z; } bool another(Deeto a, Deeto b) { return a.x > b.x; } int answer[N]; vector<int> cps; vector<Deeto> shidou; int compress(int x) { return lower_bound(all(cps), x) - cps.begin() + 1; } void solve(int l, int r, FenwickTree &bit) { if(l >= r) return; int mid = (l + r) >> 1; vector<Deeto> updates, queries; for(int i = l; i <= mid; i++) { if(shidou[i].id == -1) updates.push_back(shidou[i]); } for(int i = mid + 1; i <= r; i++) { if(shidou[i].id != -1) queries.push_back(shidou[i]); } vector<int> save; sort(all(updates), another); sort(all(queries), another); int j = 0; for(Deeto it : queries) { while(j < sz(updates) && updates[j].x >= it.x) { bit.update(updates[j].y, 1); save.push_back(updates[j].y); j++; } answer[it.id] += bit.get(it.y); } while(!save.empty()) { bit.update(save.back(), -1); save.pop_back(); } solve(l, mid, bit); solve(mid + 1, r, bit); } void execute() { for(int i = 1; i <= n; i++) { int s, t; tie(s, t) = pic[i]; cps.push_back(t); shidou.push_back({s + t, -1, s, t}); } for(int i = 1; i <= q; i++) { int x, y, z; tie(x, y, z) = query[i]; cps.push_back(y); shidou.push_back({z, i, x, y}); } sort(all(cps)); filter(cps); for(int i = 0; i < sz(shidou); i++) { shidou[i].y = compress(shidou[i].y); } sort(all(shidou), cmp); // for(Deeto it : shidou) // cout << it.z << " " << it.id << " " << it.x << " " << it.y << endl; FenwickTree bit(sz(cps)); solve(0, sz(shidou) - 1, bit); for(int i = 1; i <= q; i++) { cout << answer[i] << endl; } } } void process() { // if(subtask_1::approve()) return subtask_1::execute(); if(subtask_4::approve()) return subtask_4::execute(); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int testcase = 1; // cin >> testcase; for(int i = 1; i <= testcase; i++) { input(); process(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...