답안 #889598

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
889598 2023-12-20T03:41:19 Z vjudge1 Tourism (JOI23_tourism) C++17
0 / 100
19 ms 12160 KB
#include <bits/stdc++.h>
#define ll long long
#define str string
#define ins insert
#define ld long double
#define pb push_back
#define pf push_front
#define pof pop_front()
#define pob pop_back()
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define fr first
#define sc second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define sz size()
#define bc back()
#define ar array
#define vll vector<ll> 
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <class _T>
bool chmin(_T &x, const _T &y){
    if(x>y){
        x=y;
        return true;
    }
    return false;
}
template <class _T>
bool chmax(_T &x, const _T &y){
    bool flag=false;
    if (x<y){
        x=y;flag|=true;
    }
    return flag;
}
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>
void fre(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
void start(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
const ll inf=2e18+7;
const ll mod=1e9+7;
const ll N=1e5+7;
const ld eps=1e-9;
vector<vll> g(N);
vector<pair<ll,ll>> t(N*4,{inf,0});
ll val[N];
void build(ll v,ll tl,ll tr){
	if(tl==tr){
		t[v]={val[tl],val[tl]};
		return;
	}
	ll tm=(tl+tr)/2;
	build(v*2,tl,tm);
	build(v*2+1,tm+1,tr);
	t[v]={min(t[v*2].fr,t[v*2+1].fr),max(t[v*2].sc,t[v*2+1].sc)};
}

pair<ll,ll> get(ll v,ll tl,ll tr,ll l,ll r){
	if(tl>r || tr<l)return {inf,0ll};
	if(l<=tl && tr<=r) return t[v];
	ll tm=(tl+tr)/2;
	pair<ll,ll> a=get(v*2,tl,tm,l,r);
	pair<ll,ll> b=get(v*2+1,tm+1,tr,l,r);
	return {min(a.fr,b.fr),max(a.sc,b.sc)};
}

bool f[2005];
ll dfs(ll v,ll p){
	ll sum=0;
	for(auto i : g[v]){
		if(i==p)continue;
		sum+=dfs(i,v);
	}
	if(f[v] || sum) return sum+1;
	return sum;
}
void solve(){
	ll i,j;
	ll n,m,q;
	ll a,b;
	cin>>n>>m>>q;
	bool line=true,bint=true;
	//bool flag=true;
	for(i=1;i<n;i++){
		cin>>a>>b;
		if(a>b)swap(a,b);
		if(b-a!=1)line=false;
		if(b/2!=a)bint=false;
		g[a].pb(b);
		g[b].pb(a);
	}
	vector<ll> s(m+1);
	for(i=1;i<=m;i++)cin>>s[i];
	if(line){
		for(i=1;i<=m;i++)val[i]=s[i];
		build(1,1,n);
		for(i=0;i<q;i++){
			cin>>a>>b;
			pair<ll,ll> x=get(1,1,n,a,b);
			cout<<x.sc-x.fr+1<<endl;
		}
		return;
	}
	if(n<=2000 && m<=2000 && q<=2000){
		for(i=1;i<=q;i++){
			memset(f,false,sizeof(f));
			cin>>a>>b;
			for(j=a;j<=b;j++)f[s[j]]=true;
			cout<<dfs(a,0)<<endl;
		}
		return;
	}
	if(bint){
		
		return;
	}
	
}
signed main(){
	start();
    ll t=1;
	//cin>>t;
    while(t--) solve();
    return 0;
}
/*
1
6
5 4 3 2 1 0





*/

Compilation message

tourism.cpp: In function 'void fre(std::string)':
tourism.cpp:42:27: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 | void fre(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
      |                    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tourism.cpp:42:64: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 | void fre(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
      |                                                         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 9048 KB Output is correct
2 Correct 3 ms 9052 KB Output is correct
3 Incorrect 3 ms 9052 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 9048 KB Output is correct
2 Correct 3 ms 9052 KB Output is correct
3 Incorrect 3 ms 9052 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 9052 KB Output is correct
2 Incorrect 3 ms 9052 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 9052 KB Output is correct
2 Incorrect 19 ms 12160 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 9052 KB Output is correct
2 Incorrect 4 ms 8984 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 9048 KB Output is correct
2 Correct 3 ms 9052 KB Output is correct
3 Incorrect 3 ms 9052 KB Output isn't correct
4 Halted 0 ms 0 KB -