Submission #828936

#TimeUsernameProblemLanguageResultExecution timeMemory
828936CSQ31Passport (JOI23_passport)C++17
Compilation error
0 ms0 KiB
#pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") #include<bits/stdc++.h> using namespace std; #define pb push_back #define fi first #define se second #define sz(a) (int)(a.size()) #define all(a) a.begin(),a.end() #define lb lower_bound #define ub upper_bound #define owo ios_base::sync_with_stdio(0);cin.tie(0); #define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr) #define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\ debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC)) typedef long long int ll; typedef long double ld; typedef pair<ll,ll> PII; typedef pair<int,int> pii; typedef vector<vector<int>> vii; typedef vector<vector<ll>> VII; ll gcd(ll a,ll b){if(!b)return a;else return gcd(b,a%b);} const int MAXN = 2e5+5; int a[MAXN],b[MAXN],c[MAXN]; int dist[4][MAXN]; vector<int>adj[MAXN]; int main() { owo int n; cin>>n; for(int i=1;i<=n;i++)dist[0][i] = dist[1][i] = dist[2][i] = dist[3][i] = 1e9; for(int i=1;i<=n;i++){ cin>>a[i]>>b[i]; if(a[i]==1)c[i]++; if(b[i]==n)c[i]+=2; dist[c[i]][i] = 1; for(int j=a[i];j<=b[i];j++)adj[j].pb(i); } queue<int>q; for(int i=1;i<=n;i++){ if(c[i]==1)q.push(i); } while(!q.empty()){ int v = q.front(); q.pop(); for(int x:adj[v]){ if(dist[1][x] > dist[1][v] + 1){ dist[1][x] = dist[1][v] + 1; q.push(x); } } } for(int i=1;i<=n;i++){ if(c[i]==2)q.push(i); } while(!q.empty()){ int v = q.front(); q.pop(); for(int x:adj[v]){ if(dist[2][x] > dist[2][v] + 1){ dist[2][x] = dist[2][v] + 1; q.push(x); } } } for(int i=1;i<=n;i++){ if(c[i]==3)q.push(i); else if(dist[1][i]+dist[2][i] < 1e9){ dist[3][i] = dist[1][i] + dist[2][i] - 1; q.push(i); } } while(!q.empty()){ int v = q.front(); q.pop(); for(int x:adj[v]){ if(dist[3][x] > dist[3][v] + 1){ dist[3][x] = dist[3][v] + 1; q.push(x); } } } cin>>Q; while(Q--){ int i; cin>>i; if(dist[3][i]==1e9)cout<<-1<<'\n'; else cout<<dist[3][i]<<'\n'; } }

Compilation message (stderr)

passport.cpp: In function 'int main()':
passport.cpp:88:7: error: 'Q' was not declared in this scope
   88 |  cin>>Q;
      |       ^