Submission #1306754

#TimeUsernameProblemLanguageResultExecution timeMemory
1306754muhammad-mutahirAlternating Heights (CCO22_day1problem1)C++20
6 / 25
1095 ms4556 KiB
#include <bits/stdc++.h> using namespace std; #define print(l) for(auto i:l) cout<<i<<" ";cout<<endl; #define input(t,l,n) vector<t>l(n);for(int i = 0;i<n;i++)cin>>l[i]; #define int long long #define pb push_back #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> #define all(l) l.begin(),l.end() #define pii pair<int,int> #define fi first #define se second const int M = 1e9+7; const int inf = 1e18; int bp(int x, int y, int p){ int res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } int MI(int n, int p){ return bp(n, p - 2, p); } int mul(int x,int y, int p){ return x * 1ull * y % p; } int di(int x,int y, int p){ return mul(x, MI(y, p), p); } int n , m , k , q; vector<vector<int>>adj; map<int,int>ind; bool ck0(){ vector<int>vis(k+1,0); map<int,int>ind1 = ind; queue<int>Q; // vis[scr] = 1; int tot = 0; int vi = 0; for(auto i:ind1){ if(i.se == 0){ vis[i.fi] = 1; Q.push(i.fi); } tot++; } while(Q.size()){ int u = Q.front(); Q.pop(); vi++; for(int v :adj[u]){ ind1[v]--; if(!ind1[v]){ vis[v] = 1; Q.push(v); } } } return tot!=vi; } void solve(int testcase_number){ cin>>n>>k>>q; input(int,a,n); vector<int>maxl(n+1,0); for(int i = 0;i<n;i++){ int ans = 1; adj.clear(); adj.resize(n+1); ind.clear(); // cout<<i<<" First"<<endl; for(int j = i;j+1<n;j++){ if(j%2 == i%2){ // cout<<a[j]<<" "<<a[j+1]<<endl; adj[a[j]].pb(a[j+1]); ind[a[j+1]]++; ind[a[j]] = ind[a[j]]; } else{ // cout<<a[j+1]<<" "<<a[j]<<endl; adj[a[j+1]].pb(a[j]); ind[a[j+1]] = ind[a[j+1]]; ind[a[j]]++; } // cout<<ck0()<<endl; if(ck0()){ break; } ans++; } int ans1 = ans; // ans = 1; adj.clear(); adj.resize(n+1); ind.clear(); for(int j = i;j+1<n;j++){ if(j%2 != i%2){ adj[a[j]].pb(a[j+1]); ind[a[j+1]]++; ind[a[j]] = ind[a[j]]; } else{ adj[a[j+1]].pb(a[j]); ind[a[j+1]] = ind[a[j+1]]; ind[a[j]]++; } if(ck0()){ break; } ans++; } // cout<<ans<<" "<<ans1<<endl; maxl[i] = max(ans,ans1); } // print(maxl); for(int i = 0;i<q;i++){ int l,r; cin>>l>>r; l--; if(l+maxl[l] >= r){ cout<<"YES"<<endl; } else{ cout<<"NO"<<endl; } } } signed main(){ ios::sync_with_stdio(0);//DO NOT USE IN INTERACTIVE cin.tie(0), cout.tie(0); cout << fixed<<setprecision(9); int t = 1; // cin>>t; for(int i = 1;i<=t;i++){ solve(i); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...