답안 #881695

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
881695 2023-12-01T18:08:10 Z sheldon Regions (IOI09_regions) C++14
0 / 100
97 ms 41316 KB
#include <bits/stdc++.h>

using namespace std;

const int nax = 2e5 + 5;

int region[nax];
vector<int> edges[nax], positions[nax];
int tin[nax], tout[nax], who[nax];
int timer = 0;
unordered_map<int, int> mp[nax];

void dfs (int u, int p) {
    tin[u] = ++timer;
    who[timer] = u;
    positions[region[u]].push_back(timer);
    for (int v : edges[u]) {
        if (v != p) {
            dfs (v, u);
        }
    }
    tout[u] = timer;
}

void solve() {
    int n, r, q;
    cin >> n >> r >> q;
    cin >> region[1];
    for (int i = 2; i <= n; ++i) {
        int p;
        cin >> p >> region[i];
        edges[i].push_back(p);
        edges[p].push_back(i);
    }
    dfs (1, 0);
    const int B = sqrt(n) + 5;
    for (int reg = 1; reg <= r; ++reg) {
        if (positions[reg].size() >= B) {
            vector<int> pref(n + 2);
            for (int i = 1; i <= n; ++i) {
                if (region[who[i]] == reg) {
                    pref[i + 1]++;
                    pref[tout[who[i]] + 1]--;
                }
            }
            for (int i = 1; i <= n; ++i) {
                pref[i] += pref[i - 1];
                // mp[reg][region[who[i]]] += pref[i];
            }
        }
    }
    // while (q--) {

    //     int reg1, reg2;
    //     cin >> reg1 >> reg2;
    //     if (positions[reg1].size() >= B) {
    //         cout << mp[reg1][reg2] << endl;
    //     } else {
    //         int ans = 0;
    //         for (int i : positions[reg1]) {
    //             if (region[who[i]] == reg1) {
    //                 auto it1 = upper_bound(positions[reg2].begin(), positions[reg2].end(), tout[who[i]]) - positions[reg2].begin();
    //                 auto it2 = lower_bound(positions[reg2].begin(), positions[reg2].end(), i) - positions[reg2].begin();
    //                 if (it1 != 0) {
    //                     ans += (int) it1 - it2;
    //                 }
    //             }
    //         }
    //         cout << ans << endl;
    //     }
    // }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    solve();
}

Compilation message

regions.cpp: In function 'void solve()':
regions.cpp:38:35: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'const int' [-Wsign-compare]
   38 |         if (positions[reg].size() >= B) {
      |             ~~~~~~~~~~~~~~~~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 23128 KB Unexpected end of file - int32 expected
2 Incorrect 5 ms 23128 KB Unexpected end of file - int32 expected
3 Incorrect 5 ms 23128 KB Unexpected end of file - int32 expected
4 Incorrect 6 ms 23128 KB Unexpected end of file - int32 expected
5 Incorrect 5 ms 23128 KB Unexpected end of file - int32 expected
6 Incorrect 5 ms 23128 KB Unexpected end of file - int32 expected
7 Incorrect 5 ms 23128 KB Unexpected end of file - int32 expected
8 Incorrect 5 ms 23128 KB Unexpected end of file - int32 expected
9 Incorrect 6 ms 23640 KB Unexpected end of file - int32 expected
10 Incorrect 8 ms 23384 KB Unexpected end of file - int32 expected
11 Incorrect 8 ms 23828 KB Unexpected end of file - int32 expected
12 Incorrect 9 ms 24152 KB Unexpected end of file - int32 expected
13 Incorrect 12 ms 24108 KB Unexpected end of file - int32 expected
14 Incorrect 13 ms 24352 KB Unexpected end of file - int32 expected
15 Incorrect 14 ms 26716 KB Unexpected end of file - int32 expected
# 결과 실행 시간 메모리 Grader output
1 Incorrect 27 ms 27224 KB Unexpected end of file - int32 expected
2 Incorrect 27 ms 26780 KB Unexpected end of file - int32 expected
3 Incorrect 26 ms 28800 KB Unexpected end of file - int32 expected
4 Incorrect 13 ms 24560 KB Unexpected end of file - int32 expected
5 Incorrect 14 ms 25800 KB Unexpected end of file - int32 expected
6 Incorrect 33 ms 25852 KB Unexpected end of file - int32 expected
7 Incorrect 32 ms 26532 KB Unexpected end of file - int32 expected
8 Incorrect 56 ms 30932 KB Unexpected end of file - int32 expected
9 Incorrect 45 ms 30364 KB Unexpected end of file - int32 expected
10 Incorrect 97 ms 35784 KB Unexpected end of file - int32 expected
11 Incorrect 56 ms 32252 KB Unexpected end of file - int32 expected
12 Incorrect 57 ms 31844 KB Unexpected end of file - int32 expected
13 Incorrect 61 ms 32572 KB Unexpected end of file - int32 expected
14 Incorrect 82 ms 32892 KB Unexpected end of file - int32 expected
15 Incorrect 59 ms 35932 KB Unexpected end of file - int32 expected
16 Incorrect 62 ms 41316 KB Unexpected end of file - int32 expected
17 Incorrect 67 ms 40012 KB Unexpected end of file - int32 expected