Submission #732749

#TimeUsernameProblemLanguageResultExecution timeMemory
732749loctildoreThrough Another Maze Darkly (CCO21_day1problem3)C++14
0 / 25
49 ms52692 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define f first #define s second #define endl '\n' #define all(x) begin(x), end(x) struct node { int l, r; node *lft, *rht; int tot; node(int tl, int tr): l(tl), r(tr), tot(0) { if (l + 1 == r) { lft = rht = NULL; return; } lft = new node(l, (l + r) / 2); rht = new node((l + r) / 2, r); } void add(int p) { if (p < l || p >= r) { return; } tot++; if (l + 1 == r) return; lft->add(p); rht->add(p); } int fnd(int x) { if (l + 1 == r) return l; if (lft->tot >= x) return lft->fnd(x); return rht->fnd(x - lft->tot); } }* root; int n, q; int a, b, tb; vector<int> grph[800069]; int lgc; vector<int> lg[800069]; vector<pair<int,int>> vctr, qrys; int ans[800069]; void dfs(int x, int rnd, int lst = -1) { for (auto i : grph[x]) { if (i == lst) { rnd++; continue; } vctr.push_back({i, rnd}); dfs(i, rnd, x); vctr.push_back({x, rnd}); } } int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cin>>n>>q; for (int i = 0; i < n; i++) { cin>>a; cin>>tb; tb--; for (int j = 1; j < a; j++) { cin>>b; b--; grph[i].push_back(b); } grph[i].push_back(tb); } dfs(0, 0); root = new node(0, vctr.size()); for (int i = 0; i < vctr.size(); i++) { vctr[i].f++; lg[vctr[i].s].push_back(i); } for (int i = 0; i < q; i++) { cin>>a; qrys.push_back({a, i}); } sort(all(qrys)); int cur = 0; for (auto tmp : qrys) { tie(a, b) = tmp; while (a - cur > root->tot && lgc < 800069) { cur += root->tot; for (auto i : lg[lgc]) { root->add(i); } lgc++; } a -= cur; a %= root->tot; if (!a) a = root->tot; ans[b] = vctr[root->fnd(a)].f; } for (int i = 0; i < q; i++) { cout<<ans[i]<<endl; } return 0; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:65:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |     for (int i = 0; i < vctr.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...