#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define str string
#define int long long
#define ll long long
#define ld long double
#define pb push_back
#define F first
#define S second
#define all(x) x.begin() , x.end()
#define setpr(x) cout << fixed << setprecision(x)
#define endl '\n'
const int inf = INT_MAX;
const ld eps = 1e-9 , pi = acos(-1.0);
const ll mod = 1e9 + 7; // 998244353;
const int dx[4]{1 , 0 , -1 , 0} , dy[4]{0 , 1 , 0 , -1};
/*
T_ai <= T_bi -->
ai < bi --> S_(ai + 1 , bi) <= S_(ai , bi - 1)
ai > bi --> S_(bi + 1 , ai) >= S_(bi , ai - 1)
*/
void solution(){
int n , x; cin >> n;
vector<pair<int , int>> bu(n);
for(int i = 0 ; i < n ; i ++) cin >> bu[i].F >> bu[i].S;
int q; cin >> q;
while(q --) cin >> x;
int l = bu[x - 1].F , r = bu[x - 1].S , h = 1;
if(r == n){
cout << 1; return;
}
int mx = 0;
for(int i = 0 ; i < n ; i ++){
for(int i = l ; i <= r ; i ++) mx = max(mx , bu[i - 1].S);
if(mx == r){
cout << -1; return;
}
l = r + 1;
r = mx;
h ++;
if(r == n){
cout << h; return;
}
}
}
signed main(){
IOS;
int t = 1; // cin >> t;
while(t --) solution();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
23 ms |
3420 KB |
Output is correct |
5 |
Correct |
23 ms |
3672 KB |
Output is correct |
6 |
Correct |
23 ms |
3420 KB |
Output is correct |
7 |
Correct |
19 ms |
3420 KB |
Output is correct |
8 |
Correct |
16 ms |
2908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
23 ms |
3420 KB |
Output is correct |
5 |
Correct |
23 ms |
3672 KB |
Output is correct |
6 |
Correct |
23 ms |
3420 KB |
Output is correct |
7 |
Correct |
19 ms |
3420 KB |
Output is correct |
8 |
Correct |
16 ms |
2908 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |