Submission #973566

#TimeUsernameProblemLanguageResultExecution timeMemory
973566vjudge1Passport (JOI23_passport)C++17
0 / 100
2050 ms11280 KiB
#include <time.h> #include <cstdlib> #include <stack> #include <numeric> #include <unordered_map> #include <unordered_set> #include <iomanip> #include <map> #include <set> #include <iterator> #include <deque> #include <queue> #include <sstream> #include <array> #include <string> #include <tuple> #include <chrono> #include <cassert> #include <cstdio> #include <cstring> #include <list> #include <iostream> #include <vector> #include <cmath> #include <algorithm> #include <bitset> using namespace std; int tt = 1, n; int a[200005], lf[200005], rg[200005]; int mn[4 * 200005], mx[4 * 200005]; void up(int l, int r, int pos, int num, int num1, int vv){ if(l > pos || r < pos) return; if(l == r){ mn[vv] = num; mx[vv] = num1; return; } int mid = (l + r) / 2; up(l, mid, pos, num, num1, vv * 2); up(mid + 1, r, pos, num, num1, vv * 2 + 1); mn[vv] = min(mn[vv * 2], mn[vv * 2 + 1]); mx[vv] = max(mx[vv * 2], mx[vv * 2 + 1]); } int sbor(int l, int r, int l1, int r1, int vv){ if(l > r1 || l1 > r) return 1e9; if(l >= l1 && r1 >= r) return mn[vv]; int mid = (l + r) / 2; return min(sbor(l, mid, l1, r1, vv * 2), sbor(mid + 1, r, l1, r1, vv * 2 + 1)); } int sbor1(int l, int r, int l1, int r1, int vv){ if(l > r1 || l1 > r) return 0; if(l >= l1 && r1 >= r) return mx[vv]; int mid = (l + r) / 2; return max(sbor1(l, mid, l1, r1, vv * 2), sbor1(mid + 1, r, l1, r1, vv * 2 + 1)); } int main(){ ios::sync_with_stdio(0); cin.tie(0), cout.tie(0); cin >> n; for(int i = 1; i <= n; i++){ cin >> lf[i] >> rg[i]; up(1, n, i, lf[i], rg[i], 1); } cin >> tt; while(tt--){ int x; cin >> x; int l = x, r = x, l1 = x, r1 = x, k = 0; bool ok = 0; while(l != 1 || r != n){ int mn1 = sbor(1, n, l, r, 1); int mx1 = sbor1(1, n, l, r, 1); l = mn1, r = mx1; k++; if(l == l1 && r == r1){ ok = 1; break; } } if(ok) cout << -1 << "\n"; else cout << k << "\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...