제출 #765306

#제출 시각아이디문제언어결과실행 시간메모리
765306keta_tsimakuridzeRegions (IOI09_regions)C++14
35 / 100
1063 ms131072 KiB
#include<bits/stdc++.h> #define f first #define s second #define int long long #define pii pair<int,int> using namespace std; const int N = 2e5 + 5, M = 25e3 + 5, mod = 1e9 + 7, B = 2000; // ! int t, a[N], id[M], cur, cnt[M], CN2[105][M], CN1[M][105], dp[M][105], timer; vector<pair<int,int>> reg[M]; vector<int> V[N]; void dfs(int u) { ++timer; reg[a[u]].push_back({timer, 1}); ++cnt[id[a[u]]]; for(int j = 1; j <= cur; j++) { CN2[j][u] += cnt[j]; } for(int i = 0; i < V[u].size(); i++) { int v = V[u][i]; dfs(v); for(int j = 1; j <= cur; j++) { dp[u][j] += dp[v][j]; } } --cnt[id[a[u]]]; ++dp[u][id[a[u]]]; for(int j = 1; j <= cur; j++) { CN1[u][j] += dp[u][j]; } reg[a[u]].push_back({timer + 1, 0}); } main(){ int n, r, q; cin >> n >> r >> q; for(int i = 1; i <= n; i++) { if(i >= 2) { int k; cin >> k; V[k].push_back(i); } cin >> a[i]; ++cnt[a[i]]; } // cout << "+" << endl; cur = 0; for(int i = 1; i <= r; i++) { if(cnt[i] >= B) { id[i] = ++cur; // val[cur] = i; } cnt[i] = 0; } dfs(1); while(q--) { int u, v; cin >> u >> v; if(id[u]) { cout << CN2[id[u]][v] << endl; } else if(id[v]) { cout << CN2[u][id[v]] << endl; } else { int l = -1; int cn = 0, ans = 0; for(int i = 0; i < reg[u].size(); i++) { while(l + 1 < (int)reg[v].size() && reg[v][l + 1].f < reg[u][i].f) { ++l; cn += reg[v][l].s; } ans += cn * (reg[u][i].s ? -1 : 1); } cout << ans << endl; } } }

컴파일 시 표준 에러 (stderr) 메시지

regions.cpp: In function 'void dfs(long long int)':
regions.cpp:18:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |     for(int i = 0; i < V[u].size(); i++) {
      |                    ~~^~~~~~~~~~~~~
regions.cpp: At global scope:
regions.cpp:32:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   32 | main(){
      | ^~~~
regions.cpp: In function 'int main()':
regions.cpp:63:30: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |             for(int i = 0; i < reg[u].size(); i++) {
      |                            ~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...