Submission #1127927

#TimeUsernameProblemLanguageResultExecution timeMemory
112792712345678Gift Exchange (JOI24_ho_t4)C++20
50 / 100
2594 ms3552 KiB
#include <bits/stdc++.h> using namespace std; const int nx=1e5+5; int n, q, a[nx], b[nx], l, r, mx, x[nx], y[nx], qs[2*nx]; vector<int> mp, v; int main() { cin.tie(NULL)->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]; cin>>q; while (q--) { cin>>l>>r; mp.clear(); for (int i=l; i<=r; i++) mp.push_back(a[i]), mp.push_back(b[i]); sort(mp.begin(), mp.end()); for (int i=l; i<=r; i++) x[i]=upper_bound(mp.begin(), mp.end(), a[i])-mp.begin(), y[i]=upper_bound(mp.begin(), mp.end(), b[i])-mp.begin(); for (int i=1; i<=2*n; i++) qs[i]=0; for (int i=l; i<=r; i++) qs[y[i]]++, qs[x[i]+1]--; for (int i=1; i<=2*n; i++) qs[i]+=qs[i-1]; int f=0; for (int i=l; i<=r; i++) { if (x[i]==y[i]+1&&qs[x[i]]==1) { f=1; cout<<"No\n"; break; } } if (!f) cout<<"Yes\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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...