제출 #957536

#제출 시각아이디문제언어결과실행 시간메모리
957536aykhnExhibition (JOI19_ho_t2)C++17
0 / 100
0 ms348 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define inf 0x3F3F3F3F vector<int> st; void make(int l, int r, int x, int ind, int val) { if (l + 1 == r) { st[x] = max(st[x], val); return; } int mid = (l + r) >> 1; if (ind < mid) make(l, mid, 2*x + 1, ind, val); else make(mid, r, 2*x + 2, ind, val); st[x] = max(st[2*x + 1], st[2*x + 2]); } int get(int l, int r, int x, int lx, int rx) { if (l >= rx || r <= lx) return 0; if (l >= lx && r <= rx) return st[x]; int mid = (l + r) >> 1; return max(get(l, mid, 2*x + 1, lx, rx), get(mid, r, 2*x + 2, lx, rx)); } signed main() { ios_base::sync_with_stdio(0); cin.tie(nullptr); int n, m, sz = 1; cin >> n >> m; while (sz < 50) sz <<= 1; st.assign(sz << 1, 0); int b[m]; array<int, 2> a[n]; vector<int> mp; for (array<int, 2> &x : a) { cin >> x[0] >> x[1]; mp.push_back(x[0]); mp.push_back(x[1]); } for (int &i : b) { cin >> i; mp.push_back(i); } sort(mp.begin(), mp.end()); mp.resize(unique(mp.begin(), mp.end()) - mp.begin()); for (array<int, 2> &x : a) x[0] = lower_bound(mp.begin(), mp.end(), x[0]) - mp.begin(), x[1] = lower_bound(mp.begin(), mp.end(), x[1]) - mp.begin(); for (int &i : b) i = lower_bound(mp.begin(), mp.end(), i) - mp.begin(); sort(b, b + m); sort(a, a + n); int j = n - 1; for (int i = m - 1; i >= 0;) { int x = b[i]; while (i >= 0 && b[i] == x) i--; int mx = m - i - 2; while (j >= 0 && a[j][0] >= x) { if (a[j][0] <= b[m - 1]) { make(0, sz, 0, a[j][1], min(mx, get(0, sz, 0, a[j][1], sz) + 1)); } j--; } } cout << get(0, sz, 0, 0, sz) << '\n'; } // 15 2 19 3 0 18 5 9 // 4 11 12 13 14 17 21 22 // 1 6 7 8 10 16 20 23
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...