# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
657556 |
2022-11-10T08:38:03 Z |
d4xn |
Regions (IOI09_regions) |
C++17 |
|
0 ms |
0 KB |
#pragma GCC optimize ("Ofast")
//#pragma GCC target ("avx2")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) x.begin(), x.end()
#define pb push_back
#define vi vector<int>
#define vvi vector<vi>
#define vll vector<ll>
const int N = 200000, R1 = 25000, R2 = 500;
int n, r, q, curr;
int reg[N], sz[N], pre[N], idx[N];
vll ans[R1];
vi adj[N], from[R1], pos[R1];
void dfs(int u) {
sz[u] = 1;
pre[curr] = reg[u];
pos[reg[u]].pb(curr);
idx[u] = curr;
curr++;
for (int &v : adj[u]) {
dfs(v);
sz[u] += sz[v];
}
}
int query(int a, int b, int c) {
int l = lower_bound(all(pos[c]), a) - pos[c].begin();
int r = upper_bound(all(pos[c]), b) - pos[c].begin();
return r-l;
}
signed main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> n >> r >> q;
int mx = 0;
for (int i = 0; i < n; i++) {
if (i) {
int x;
cin >> x;
x--;
adj[x].pb(i);
}
cin >> reg[i];
reg[i]--;
from[reg[i]].pb(i);
mx = max(mx, (int)from[reg[i]].size());
}
curr = 0;
dfs(0);
for (int i = 0; i < r; i++) {
if (from[i].size() <= R2) continue;
ans[i].resize(r, 0);
for (int &u : from[i]) {
for (int j = 0; j < sz[u]; j++) {
ans[i][pre[idx[u]+j]++;
}
}
}
while (q--) {
int x, y;
cin >> x >> y;
x--; y--;
if (from[x].size() > R2) {
cout << ans[x][y] << endl;
}
else {
ll cnt = 0;
for (int &u : from[x]) {
cnt += query(idx[u], idx[u] + sz[u] - 1, y);
}
cout << cnt << endl;
}
}
}
Compilation message
regions.cpp:64:2: error: extended character is not valid in an identifier
64 | ans[i].resize(r, 0);
| ^
regions.cpp:64:5: error: extended character is not valid in an identifier
64 | ans[i].resize(r, 0);
| ^
regions.cpp:65:2: error: extended character is not valid in an identifier
65 |
| ^
regions.cpp:65:5: error: extended character is not valid in an identifier
65 |
| ^
regions.cpp:66:2: error: extended character is not valid in an identifier
66 |
| ^
regions.cpp:66:5: error: extended character is not valid in an identifier
66 |
| ^
regions.cpp:66:8: error: extended character is not valid in an identifier
66 |
| ^
regions.cpp:67:2: error: extended character is not valid in an identifier
67 |
| ^
regions.cpp:67:5: error: extended character is not valid in an identifier
67 |
| ^
regions.cpp:67:8: error: extended character is not valid in an identifier
67 |
| ^
regions.cpp:68:2: error: extended character is not valid in an identifier
68 | for (int &u : from[i]) {
| ^
regions.cpp:68:5: error: extended character is not valid in an identifier
68 | for (int &u : from[i]) {
| ^
regions.cpp:68:8: error: extended character is not valid in an identifier
68 | for (int &u : from[i]) {
| ^
regions.cpp:69:2: error: extended character is not valid in an identifier
69 | for (int j = 0; j < sz[u]; j++) {
| ^
regions.cpp:69:5: error: extended character is not valid in an identifier
69 | for (int j = 0; j < sz[u]; j++) {
| ^
regions.cpp:69:8: error: extended character is not valid in an identifier
69 | for (int j = 0; j < sz[u]; j++) {
| ^
regions.cpp:69:11: error: extended character is not valid in an identifier
69 | for (int j = 0; j < sz[u]; j++) {
| ^
regions.cpp:70:2: error: extended character is not valid in an identifier
70 | ans[i][pre[idx[u]+j]++;
| ^
regions.cpp:70:5: error: extended character is not valid in an identifier
70 | ans[i][pre[idx[u]+j]++;
| ^
regions.cpp:70:8: error: extended character is not valid in an identifier
70 | ans[i][pre[idx[u]+j]++;
| ^
regions.cpp:70:11: error: extended character is not valid in an identifier
70 | ans[i][pre[idx[u]+j]++;
| ^
regions.cpp:70:14: error: extended character is not valid in an identifier
70 | ans[i][pre[idx[u]+j]++;
| ^
regions.cpp:71:2: error: extended character is not valid in an identifier
71 | }
| ^
regions.cpp:71:5: error: extended character is not valid in an identifier
71 | }
| ^
regions.cpp:71:8: error: extended character is not valid in an identifier
71 | }
| ^
regions.cpp:72:2: error: extended character is not valid in an identifier
72 |
| ^
regions.cpp:72:5: error: extended character is not valid in an identifier
72 |
| ^
regions.cpp:72:8: error: extended character is not valid in an identifier
72 |
| ^
regions.cpp:72:11: error: extended character is not valid in an identifier
72 |
| ^
regions.cpp: In function 'int main()':
regions.cpp:64:2: error: '\U000000a0' was not declared in this scope
64 | ans[i].resize(r, 0);
| ^
regions.cpp:65:4: error: expected ';' before '\U000000a0'
65 |
| ^~
| ;