답안 #1081319

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1081319 2024-08-29T22:24:20 Z Dennis_Jason Regions (IOI09_regions) C++14
0 / 100
95 ms 131072 KB
#include <bits/stdc++.h>
#define NMAX 200001
#define pb push_back
#define eb emplace_back
#define MOD 100003
#define nl '\n'
#define INF  2147483647
#define LLONG_MAX 9223372036854775807
#define pii pair<int,int>
#define tpl tuple<int,int,int>
//#pragma GCC optimize("O3")
using namespace std;
ifstream fin("aib.in");
ofstream fout("aib.out");
/*
 *
 *
    ================DEMONSTRATION===================


    =====================END========================
 */

int n,r,q;
int r1,r2,ans;
vector<int>h(NMAX),s(NMAX);
vector<int>tin(NMAX),tout(NMAX);
vector<vector<int>>G(NMAX);
vector<vector<int>>R(25001);
vector<vector<int>> regions(NMAX, vector<int>(25001, 0));
int timp;
void read_query()
{
    cin>>r1>>r2;
}
void print_query()
{
    cout.flush()<<ans<<nl;
    cout.flush();
}
void dfs(int node,int parent) {
    tin[node] = ++timp;
    for (auto x: G[node]) {
        if (x != parent) {
            dfs(x, node);
            for (int i = 1; i <= 25000; ++i) {
                regions[node][i] += regions[x][i];
            }
        }
        tout[node] = timp;
    }
}

signed main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>n>>r>>q;
    cin>>h[1];
    regions[1][h[1]]=1;
    R[h[1]].pb(1);
    for(int i=2;i<=n;++i)
    {
        cin>>s[i]>>h[i];
        regions[i][h[i]]=1;
        R[h[i]].pb(i);
        G[i].pb(s[i]);
        G[s[i]].pb(i);
    }

    dfs(1,-1);

//    seg.init(n);
//    for(int i=1;i<=n;++i)
//    {
//        seg.update(tin[i],h[i]);
//    }
//    seg.check();
//    for(auto [x,y]:regions[1])
//        cout<<x<<" "<<y<<nl;
    while(q--)
    {
        ans=0;
        read_query();
        for(auto x:R[r1])
        {
            ans+=(regions[x][r2]);
        }
        print_query();
    }

    return 0;
}

Compilation message

regions.cpp:8: warning: "LLONG_MAX" redefined
    8 | #define LLONG_MAX 9223372036854775807
      | 
In file included from /usr/lib/gcc/x86_64-linux-gnu/10/include/limits.h:195,
                 from /usr/lib/gcc/x86_64-linux-gnu/10/include/syslimits.h:7,
                 from /usr/lib/gcc/x86_64-linux-gnu/10/include/limits.h:34,
                 from /usr/include/c++/10/climits:42,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:39,
                 from regions.cpp:1:
/usr/include/limits.h:135: note: this is the location of the previous definition
  135 | #  define LLONG_MAX __LONG_LONG_MAX__
      |
# 결과 실행 시간 메모리 Grader output
1 Runtime error 66 ms 131072 KB Execution killed with signal 9
2 Runtime error 65 ms 131072 KB Execution killed with signal 9
3 Runtime error 67 ms 131072 KB Execution killed with signal 9
4 Runtime error 67 ms 131072 KB Execution killed with signal 9
5 Runtime error 68 ms 131072 KB Execution killed with signal 9
6 Runtime error 65 ms 131072 KB Execution killed with signal 9
7 Runtime error 66 ms 131072 KB Execution killed with signal 9
8 Runtime error 66 ms 131072 KB Execution killed with signal 9
9 Runtime error 67 ms 131072 KB Execution killed with signal 9
10 Runtime error 66 ms 131072 KB Execution killed with signal 9
11 Runtime error 95 ms 131072 KB Execution killed with signal 9
12 Runtime error 76 ms 131072 KB Execution killed with signal 9
13 Runtime error 65 ms 131072 KB Execution killed with signal 9
14 Runtime error 67 ms 131072 KB Execution killed with signal 9
15 Runtime error 65 ms 131072 KB Execution killed with signal 9
# 결과 실행 시간 메모리 Grader output
1 Runtime error 70 ms 131072 KB Execution killed with signal 9
2 Runtime error 82 ms 131072 KB Execution killed with signal 9
3 Runtime error 80 ms 131072 KB Execution killed with signal 9
4 Runtime error 94 ms 131072 KB Execution killed with signal 9
5 Runtime error 57 ms 131072 KB Execution killed with signal 9
6 Runtime error 56 ms 131072 KB Execution killed with signal 9
7 Runtime error 64 ms 131072 KB Execution killed with signal 9
8 Runtime error 67 ms 131072 KB Execution killed with signal 9
9 Runtime error 71 ms 131072 KB Execution killed with signal 9
10 Runtime error 60 ms 131072 KB Execution killed with signal 9
11 Runtime error 66 ms 131072 KB Execution killed with signal 9
12 Runtime error 70 ms 131072 KB Execution killed with signal 9
13 Runtime error 63 ms 131072 KB Execution killed with signal 9
14 Runtime error 70 ms 131072 KB Execution killed with signal 9
15 Runtime error 65 ms 131072 KB Execution killed with signal 9
16 Runtime error 66 ms 131072 KB Execution killed with signal 9
17 Runtime error 66 ms 131072 KB Execution killed with signal 9