Submission #1157115

#TimeUsernameProblemLanguageResultExecution timeMemory
1157115mychecksedadGift Exchange (JOI24_ho_t4)C++20
9 / 100
2598 ms1260 KiB
/* Author : Mychecksdead */ #include<bits/stdc++.h> using namespace std; #define ll long long int #define MOD (1000000000+7) #define MOD1 (998244353) #define pb push_back #define all(x) x.begin(), x.end() #define en cout << '\n' #define ff first #define ss second #define pii pair<int,int> #define vi vector<int> const int N = 1e6+100, M = 1e5+10, K = 52, MX = 30; int n, q, pos[N]; array<int, 2> a[N], bad[N]; void solve(){ cin>> n; for(int i = 1; i <= n; ++i){ cin >> a[i][0]; } for(int i = 1; i <= n; ++i){ cin >> a[i][1]; } for(int i = 1; i <= n; ++i){ int L = 1, R = n; for(int j = 1; j <= n; ++j){ if(a[j][0] < a[i][0] && a[j][0] > a[i][1]){ if(j < i) L = max(L, j + 1); if(j > i) R = min(R, j - 1); } } bad[i] = {L, R}; for(int j = 1; j <= n; ++j){ if(a[j][0] > a[i][0] && a[j][1] < a[i][0]){ if(j < i) L = max(L, j + 1); if(j > i) R = min(R, j - 1); } } bad[i][0] = max(bad[i][0], L); bad[i][1] = min(bad[i][1], R); } cin >> q; for(;q--;){ int l, r;cin >> l >> r; bool ok = 1; for(int j = l; j <= r; ++j){ if(bad[j][0] <= l && r <= bad[j][1]){ ok =0 ; } } if(ok) cout << "Yes\n"; else cout << "No\n"; } } int main(){ cin.tie(0); ios::sync_with_stdio(0); int tt = 1, aa; // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); while(tt--){ solve(); } cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" seconds\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...