Submission #971571

#TimeUsernameProblemLanguageResultExecution timeMemory
971571CookieAlternating Heights (CCO22_day1problem1)C++14
25 / 25
260 ms30696 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...