제출 #1280082

#제출 시각아이디문제언어결과실행 시간메모리
1280082AquariusRegions (IOI09_regions)C++20
30 / 100
1675 ms196608 KiB
#include<bits/stdc++.h> #define int long long #define sz(x) (int) x.size() #define all(x) x.begin(), x.end() using namespace std; const int N = 2e5 + 5; vector<int> E[N]; vector<int> can_st[N], can_ed[N]; map<int, int> ans[250001]; int val[N], st[N], ed[N]; int n, q, r, t = 0; void dfs(int u, int p) { st[u] = ++t; can_st[val[u]].push_back(st[u]); for(int v: E[u]) { if(v==p) continue; dfs(v, u); } ed[u] = ++t; can_ed[val[u]].push_back(ed[u]); } int count_parent(int u, int c) { // st[x] <= st[u] // ed[x] <= st[u] int a = upper_bound(all(can_st[c]), st[u]) - can_st[c].begin(); int b = upper_bound(all(can_ed[c]), st[u]) - can_ed[c].begin(); return a - b; } void solve() { cin >> n >> r >> q; for(int i=1; i<=n; i++) { if(i != 1) { int p; cin >> p; E[p].push_back(i); E[i].push_back(p); } cin >> val[i]; } dfs(1, 0); for(int i=1; i<=r; i++) sort(all(can_ed[i])); for(int i=1; i<=n; i++) { for(int color = 1; color <=r; color++) { if(color == val[i]) continue; ans[val[i]][color] += count_parent(i, color); } } while(q--) { int r1, r2; cin >> r1 >> r2; cout<<ans[r2][r1] << endl; } } /* 1 3 2 1 */ signed main() { if(fopen("input.txt", "r")) freopen("input.txt", "r", stdin); ios_base::sync_with_stdio(false);cin.tie(0); int T = 1; // cin >> T; while(T--) solve(); }

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

regions.cpp: In function 'int main()':
regions.cpp:79:40: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   79 |     if(fopen("input.txt", "r")) freopen("input.txt", "r", stdin);
      |                                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...