Submission #933458

# Submission time Handle Problem Language Result Execution time Memory
933458 2024-02-25T17:21:02 Z thunopro Regions (IOI09_regions) C++14
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>
using namespace std ; 
#define maxn 200009
#define ll long long 
#define pb push_back 
#define fi first 
#define se second 
#define left id<<1
#define right id<<1|1 
#define re exit(0); 
#define _lower(x) lower_bound(v.begin(),v.end(),x)-v.begin()+1
const int mod = 1e9+7 ;
const int INF = 1e9 ; 

typedef vector<int> vi ; 
typedef pair<int,int> pii ; 
typedef vector<pii> vii ; 

template < typename T > void chkmin ( T &a , T b ) { if ( a > b ) a = b ; } 
template < typename T > void chkmax ( T &a , T b ) { if ( a < b ) a = b ; } 

void add ( int &a , int b ) 
{
	a += b ; 
	if ( a >= mod ) a -= mod ; 
	if ( a < 0 ) a += mod ; 
}

void rf () 
{
	freopen ("bai1.inp","r",stdin) ;
}

int _pow ( int a , int n ) 
{
	if ( n == 0 ) return 1 ; 
	int res = _pow (a,n/2) ; 
	if ( n % 2 ) return 1ll*res*res%mod*a%mod ; 
	else return 1ll*res*res%mod ; 
}

int n , region , nq ; 

vi adjList [maxn] , R [maxn] , FR [maxn] ;  
int group [maxn] ; 
int num , ver [maxn] , cnt [maxn] ; 
int tin [maxn] , tout [maxn] , timeDfs ; 
int ans [202][maxn] ; 

void dfs ( int u ) 
{
	tin [u] = ++ timeDfs ; 
	euler [timeDfs] = u ; 
	for ( auto v : adjList [u] ) dfs (v) ; 
	tout [u] = timeDfs ; 
}
int main () 
{
	ios_base::sync_with_stdio(0); 
	cin.tie(0);cout.tie(0); 
//	rf () ; 
	cin >> n >> region >> nq ; 
	for ( int i = 1 ; i <= n ; i ++ ) 
	{
		int x , r ; 
		if ( i != 1 ) cin >> x , adjList [x] . pb (i) ; 
		cin >> r ;
		group [i] = r ; 
		R [r] . pb (i) ; 
	}
	
	dfs (1) ; 

	for ( int i = 1 ; i <= n ; i ++ ) FR[group[i]] . pb (tin[i]) ; 
	for ( int i = 1 ; i <= region ; i ++ ) sort (FR[i].begin(),FR[i].end()) ; 
	
	for ( int r = 1 ; r <= region ; r ++ ) 
	{
		if ( R [r].size () >= 1000 ) 
		{
			++ num ; 
			ver [r] = num ; 
			for ( auto x : R [r] ) 
			{
				cnt [tin[x]] ++ , cnt [tout[x]+1] -- ; 
			}
			for ( int i = 1 ; i <= n ; i ++ ) 
			{
				cnt [i] += cnt [i-1] ; 
				ans [num][group[euler[i]]] += cnt [i] ; 
			}
			for ( int i = 1 ; i <= n ; i ++ ) cnt [i] = 0 ; 
		}
	}
	
	for ( int r = 1 ; r <= nq ; r ++ ) 
	{
		int x , y ; cin >> x >> y ; 
		if ( ver [x] != 0 ) cout << ans [ver[x]][y] << endl ; 
		else 
		{
			int res = 0 ; 
			for ( auto i : R [x] ) 
			{
				res += upper_bound (FR[y].begin(),FR[y].end(),tout[i]) - lower_bound (FR[y].begin(),FR[y].end(),tin[i]) ; 
			}
			cout << res << endl ; 
		}
	}
}

Compilation message

regions.cpp: In function 'void dfs(int)':
regions.cpp:53:2: error: 'euler' was not declared in this scope
   53 |  euler [timeDfs] = u ;
      |  ^~~~~
regions.cpp: In function 'int main()':
regions.cpp:90:21: error: 'euler' was not declared in this scope
   90 |     ans [num][group[euler[i]]] += cnt [i] ;
      |                     ^~~~~
regions.cpp: In function 'void rf()':
regions.cpp:31:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |  freopen ("bai1.inp","r",stdin) ;
      |  ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~