Submission #1097348

#TimeUsernameProblemLanguageResultExecution timeMemory
1097348vjudge1Passport (JOI23_passport)C++17
0 / 100
276 ms65820 KiB
#include <iostream> #include <cstring> #include <vector> #include <queue> using namespace std; const int INF = 1e9+7; const int MAXN = 2e5+3; int n, q, x; vector<pair<int,int>> e[4*MAXN]; int ans; int f[4*MAXN]; int ID[MAXN]; bool vis[4*MAXN]; void STbuild(int idx=1, int l=1, int r=n){ if(l==r){ ID[l] = idx; return; } int mid = l+r>>1; e[idx].push_back({idx<<1, 0}); e[idx].push_back({idx<<1|1, 0}); STbuild(idx<<1, l, mid); STbuild(idx<<1|1, mid+1, r); } void STunion(int z, int u, int v, int idx=1, int l=1, int r=n){ if(v<l || r<u)return; if(u<=l && r<=v){ if(idx==ID[z])return; e[ID[z]].push_back({idx, 1}); return; } int mid = l+r>>1; STunion(z,u,v,idx<<1,l,mid); STunion(z,u,v,idx<<1|1,mid+1,r); } struct sub4 { class Compare{ public: bool operator()(const int &a, const int &b){ return f[a] > f[b]; }}; priority_queue<int, vector<int>, Compare> pq; void solve(){ for(int i=1; i<=4*n; ++i) f[i] = INF, vis[i] = 0; pq.push(ID[x]); f[ID[x]] = 0; vis[ID[x]] = 1; while(!pq.empty()){ int u = pq.top(); pq.pop(); for(pair<int,int> &z : e[u]){ int v = z.first, w = z.second; if(vis[v])continue; pq.push(v); vis[v] = 1; f[v] = min(f[v],f[u]+w); } } ans = 0; for(int i=1; i<=n; ++i)ans=max(ans,f[ID[i]]); cout << (ans>=INF ? -1 : ans) << '\n'; } }; signed main() { // cin.tie(0) -> sync_with_stdio(0); if(fopen("*.inp", "r")){ freopen("*.inp", "r",stdin); freopen("*.out", "w",stdout); } cin >> n; STbuild(); for(int l, r, i=1; i<=n; ++i){ cin >> l >> r; STunion(i, l, r); } auto subans = (new sub4()); cin >> q; while(q--){ cin >> x; subans -> solve(); } return 0; }

Compilation message (stderr)

passport.cpp: In function 'void STbuild(int, int, int)':
passport.cpp:25:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   25 |     int mid = l+r>>1;
      |               ~^~
passport.cpp: In function 'void STunion(int, int, int, int, int, int)':
passport.cpp:39:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   39 |     int mid = l+r>>1;
      |               ~^~
passport.cpp: In function 'int main()':
passport.cpp:85:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   85 |         freopen("*.inp", "r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~
passport.cpp:86:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   86 |         freopen("*.out", "w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...