#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#define getar(ar,n) for(ll i=0;i<n;++i) cin>>ar[i]
#define show(n) cout<<n<<'\n'
#define all(v) v.begin(), v.end()
#define br cout<<"\n"
#define pb push_back
#define nl '\n'
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define ret return
#define ll long long
#define ld long double
#define sza(x) ((int)x.size())
const int mxN = 2e5 + 50;
const ll MOD = 1e9 + 7;
const ll INF = 1e9;
const ld EPS = 1e-9;
vector<ll> adj[mxN];
ll hd[mxN],lt[mxN],st[mxN],en[mxN];
ll seg[mxN*4][505],tin=-1;
void build(ll node,ll start,ll end){
if(start==end){
seg[node][lt[start]]=1;
return;
}
ll mid=start+(end-start)/2;
build(node*2+1,start,mid);
build(node*2+2,mid+1,end);
for(ll i=1;i<505;++i){
seg[node][i]=seg[node*2+1][i]+seg[node*2+2][i];
}
}
void dfs(ll u=1,ll par=-1){
st[u]=++tin;
lt[tin]=hd[u];
for(auto it:adj[u]){
if(it^par){
dfs(it,u);
}
}
en[u]=tin;
}
ll qry(ll node,ll start,ll end,ll l,ll r,ll v){
if(start>r||end<l) return 0;
if(start>=l&&end<=r) return seg[node][v];
ll mid=start+(end-start)/2;
return qry(node*2+1,start,mid,l,r,v)+qry(node*2+2,mid+1,end,l,r,v);
}
void solve(ll tc) {
ll n,r,q,r1,r2,h,super;cin>>n>>r>>q;
cin>>hd[1];
unordered_map<ll,vector<ll>> mp;
mp[hd[1]].pb(1);
for(ll i=2;i<=n;++i){
cin>>super>>hd[i];
adj[super].pb(i);
mp[hd[i]].pb(i);
}
memset(seg,0,sizeof(seg));
dfs();
build(0,0,tin);
while(q--){
cin>>r1>>r2;
ll ans=0;
for(auto it:mp[hd[r1]]){
ans+=qry(0,0,tin,st[it],en[it],r2);
}
cout<<ans<<endl;
}
//cout<<qry(0,0,tin,st[1],en[1],2)<<nl;
}
Compilation message
regions.cpp: In function 'void solve(long long int)':
regions.cpp:64:18: warning: unused variable 'h' [-Wunused-variable]
64 | ll n,r,q,r1,r2,h,super;cin>>n>>r>>q;
| ^
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/crt1.o: in function `_start':
(.text+0x24): undefined reference to `main'
/tmp/ccNh9TtV.o: in function `__tcf_0':
regions.cpp:(.text+0x9): relocation truncated to fit: R_X86_64_PC32 against symbol `adj' defined in .bss section in /tmp/ccNh9TtV.o
/tmp/ccNh9TtV.o: in function `build(long long, long long, long long) [clone .part.0]':
regions.cpp:(.text+0x116): relocation truncated to fit: R_X86_64_PC32 against symbol `lt' defined in .bss section in /tmp/ccNh9TtV.o
regions.cpp:(.text+0x150): relocation truncated to fit: R_X86_64_PC32 against symbol `lt' defined in .bss section in /tmp/ccNh9TtV.o
/tmp/ccNh9TtV.o: in function `build(long long, long long, long long)':
regions.cpp:(.text+0x184): relocation truncated to fit: R_X86_64_PC32 against symbol `lt' defined in .bss section in /tmp/ccNh9TtV.o
/tmp/ccNh9TtV.o: in function `dfs(long long, long long)':
regions.cpp:(.text+0x1b9): relocation truncated to fit: R_X86_64_PC32 against symbol `st' defined in .bss section in /tmp/ccNh9TtV.o
regions.cpp:(.text+0x1da): relocation truncated to fit: R_X86_64_PC32 against symbol `hd' defined in .bss section in /tmp/ccNh9TtV.o
regions.cpp:(.text+0x1e5): relocation truncated to fit: R_X86_64_PC32 against symbol `lt' defined in .bss section in /tmp/ccNh9TtV.o
regions.cpp:(.text+0x1fb): relocation truncated to fit: R_X86_64_PC32 against symbol `adj' defined in .bss section in /tmp/ccNh9TtV.o
regions.cpp:(.text+0x235): relocation truncated to fit: R_X86_64_PC32 against symbol `en' defined in .bss section in /tmp/ccNh9TtV.o
/tmp/ccNh9TtV.o: in function `solve(long long)':
regions.cpp:(.text+0x339): relocation truncated to fit: R_X86_64_PC32 against symbol `std::cin' defined in .bss._ZSt3cin section in /usr/lib/gcc/x86_64-linux-gnu/10/libstdc++.a(globals_io.o)
regions.cpp:(.text+0x388): additional relocation overflows omitted from the output
/usr/bin/ld: failed to convert GOTPCREL relocation; relink with --no-relax
collect2: error: ld returned 1 exit status