(UPD: 2024-12-04 14:48 UTC) Judge is not working due to Cloudflare incident. (URL) We can do nothing about it, sorry. After the incident is resolved, we will grade all submissions.

Submission #635666

#TimeUsernameProblemLanguageResultExecution timeMemory
635666jhnah917Through Another Maze Darkly (CCO21_day1problem3)C++14
4 / 25
100 ms43960 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; constexpr int SZ = 1 << 21; int N, Q, On[808080], R[808080], T[SZ]; vector<int> G[80808]; vector<pair<int,int>> Tour; vector<int> Idx[808080]; // Idx[t] : t에 켜지는 정점 void Add(int x, int v){ for(x+=3; x<SZ; x+=x&-x) T[x] += v; } int Get(int x){ int ret = 0; for(x+=3; x; x-=x&-x) ret += T[x]; return ret; } int Kth(int x){ int l = 0, r = Tour.size() - 1; while(l < r){ int m = (l + r) / 2; if(Get(m) >= x) r = m; else l = m + 1; } return r; } void GetTime(int v, int b=-1, int t=1){ On[v] = t; int pos = find(G[v].begin(), G[v].end(), b) - G[v].begin(); for(int i=0; i<pos; i++) GetTime(G[v][i], v, t); for(int i=pos+1; i<G[v].size(); i++) GetTime(G[v][i], v, t+1); if(b != -1) rotate(G[v].begin(), G[v].begin()+pos, G[v].end()); } inline void AddEdge(int s, int e){ Idx[max(On[s], On[e])].push_back(Tour.size()); Tour.emplace_back(s, e); } void GetTour(int v, int b=-1){ for(auto i : G[v]) if(i != b) AddEdge(v, i), GetTour(i, v), AddEdge(i, v); } int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> N >> Q; for(int i=1; i<=N; i++){ int sz; cin >> sz; G[i].resize(sz); for(auto &j : G[i]) cin >> j; rotate(G[i].begin(), G[i].begin()+1, G[i].end()); } GetTime(1); GetTour(1); vector<pair<ll,ll>> V(Q); for(int i=0; i<Q; i++) cin >> V[i].first, V[i].second = i + 1; sort(V.begin(), V.end()); ll now = 0; for(int i=0, j=1; i<V.size(); i++){ for(; j<=N && now<V[i].first; j++){ for(auto e : Idx[j]) Add(e, 1); now += Get(Tour.size()); } ll k = V[i].first - (now - Get(Tour.size())); R[V[i].second] = Kth((k - 1) % (2*N-2) + 1); } for(int i=1; i<=Q; i++) cout << Tour[R[i]].second << "\n"; }

Compilation message (stderr)

Main.cpp: In function 'void GetTime(int, int, int)':
Main.cpp:27:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     for(int i=pos+1; i<G[v].size(); i++) GetTime(G[v][i], v, t+1);
      |                      ~^~~~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:56:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |     for(int i=0, j=1; i<V.size(); 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...