제출 #1166789

#제출 시각아이디문제언어결과실행 시간메모리
1166789thinknoexitGift Exchange (JOI24_ho_t4)C++20
50 / 100
2596 ms47816 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; const int N = 500005; // precompute //-------------------- int tree1[8 * N], lazy1[8 * N]; int a[N], b[N], L[N], R[N], n; bool SS_ = 0; int op(int a, int b) { if (SS_) return min(a, b); return max(a, b); } void lzy(int now, int l, int r) { if (lazy1[now] == 0 || lazy1[now] >= 1e9) return; tree1[now] = op(tree1[now], lazy1[now]); if (l != r) { lazy1[2 * now] = op(lazy1[2 * now], lazy1[now]); lazy1[2 * now + 1] = op(lazy1[2 * now + 1], lazy1[now]); } if (SS_) lazy1[now] = 1e9; else lazy1[now] = 0; } void update1(int ql, int qr, int w, int now = 1, int l = 1, int r = 2 * n) { lzy(now, l, r); if (l > qr || r < ql) return; if (ql <= l && r <= qr) { lazy1[now] = w; lzy(now, l, r); return; } int mid = (l + r) / 2; update1(ql, qr, w, 2 * now, l, mid), update1(ql, qr, w, 2 * now + 1, mid + 1, r); tree1[now] = op(tree1[2 * now], tree1[2 * now + 1]); } int query1(int ql, int qr, int now = 1, int l = 1, int r = 2 * n) { lzy(now, l, r); if (ql <= l && r <= qr) return tree1[now]; int mid = (l + r) / 2; if (qr <= mid) return query1(ql, qr, 2 * now, l, mid); if (ql > mid) return query1(ql, qr, 2 * now + 1, mid + 1, r); return op(query1(ql, qr, 2 * now, l, mid), query1(ql, qr, 2 * now + 1, mid + 1, r)); } //------------------------- bool ans[N]; vector<pair<int, int>> Q[N]; int main() { cin.tie(nullptr)->sync_with_stdio(false); cin >> n; for (int i = 1;i <= n;i++) cin >> a[i]; for (int i = 1;i <= n;i++) cin >> b[i]; for (int i = 1;i <= n;i++) { L[i] = query1(b[i], a[i]); update1(b[i], a[i], i); } memset(tree1, 0x3f, sizeof tree1); memset(lazy1, 0x3f, sizeof lazy1); SS_ = 1; for (int i = n;i >= 1;i--) { R[i] = min(n + 1, query1(b[i], a[i])); update1(b[i], a[i], i); } // for (int i = 1;i <= n;i++) { // cout << L[i] << ' ' << R[i] << '\n'; // } int q; cin >> q; for (int i = 1;i <= q;i++) { int l, r; cin >> l >> r; Q[r].push_back({ l, i }); } for (int i = 1;i <= n;i++) { for (auto& [l, idx] : Q[i]) { ans[idx] = 1; for (int j = l;j <= i;j++) { if (L[j] < l && R[j] > i) ans[idx] = 0; } } } for (int i = 1;i <= q;i++) { if (ans[i]) cout << "Yes\n"; else cout << "No\n"; } 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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...