Submission #1107854

#TimeUsernameProblemLanguageResultExecution timeMemory
1107854_callmelucianGift Exchange (JOI24_ho_t4)C++14
50 / 100
2594 ms6808 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll,ll> pl; typedef pair<int,int> pii; typedef tuple<int,int,int> tt; #define all(a) a.begin(), a.end() #define filter(a) a.erase(unique(all(a)), a.end()) bool solve (vector<int> a, vector<int> b, int n) { vector<int> pa(n), pb(n); for (int i = 0; i < n; i++) pa[i] = pb[i] = i; sort(all(pa), [&] (int i, int j) { return a[i] < a[j]; }); sort(all(pb), [&] (int i, int j) { return b[i] < b[j]; }); for (int i = 0; i < n; i++) { if (pa[i] == pb[i]) { if (i - 1 >= 0 && a[pa[i - 1]] > b[pb[i]]) continue; if (i + 1 < n && a[pa[i]] > b[pb[i + 1]]) continue; return 0; } if (a[pa[i]] < b[pb[i]]) return 0; } return 1; } const int mn = 5e5 + 5; int a[mn], b[mn]; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) cin >> b[i]; int q; cin >> q; while (q--) { int l, r; cin >> l >> r; vector<int> vec_a, vec_b; for (int i = l; i <= r; i++) { vec_a.push_back(a[i]); vec_b.push_back(b[i]); } cout << (solve(vec_a, vec_b, r - l + 1) ? "Yes" : "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...