답안 #94953

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
94953 2019-01-25T16:33:12 Z MvC 동기화 (JOI13_synchronization) C++11
0 / 100
8000 ms 22636 KB
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<61);
const int inf=(1<<30);
const int nmax=2e5+50;
const int mod=1e9+7;
using namespace std;
int x,y,i,n,up[nmax][20],tin[nmax],tout[nmax],t,v,ans[nmax],q,m,fw[nmax],lst[nmax];
vector<int>a[nmax];
vector<pair<int,int> >e;
void dfs(int x,int p)
{
    tin[x]=++t;
    if(p)up[x][0]=p;
    else up[x][0]=1;
    for(int i=1;i<20;i++)up[x][i]=up[up[x][i-1]][i-1];
    for(int i=0;i<a[x].size();i++)if(a[x][i]!=p)dfs(a[x][i],x);
    tout[x]=t+1;
}
void upd(int i,int v)
{
	for(;i<tout[1];i+=i&(-i))fw[i]+=v;
}
int qry(int x)
{
	int rs=0;
	for(;i>=1;i-=i&(-i))rs+=fw[i];
	return rs;
}
int get(int x)
{
	int y=qry(tin[x]);
	for(int i=19;i>=0;i--)if(qry(up[x][i])==y)x=up[x][i];
	return x;
}
int main()
{
	//freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
    cin>>n>>m>>q;
    for(i=1;i<n;i++)
    {
        cin>>x>>y;
        e.pb({x,y});
        a[x].pb(y);
        a[y].pb(x);
    }
    dfs(1,1);
    for(i=0;i<n-1;i++)if(tin[e[i].fr]>tin[e[i].sc])swap(e[i].fr,e[i].sc);
	for(i=1;i<=n;i++)
	{
		upd(tin[i],1);
		upd(tout[i],-1);
		ans[i]=1;
	}
	while(m--)
	{
		cin>>i;
		x=e[i+1].fr,y=e[i+1].sc,v=get(x);
		if(lst[i]==-1)
		{
			upd(tin[y],1);
			upd(tout[y],-1);
			ans[y]=lst[i]=ans[v];
		}
		else
		{
			upd(tin[y],-1);
			upd(tout[y],1);
			ans[v]+=ans[y]-lst[i];
			lst[i]=-1;
		}
	}
	while(q--)
	{
		cin>>x;
		cout<<ans[get(x)]<<endl;
	}
    return 0;
}

Compilation message

synchronization.cpp: In function 'void dfs(int, int)':
synchronization.cpp:26:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<a[x].size();i++)if(a[x][i]!=p)dfs(a[x][i],x);
                 ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 8039 ms 4984 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 8058 ms 21100 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 8032 ms 5112 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 8087 ms 22636 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 8015 ms 4984 KB Time limit exceeded
2 Halted 0 ms 0 KB -