# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
155702 | Mercenary | Regions (IOI09_regions) | C++14 | 67 ms | 12792 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define taskname "UNDRA"
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
const int maxn = 2e5 + 5;
const int maxr = 25005;
const int sqr = 450 + 5;
int bigid[maxr];
int col[maxr];
int n , r , q;
vector<int> adj[maxn];
int big[sqr];
int nBig = 0;
vector<ii> querysmall[maxr];
int precal[sqr][maxr];
int c[maxn];
int cnt[maxr];
int res[maxn];
void DFS(int u){
if(bigid[c[u]]){
for(int i = 1 ; i <= r ; ++i){
precal[bigid[c[u]]][i] += cnt[i];
}
}else{
for(const ii& v : querysmall[c[u]]){
res[v.second] += cnt[v.first];
}
}
cnt[c[u]]++;
for(auto & v : adj[u]){
DFS(v);
}
cnt[c[u]]--;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
if(fopen(taskname".INP","r")){
freopen(taskname".INP","r",stdin);
freopen(taskname".OUT","w",stdout);
}
cin >> n >> r >> q;
for(int p , i = 1 ; i <= n ; ++i){
if(i > 1){
cin >> p >> c[i];
adj[p].pb(i);
}
else cin >> c[i];
col[c[i]]++;
}
for(int i = 1 ; i <= r ; ++i){
if(col[i] >= sqr){
bigid[i] = ++nBig;
big[nBig] = i;
}
}
for(int r1 , r2, i = 1 ; i <= q ; ++i){
cin >> r1 >> r2;
querysmall[r2].pb(mp(r1 , i));
}
DFS(1);
for(int i = 1 ; i <= nBig ; ++i){
for(auto & v : querysmall[big[i]]){
res[v.second] = precal[i][v.first];
}
}
for(int i = 1 ; i <= q ; ++i)cout << res[i] << endl;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |