Submission #871151

#TimeUsernameProblemLanguageResultExecution timeMemory
871151LOLOLOExamination (JOI19_examination)C++14
100 / 100
567 ms35580 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define f first #define s second #define pb push_back #define ep emplace #define eb emplace_back #define lb lower_bound #define ub upper_bound #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define uniquev(v) sort(all(v)), (v).resize(unique(all(v)) - (v).begin()) #define mem(f,x) memset(f , x , sizeof(f)) #define sz(x) (int)(x).size() #define __lcm(a, b) (1ll * ((a) / __gcd((a), (b))) * (b)) #define mxx *max_element #define mnn *min_element #define cntbit(x) __builtin_popcountll(x) #define len(x) (int)(x.length()) const int N = 8e5 + 100; vector < vector <int>> st; int f[N], ans[N]; void upd(int i, int x) { for (; i < N; i += i & (-i)) f[i] += x; } int get(int i) { int s = 0; for (; i; i -= i & (-i)) s += f[i]; return s; } void dnc(int l, int r) { if (l == r) return; int m = (l + r) / 2; dnc(l, m); dnc(m + 1, r); vector < vector <int>> save; for (int i = l; i <= m; i++) { if (st[i][3] == -1) { save.pb({st[i][1], st[i][2], -1}); } } for (int i = m + 1; i <= r; i++) { if (st[i][3] != -1) { save.pb({st[i][1], st[i][2], st[i][3]}); } } sort(all(save)); for (auto x : save) { if (x[2] == -1) { upd(x[1], 1); } else { ans[x[2]] += get(x[1]); } } for (auto x : save) { if (x[2] == -1) { upd(x[1], -1); } } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, q; cin >> n >> q; vector <int> coor; coor.pb((int)-4e9); for (int i = 1; i <= n; i++) { int s, t; cin >> s >> t; st.pb({-s, -t, -s - t, -1}); coor.pb(-s); coor.pb(-t); coor.pb(-s - t); } for (int i = 1; i <= q; i++) { int a, b, c; cin >> a >> b >> c; a = -a, b = -b, c = -c; coor.pb(a), coor.pb(b), coor.pb(c); st.pb({a, b, c, i}); } sort(all(coor)); uniquev(coor); for (auto &x : st) { for (int j = 0; j < 3; j++) { x[j] = lower_bound(all(coor), x[j]) - coor.begin(); } } sort(all(st)); dnc(0, n + q - 1); 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...