Submission #1368859

#TimeUsernameProblemLanguageResultExecution timeMemory
1368859monk_is_liveRegions (IOI09_regions)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long

vector<vector<int>> g, v, t, a;
vector<int> c, tin, tout, id, hv;
int tm = 0;

void dfs(int x) {
    tin[x] = ++tm;
    v[c[x]].push_back(x);
    t[c[x]].push_back(tin[x]);
    for (auto y : g[x]) dfs(y);
    tout[x] = tm;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, r, q;
    cin >> n >> r >> q;

    g.resize(n + 1);
    c.resize(n + 1);

    cin >> c[1];

    for (int i = 2; i <= n; i++) {
        int p;
        cin >> p >> c[i];
        g[p].push_back(i);
    }

    tin.resize(n + 1);
    tout.resize(n + 1);

    v.resize(r + 1);
    t.resize(r + 1);

    dfs(1);

    int b = 450;

    id.assign(r + 1, -1);

    for (int i = 1; i <= r; i++) {
        if ((int)v[i].size() > b) {
            id[i] = hv.size();
            hv.push_back(i);
        }
    }

    a.assign(hv.size(), vector<int>(r + 1));

    for (int i = 0; i < hv.size(); i++) {
        int h = hv[i];

        function<void(int,int)> go = [&](int x, int s) {
            a[i][c[x]] += s;

            int ns = s + (c[x] == h);

            for (auto y : g[x]) {
                go(y, ns);
            }
        };

        go(1, 0);
    }

    while (q--) {
        int x, y;
        cin >> x >> y;

        int ans = 0;

        if (id[x] != -1) {
            ans = a[id[x]][y];
        } else {
            for (auto z : v[x]) {
                ans += upper_bound(t[y].begin(), t[y].end(), tout[z]) -
                       lower_bound(t[y].begin(), t[y].end(), tin[z]);
            }
        }

        cout << ans << '\n';
    }

    return 0;
}

Compilation message (stderr)

regions.cpp: In function 'void dfs(long long int)':
regions.cpp:11:16: error: reference to 'tm' is ambiguous
   11 |     tin[x] = ++tm;
      |                ^~
In file included from /usr/include/time.h:39,
                 from /usr/include/pthread.h:23,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/gthr-default.h:35,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/gthr.h:148,
                 from /usr/include/c++/13/ext/atomicity.h:35,
                 from /usr/include/c++/13/bits/ios_base.h:39,
                 from /usr/include/c++/13/streambuf:43,
                 from /usr/include/c++/13/bits/streambuf_iterator.h:35,
                 from /usr/include/c++/13/iterator:66,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:54,
                 from regions.cpp:1:
/usr/include/x86_64-linux-gnu/bits/types/struct_tm.h:7:8: note: candidates are: 'struct tm'
    7 | struct tm
      |        ^~
regions.cpp:8:5: note:                 'long long int tm'
    8 | int tm = 0;
      |     ^~
regions.cpp:15:15: error: reference to 'tm' is ambiguous
   15 |     tout[x] = tm;
      |               ^~
/usr/include/x86_64-linux-gnu/bits/types/struct_tm.h:7:8: note: candidates are: 'struct tm'
    7 | struct tm
      |        ^~
regions.cpp:8:5: note:                 'long long int tm'
    8 | int tm = 0;
      |     ^~