#include<bits/stdc++.h>
#include<fstream>
using namespace std;
#define sz(a) (int)a.size()
#define ALL(v) v.begin(), v.end()
#define ALLR(v) v.rbegin(), v.rend()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
#define mpp make_pair
const ld PI = 3.14159265359, prec = 1e-9;;
//using u128 = __uint128_t;
//const int x[4] = {1, 0, -1, 0};
//const int y[4] = {0, -1, 0, 1};
const ll mod =1e9 + 7, pr = 31;
const int mxn = 5e5 + 5, mxq = 1e5 + 5, sq = 500, mxv = 5e4 + 1;
//const int base = (1 <<18);
const ll inf = 1e13 + 5, neg = -69420, inf2 = 1e14;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
// have fun!
int n, k, q;
int a[mxn + 1], nxt[mxn + 1], c[mxn + 1];
vt<pii>adj[mxn + 1];
bool cyc;
void dfs(int s, int l, int r){
c[s] = 1;
for(auto [v, id]: adj[s]){
if(id < l || id >= r)continue;
if(c[v] == 1)cyc = 1;
else if(c[v] == 0){
dfs(v, l, r);
}
}
c[s] = 2;
}
bool check(int l, int r){
for(int i = 1; i <= n; i++){
c[i] = 0;
}
cyc = 0;
for(int i = 1; i <= n; i++){
if(!c[i])dfs(i, l, r);
}
return(!cyc);
}
void solve(){
cin >> n >> k >> q;
for(int i = 1; i <= n; i++)cin >> a[i];
for(int i = 1; i < n; i++){
if(i & 1)adj[a[i]].pb(mpp(a[i + 1], i));
else adj[a[i + 1]].pb(mpp(a[i], i));
}
int r = 1;
for(int i = 1; i <= n; i++){
while(r < n && check(i, r + 1))r++;
nxt[i] = r;
}
while(q--){
int l, r; cin >> l >> r;
cout << ((nxt[l] >= r) ? "YES" : "NO") << "\n";
}
}
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//freopen("THREE.inp", "r", stdin);
//freopen("THREE.out", "w", stdout);
int tt; tt = 1;
while(tt--){
solve();
}
return(0);
}
Compilation message
Main.cpp: In function 'void dfs(int, int, int)':
Main.cpp:35:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
35 | for(auto [v, id]: adj[s]){
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
219 ms |
29268 KB |
Output is correct |
2 |
Correct |
221 ms |
29392 KB |
Output is correct |
3 |
Correct |
227 ms |
29392 KB |
Output is correct |
4 |
Correct |
123 ms |
23800 KB |
Output is correct |
5 |
Correct |
127 ms |
25848 KB |
Output is correct |
6 |
Correct |
226 ms |
29268 KB |
Output is correct |
7 |
Correct |
218 ms |
29268 KB |
Output is correct |
8 |
Correct |
221 ms |
29264 KB |
Output is correct |
9 |
Correct |
227 ms |
29732 KB |
Output is correct |
10 |
Correct |
216 ms |
29776 KB |
Output is correct |
11 |
Correct |
190 ms |
30684 KB |
Output is correct |
12 |
Correct |
218 ms |
29776 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
150 ms |
27732 KB |
Output is correct |
2 |
Correct |
147 ms |
27740 KB |
Output is correct |
3 |
Correct |
145 ms |
27564 KB |
Output is correct |
4 |
Correct |
121 ms |
25048 KB |
Output is correct |
5 |
Correct |
133 ms |
25936 KB |
Output is correct |
6 |
Correct |
145 ms |
27608 KB |
Output is correct |
7 |
Correct |
146 ms |
27700 KB |
Output is correct |
8 |
Correct |
145 ms |
27732 KB |
Output is correct |
9 |
Correct |
153 ms |
28104 KB |
Output is correct |
10 |
Correct |
151 ms |
28500 KB |
Output is correct |
11 |
Correct |
145 ms |
28504 KB |
Output is correct |
12 |
Correct |
3 ms |
16988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
16988 KB |
Output is correct |
2 |
Correct |
107 ms |
16988 KB |
Output is correct |
3 |
Correct |
106 ms |
16872 KB |
Output is correct |
4 |
Correct |
73 ms |
16988 KB |
Output is correct |
5 |
Correct |
4 ms |
16984 KB |
Output is correct |
6 |
Correct |
5 ms |
16988 KB |
Output is correct |
7 |
Correct |
94 ms |
17104 KB |
Output is correct |
8 |
Correct |
92 ms |
16976 KB |
Output is correct |
9 |
Correct |
92 ms |
17112 KB |
Output is correct |
10 |
Correct |
60 ms |
17116 KB |
Output is correct |
11 |
Correct |
61 ms |
17108 KB |
Output is correct |
12 |
Correct |
61 ms |
17124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
219 ms |
29268 KB |
Output is correct |
2 |
Correct |
221 ms |
29392 KB |
Output is correct |
3 |
Correct |
227 ms |
29392 KB |
Output is correct |
4 |
Correct |
123 ms |
23800 KB |
Output is correct |
5 |
Correct |
127 ms |
25848 KB |
Output is correct |
6 |
Correct |
226 ms |
29268 KB |
Output is correct |
7 |
Correct |
218 ms |
29268 KB |
Output is correct |
8 |
Correct |
221 ms |
29264 KB |
Output is correct |
9 |
Correct |
227 ms |
29732 KB |
Output is correct |
10 |
Correct |
216 ms |
29776 KB |
Output is correct |
11 |
Correct |
190 ms |
30684 KB |
Output is correct |
12 |
Correct |
218 ms |
29776 KB |
Output is correct |
13 |
Correct |
150 ms |
27732 KB |
Output is correct |
14 |
Correct |
147 ms |
27740 KB |
Output is correct |
15 |
Correct |
145 ms |
27564 KB |
Output is correct |
16 |
Correct |
121 ms |
25048 KB |
Output is correct |
17 |
Correct |
133 ms |
25936 KB |
Output is correct |
18 |
Correct |
145 ms |
27608 KB |
Output is correct |
19 |
Correct |
146 ms |
27700 KB |
Output is correct |
20 |
Correct |
145 ms |
27732 KB |
Output is correct |
21 |
Correct |
153 ms |
28104 KB |
Output is correct |
22 |
Correct |
151 ms |
28500 KB |
Output is correct |
23 |
Correct |
145 ms |
28504 KB |
Output is correct |
24 |
Correct |
3 ms |
16988 KB |
Output is correct |
25 |
Correct |
4 ms |
16988 KB |
Output is correct |
26 |
Correct |
107 ms |
16988 KB |
Output is correct |
27 |
Correct |
106 ms |
16872 KB |
Output is correct |
28 |
Correct |
73 ms |
16988 KB |
Output is correct |
29 |
Correct |
4 ms |
16984 KB |
Output is correct |
30 |
Correct |
5 ms |
16988 KB |
Output is correct |
31 |
Correct |
94 ms |
17104 KB |
Output is correct |
32 |
Correct |
92 ms |
16976 KB |
Output is correct |
33 |
Correct |
92 ms |
17112 KB |
Output is correct |
34 |
Correct |
60 ms |
17116 KB |
Output is correct |
35 |
Correct |
61 ms |
17108 KB |
Output is correct |
36 |
Correct |
61 ms |
17124 KB |
Output is correct |
37 |
Correct |
245 ms |
30088 KB |
Output is correct |
38 |
Correct |
260 ms |
29836 KB |
Output is correct |
39 |
Correct |
226 ms |
29264 KB |
Output is correct |
40 |
Correct |
124 ms |
24816 KB |
Output is correct |
41 |
Correct |
127 ms |
26200 KB |
Output is correct |
42 |
Correct |
240 ms |
29972 KB |
Output is correct |
43 |
Correct |
224 ms |
30288 KB |
Output is correct |
44 |
Correct |
247 ms |
30072 KB |
Output is correct |
45 |
Correct |
210 ms |
30292 KB |
Output is correct |
46 |
Correct |
210 ms |
30696 KB |
Output is correct |
47 |
Correct |
208 ms |
30440 KB |
Output is correct |