제출 #165679

#제출 시각아이디문제언어결과실행 시간메모리
165679nvmdavaRegions (IOI09_regions)C++17
100 / 100
4334 ms34904 KiB
#include <bits/stdc++.h> using namespace std; #define ff first #define ss second mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #define N 200005 int h[N], p[N], ho[N], le[N], ri[N], cntr; int rs[25005]; vector<int> rid[25005], ch[N]; vector<pair<pair<int, int>, int> > rra[25005]; void dfs(int v){ int t = ++cntr; rid[h[v]].push_back(cntr); ho[cntr] = h[v]; for(auto& x : ch[v]) dfs(x); ri[t] = cntr; } map<int, int> dif, cache; void addrange(int v){ dif.clear(); for(auto& x : rid[v]){ ++dif[x]; --dif[ri[x] + 1]; } int now = 0, le = -1; for(auto& x : dif){ if(now != 0){ rra[v].push_back({{le, x.ff - 1}, now}); } now += x.ss; le = x.ff; } } int main(){ int n, r, q; scanf("%d%d%d%d", &n, &r, &q, &h[1]); ++rs[h[1]]; for(int i = 2; i <= n; ++i){ scanf("%d%d", &p[i], &h[i]); ++rs[h[i]]; ch[p[i]].push_back(i); } dfs(1); cntr = 0; for(int i = 1; i <= r; ++i) addrange(i); while(q--){ int r1, r2; scanf("%d%d", &r1, &r2); auto it = cache.find(r1 * 25000 + r2); if(it != cache.end()){ printf("%d\n", it -> ss); fflush(stdout); continue; } int ans = 0, i = 0; for(auto& x : rid[r2]){ while(rra[r1].size() > i && rra[r1][i].ff.ss < x) ++i; if(rra[r1].size() == i) break; if(rra[r1].size() != i && rra[r1][i].ff.ff <= x) ans += rra[r1][i].ss; } cache[r1 * 25000 + r2] = ans; printf("%d\n", ans); fflush(stdout); } }

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

regions.cpp: In function 'int main()':
regions.cpp:72:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             while(rra[r1].size() > i && rra[r1][i].ff.ss < x)
                   ~~~~~~~~~~~~~~~^~~
regions.cpp:74:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if(rra[r1].size() == i)
                ~~~~~~~~~~~~~~~^~~~
regions.cpp:76:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if(rra[r1].size() != i && rra[r1][i].ff.ff <= x)
                ~~~~~~~~~~~~~~~^~~~
regions.cpp:46:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%d%d", &n, &r, &q, &h[1]);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
regions.cpp:49:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &p[i], &h[i]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
regions.cpp:63:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &r1, &r2);
         ~~~~~^~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...