Submission #921437

# Submission time Handle Problem Language Result Execution time Memory
921437 2024-02-03T20:57:57 Z Ahmed_Solyman Regions (IOI09_regions) C++14
0 / 100
2 ms 5972 KB
/*
In the name of Allah
made by: Ahmed_Solyman
*/
#include <bits/stdc++.h>
#include <ext/rope>
 
using namespace std;
using namespace __gnu_cxx;
#pragma GCC optimize("-Ofast")
#pragma GCC optimize("-O1")
//-------------------------------------------------------------//
typedef long long ll;
typedef unsigned long long ull;
#define PI acos(-1)
#define lb lower_bound
#define ub upper_bound
#define endl '\n'
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define sum_to(n) (n*(n+1))/2
#define pb push_back
#define pf push_front
#define fil(arr,x) memset(arr,x,sizeof(arr))
const ll mod=1e9+7;
int dx[8]={0,1,0,-1,1,1,-1,-1};
int dy[8]={1,0,-1,0,1,-1,-1,1};
//-------------------------------------------------------------//
ll lcm(ll a,ll b)
{
    return (max(a,b)/__gcd(a,b))*min(a,b);
}
void person_bool(bool x)
{
    cout<<(x?"YES":"NO")<<endl;
}
const int N=2e5+5,R=25005;
vector<int>adj[N],arr[R];
int n,r,q,mark=1,t[N],s[N],e[N];
void dfs(int node,int par){
    s[node]=mark++;
    for(auto i:adj[node])
        if(i!=par)
            dfs(i,node);
    e[node]=mark-1;
}
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    #ifndef ONLINE_JUDGE
    freopen("input.in", "r", stdin);
    freopen("output.out", "w", stdout);
    #endif
    cin>>n>>r>>q;
    cin>>t[1];arr[t[1]].push_back(1);
    for(int i=2;i<=n;i++){
        int x;cin>>x;
        cin>>t[i];
        arr[t[i]].push_back(i);
        adj[x].push_back(i);
    }
    dfs(1,1);
    while(q--){
        int a,b;cin>>a>>b;
        vector<int>v;
        for(auto i:arr[b])v.push_back(s[i]);
        sort(all(v));
        int ans=0;
        for(auto i:arr[a]){
            int x=upper_bound(all(v),s[i])-v.begin();
            int y=upper_bound(all(v),e[i])-v.begin();
            ans+=y-x;
        }
        cout<<ans<<endl;
    }
    return 0;
}

Compilation message

regions.cpp: In function 'int main()':
regions.cpp:52:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |     freopen("input.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
regions.cpp:53:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   53 |     freopen("output.out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 5720 KB Unexpected end of file - int32 expected
2 Incorrect 1 ms 5720 KB Unexpected end of file - int32 expected
3 Incorrect 2 ms 5720 KB Unexpected end of file - int32 expected
4 Incorrect 1 ms 5972 KB Unexpected end of file - int32 expected
5 Incorrect 2 ms 5720 KB Unexpected end of file - int32 expected
6 Incorrect 2 ms 5720 KB Unexpected end of file - int32 expected
7 Incorrect 2 ms 5720 KB Unexpected end of file - int32 expected
8 Incorrect 2 ms 5720 KB Unexpected end of file - int32 expected
9 Incorrect 2 ms 5732 KB Unexpected end of file - int32 expected
10 Incorrect 2 ms 5720 KB Unexpected end of file - int32 expected
11 Incorrect 2 ms 5816 KB Unexpected end of file - int32 expected
12 Incorrect 2 ms 5720 KB Unexpected end of file - int32 expected
13 Incorrect 2 ms 5720 KB Unexpected end of file - int32 expected
14 Incorrect 2 ms 5720 KB Unexpected end of file - int32 expected
15 Incorrect 2 ms 5720 KB Unexpected end of file - int32 expected
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 5720 KB Unexpected end of file - int32 expected
2 Incorrect 2 ms 5720 KB Unexpected end of file - int32 expected
3 Incorrect 2 ms 5720 KB Unexpected end of file - int32 expected
4 Incorrect 2 ms 5720 KB Unexpected end of file - int32 expected
5 Incorrect 2 ms 5720 KB Unexpected end of file - int32 expected
6 Incorrect 2 ms 5720 KB Unexpected end of file - int32 expected
7 Incorrect 2 ms 5720 KB Unexpected end of file - int32 expected
8 Incorrect 2 ms 5720 KB Unexpected end of file - int32 expected
9 Incorrect 2 ms 5720 KB Unexpected end of file - int32 expected
10 Incorrect 2 ms 5720 KB Unexpected end of file - int32 expected
11 Incorrect 2 ms 5720 KB Unexpected end of file - int32 expected
12 Incorrect 2 ms 5720 KB Unexpected end of file - int32 expected
13 Incorrect 1 ms 5720 KB Unexpected end of file - int32 expected
14 Incorrect 1 ms 5720 KB Unexpected end of file - int32 expected
15 Incorrect 1 ms 5720 KB Unexpected end of file - int32 expected
16 Incorrect 1 ms 5720 KB Unexpected end of file - int32 expected
17 Incorrect 2 ms 5720 KB Unexpected end of file - int32 expected