이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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();
}
컴파일 시 표준 에러 (stderr) 메시지
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) {
| ~~~~~~~~~~~~~~~~~~~~~~^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |