답안 #986400

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
986400 2024-05-20T12:50:17 Z Pyqe 늑대인간 (IOI18_werewolf) C++17
100 / 100
797 ms 158768 KB
#include <bits/stdc++.h>
#include "werewolf.h"

using namespace std;

#define mp make_pair
#define fr first
#define sc second

long long n,m,dsu[200069],pst[200069],sbt[200069],pr[200069][18],cc[200069];
vector<long long> al[200069],al2[200069];
pair<pair<long long,long long>,long long> qq[200069];
pair<long long,long long> qs[200069];
multiset<long long> ms[200069];
bitset<200069> sq;

long long fd(long long x)
{
	if(dsu[x]!=x)
	{
		dsu[x]=fd(dsu[x]);
	}
	return dsu[x];
}

void bd(long long x)
{
	long long i,j,sz=al2[x].size(),l;
	
	n++;
	pst[x]=n;
	sbt[x]=1;
	for(i=0;i<sz;i++)
	{
		l=al2[x][i];
		pr[l][0]=x;
		for(j=1;j<18;j++)
		{
			pr[l][j]=pr[pr[l][j-1]][j-1];
		}
		bd(l);
		sbt[x]+=sbt[l];
	}
}

void jo(long long x,long long y)
{
	multiset<long long>::iterator it;
	
	x=fd(x);
	y=fd(y);
	if(cc[x]<cc[y])
	{
		swap(x,y);
	}
	for(it=ms[y].begin();it!=ms[y].end();it++)
	{
		ms[x].insert(*it);
	}
	cc[x]+=cc[y];
	dsu[y]=x;
}

vector<int> check_validity(int on,vector<int> ka,vector<int> la,vector<int> sta,vector<int> fna,vector<int> lba,vector<int> rba)
{
	long long t=sta.size(),rr,i,j,k,l,w,sz,pz;
	multiset<long long>::iterator it;
	vector<int> v;
	
	n=on;
	m=ka.size();
	for(i=0;i<m;i++)
	{
		k=ka[i]+1;
		l=la[i]+1;
		al[k].push_back(l);
		al[l].push_back(k);
	}
	for(i=n;i;i--)
	{
		dsu[i]=i;
		sz=al[i].size();
		for(j=0;j<sz;j++)
		{
			l=al[i][j];
			if(l>i&&fd(l)!=i)
			{
				al2[i].push_back(fd(l));
				dsu[fd(l)]=i;
			}
		}
	}
	n=0;
	bd(1);
	for(rr=1;rr<=t;rr++)
	{
		qq[rr]={{sta[rr-1]+1,fna[rr-1]+1},lba[rr-1]+1};
		qs[rr]={rba[rr-1]+1,rr};
	}
	sort(qs+1,qs+t+1);
	for(i=0,rr=1;rr<=t;rr++)
	{
		k=qs[rr].fr;
		pz=qs[rr].sc;
		for(;i<k;)
		{
			i++;
			dsu[i]=i;
			cc[i]=1;
			ms[i].insert(pst[i]);
			sz=al[i].size();
			for(j=0;j<sz;j++)
			{
				l=al[i][j];
				if(l<i&&fd(l)!=fd(i))
				{
					jo(i,l);
				}
			}
		}
		k=qq[pz].fr.fr;
		l=qq[pz].fr.sc;
		w=qq[pz].sc;
		for(j=17;j+1;j--)
		{
			if(pr[k][j]>=w)
			{
				k=pr[k][j];
			}
		}
		it=ms[fd(l)].lower_bound(pst[k]);
		sq[pz]=it!=ms[fd(l)].end()&&*it<=pst[k]+sbt[k]-1;
	}
	for(rr=1;rr<=t;rr++)
	{
		v.push_back(sq[rr]);
	}
	return v;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 29272 KB Output is correct
2 Correct 6 ms 29276 KB Output is correct
3 Correct 6 ms 29276 KB Output is correct
4 Correct 6 ms 29316 KB Output is correct
5 Correct 6 ms 29276 KB Output is correct
6 Correct 7 ms 29276 KB Output is correct
7 Correct 6 ms 29276 KB Output is correct
8 Correct 7 ms 29116 KB Output is correct
9 Correct 7 ms 29272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 29272 KB Output is correct
2 Correct 6 ms 29276 KB Output is correct
3 Correct 6 ms 29276 KB Output is correct
4 Correct 6 ms 29316 KB Output is correct
5 Correct 6 ms 29276 KB Output is correct
6 Correct 7 ms 29276 KB Output is correct
7 Correct 6 ms 29276 KB Output is correct
8 Correct 7 ms 29116 KB Output is correct
9 Correct 7 ms 29272 KB Output is correct
10 Correct 10 ms 30044 KB Output is correct
11 Correct 12 ms 30412 KB Output is correct
12 Correct 10 ms 30300 KB Output is correct
13 Correct 10 ms 30040 KB Output is correct
14 Correct 9 ms 29988 KB Output is correct
15 Correct 10 ms 30300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 682 ms 157376 KB Output is correct
2 Correct 563 ms 116172 KB Output is correct
3 Correct 446 ms 120180 KB Output is correct
4 Correct 471 ms 128336 KB Output is correct
5 Correct 475 ms 129744 KB Output is correct
6 Correct 601 ms 136228 KB Output is correct
7 Correct 614 ms 158768 KB Output is correct
8 Correct 496 ms 116124 KB Output is correct
9 Correct 377 ms 120264 KB Output is correct
10 Correct 376 ms 128392 KB Output is correct
11 Correct 403 ms 129576 KB Output is correct
12 Correct 494 ms 137088 KB Output is correct
13 Correct 592 ms 124300 KB Output is correct
14 Correct 571 ms 124104 KB Output is correct
15 Correct 589 ms 124344 KB Output is correct
16 Correct 655 ms 124108 KB Output is correct
17 Correct 641 ms 157992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 29272 KB Output is correct
2 Correct 6 ms 29276 KB Output is correct
3 Correct 6 ms 29276 KB Output is correct
4 Correct 6 ms 29316 KB Output is correct
5 Correct 6 ms 29276 KB Output is correct
6 Correct 7 ms 29276 KB Output is correct
7 Correct 6 ms 29276 KB Output is correct
8 Correct 7 ms 29116 KB Output is correct
9 Correct 7 ms 29272 KB Output is correct
10 Correct 10 ms 30044 KB Output is correct
11 Correct 12 ms 30412 KB Output is correct
12 Correct 10 ms 30300 KB Output is correct
13 Correct 10 ms 30040 KB Output is correct
14 Correct 9 ms 29988 KB Output is correct
15 Correct 10 ms 30300 KB Output is correct
16 Correct 682 ms 157376 KB Output is correct
17 Correct 563 ms 116172 KB Output is correct
18 Correct 446 ms 120180 KB Output is correct
19 Correct 471 ms 128336 KB Output is correct
20 Correct 475 ms 129744 KB Output is correct
21 Correct 601 ms 136228 KB Output is correct
22 Correct 614 ms 158768 KB Output is correct
23 Correct 496 ms 116124 KB Output is correct
24 Correct 377 ms 120264 KB Output is correct
25 Correct 376 ms 128392 KB Output is correct
26 Correct 403 ms 129576 KB Output is correct
27 Correct 494 ms 137088 KB Output is correct
28 Correct 592 ms 124300 KB Output is correct
29 Correct 571 ms 124104 KB Output is correct
30 Correct 589 ms 124344 KB Output is correct
31 Correct 655 ms 124108 KB Output is correct
32 Correct 641 ms 157992 KB Output is correct
33 Correct 750 ms 128692 KB Output is correct
34 Correct 230 ms 71136 KB Output is correct
35 Correct 790 ms 124368 KB Output is correct
36 Correct 692 ms 130648 KB Output is correct
37 Correct 658 ms 123800 KB Output is correct
38 Correct 745 ms 128060 KB Output is correct
39 Correct 729 ms 110448 KB Output is correct
40 Correct 713 ms 135300 KB Output is correct
41 Correct 596 ms 124196 KB Output is correct
42 Correct 584 ms 130032 KB Output is correct
43 Correct 797 ms 129420 KB Output is correct
44 Correct 633 ms 124172 KB Output is correct
45 Correct 488 ms 111620 KB Output is correct
46 Correct 479 ms 110540 KB Output is correct
47 Correct 644 ms 124632 KB Output is correct
48 Correct 609 ms 124336 KB Output is correct
49 Correct 584 ms 124616 KB Output is correct
50 Correct 595 ms 124360 KB Output is correct
51 Correct 588 ms 134488 KB Output is correct
52 Correct 578 ms 134572 KB Output is correct