QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#167164#367. Long MansionLynkcat5 18ms33064kbC++201.8kb2023-09-07 11:22:172023-09-07 11:22:18

Judging History

你现在查看的是最新测评结果

  • [2023-09-07 11:22:18]
  • 评测
  • 测评结果:5
  • 用时:18ms
  • 内存:33064kb
  • [2023-09-07 11:22:17]
  • 提交

answer

// Lynkcat.
// Problem: #2397. 「JOISC 2017 Day 3」幽深府邸
// URL: https://loj.ac/p/2397
// Memory Limit: 256 MB
// Time Limit: 3000 ms
// -----------------------------------------------

//我耳朵瞎掉拉~~
#include<bits/stdc++.h>
#define poly vector<int>
#define IOS ios::sync_with_stdio(false)
#define ll long long
#define mp make_pair
#define mt make_tuple
#define pa pair < int,int >
#define fi first
#define se second
#define inf 1e18
#define mod 998244353
#define int ll
#define N 500005
using namespace std;
int n,c[N],l[N],r[N];
poly G[N],E[N];
int m;
int query(int x,int l,int r)
{
	return (lower_bound(G[x].begin(),G[x].end(),l)-G[x].begin())!=(lower_bound(G[x].begin(),G[x].end(),r+1)-G[x].begin());
}
void BellaKira()
{
	cin>>n;
	for (int i=1;i<n;i++)
		cin>>c[i];
	for (int i=1;i<=n;i++)
	{
		int x;
		cin>>x;
		while (x--)
		{
			int y;
			cin>>y;
			G[y].push_back(i);
			E[i].push_back(y);
		}
	}
	r[n]=n;
	for (int i=n-1;i>=1;i--)
	{
		r[i]=i;
		while (r[i]<n&&query(c[r[i]],i,r[i]))
		{
			r[i]=r[r[i]+1];
		}
	}
	l[1]=1;
	for (int i=2;i<=n;i++)
	{
		l[i]=i;
		while (l[i]>1&&query(c[l[i]-1],l[i],i))
		{
			l[i]=l[l[i]-1];
		}
	}
	for (int i=2;i<=n;i++)
	{
		l[i]=i;
		while ((l[i]>1&&query(c[l[i]-1],l[i],r[i]))||(r[i]<n&&query(c[r[i]],l[i],r[i])))
		{
			if ((l[i]>1&&query(c[l[i]-1],l[i],r[i])))
			{
				r[i]=max(r[i],r[l[i]-1]);
				l[i]=l[l[i]-1];
			}
			if ((r[i]<n&&query(c[r[i]],l[i],r[i])))
			{
				l[i]=min(l[i],l[r[i]+1]);
				r[i]=r[r[i]+1];
			}
		}
	}
	cin>>m;
	for (int i=1;i<=m;i++)
	{
		int x,y;
		cin>>x>>y;
		if (l[x]<=y&&y<=r[x]) cout<<"YES"<<'\n';
		else cout<<"NO"<<'\n';
	}
}
signed main()
{
	IOS;
	int T=1;
	while (T--)
	{
		BellaKira();
	}
}

詳細信息

Subtask #1:

score: 5
Accepted

Test #1:

score: 5
Accepted
time: 13ms
memory: 32952kb

input:

2000
10 7 7 6 12 13 3 13 10 13 10 4 1 12 13 10 10 11 14 9 2 15 15 12 6 1 7 11 14 2 4 12 15 2 4 1 7 3 8 1 10 9 10 9 1 1 3 3 10 8 14 7 15 12 4 15 13 14 13 2 6 9 12 6 12 10 11 9 15 8 15 11 2 7 9 13 14 1 1 10 14 13 13 14 15 6 8 2 1 11 11 5 4 4 13 3 6 6 12 13 1 10 6 1 15 14 6 4 7 4 13 5 1 2 11 1 8 10 7 7...

output:

NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO...

result:

ok 5000 lines

Test #2:

score: 0
Accepted
time: 11ms
memory: 33064kb

input:

3000
1 4 1 3 3 4 1 2 4 1 2 3 4 2 3 4 4 1 3 1 4 2 2 4 3 3 2 1 3 2 1 3 4 4 3 2 3 2 2 4 4 1 1 3 4 1 4 1 4 1 3 3 4 1 2 1 2 4 2 1 2 1 2 3 3 3 4 2 3 2 1 2 2 1 1 1 1 1 3 3 4 1 4 4 4 4 4 1 2 4 2 2 3 3 4 2 4 3 1 2 4 1 2 1 4 1 4 4 1 3 4 3 1 2 1 3 3 2 1 2 1 2 2 4 3 3 2 4 3 3 3 1 2 1 2 4 4 1 4 1 2 1 4 4 2 2 4 2...

output:

NO
YES
NO
NO
YES
NO
YES
YES
NO
YES
NO
NO
NO
NO
YES
YES
NO
YES
YES
YES
NO
NO
NO
YES
NO
NO
YES
YES
YES
NO
YES
YES
NO
NO
NO
NO
YES
NO
NO
YES
YES
NO
NO
YES
NO
YES
YES
YES
NO
NO
NO
NO
YES
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
YES
NO
NO
YES
NO
NO
NO
YES
NO
YES
NO
NO
NO
YES
YES
YES
YES
NO
YES
NO
NO
NO
NO
NO
NO
NO...

result:

ok 5000 lines

Test #3:

score: 0
Accepted
time: 7ms
memory: 32932kb

input:

5000
1 2 1 1 2 1 2 2 1 1 1 1 1 2 1 1 1 1 2 1 1 1 1 1 1 2 2 2 1 2 1 2 2 2 1 2 2 1 1 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 1 2 1 1 2 2 2 2 1 2 2 2 1 2 2 2 1 1 1 1 1 2 2 1 2 1 2 2 1 1 2 1 1 2 1 2 2 1 2 2 1 1 2 1 1 1 2 2 2 2 2 1 1 1 1 2 2 1 2 2 1 2 1 2 2 1 2 2 1 2 2 2 2 1 1 1 1 2 1 2 1 1 1 1 2 2 2 2 1 1 2 1 1 1...

output:

YES
YES
NO
NO
NO
NO
YES
YES
YES
YES
YES
NO
NO
YES
YES
YES
YES
YES
YES
YES
YES
NO
NO
YES
NO
NO
YES
YES
YES
NO
YES
YES
YES
NO
YES
NO
NO
NO
YES
YES
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
NO
YES
NO
YES
YES
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
YES
NO
NO
YES
...

result:

ok 5000 lines

Test #4:

score: 0
Accepted
time: 3ms
memory: 33024kb

input:

2000
583 580 319 242 218 934 584 174 18 1224 1376 793 803 842 1430 1269 1442 225 1470 376 1017 352 1081 587 689 582 492 930 918 1266 105 598 1273 343 1047 1499 247 1409 1061 1246 1248 324 1362 1254 208 1448 1438 58 1125 270 1029 355 555 212 881 1232 1093 351 1353 1436 236 498 28 635 187 1439 1257 14...

output:

NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
YES
NO
NO
YES
YES
NO
NO
YES
YES
NO
NO
YES
YES
NO
NO
YES
YES
NO
NO
YES
YES
NO
NO
YES
YES
NO
NO
YES
YES
NO
NO
YES
YES
NO
NO
YES
NO
NO
YES
YES
NO
NO
YES
YES
NO
NO
YES
YES
NO
NO
YES
YES
NO
NO
YES
YES
NO
NO
YES
YES
NO
NO
YES
YES
NO
NO
YES
YES
NO
NO
YES
YES
NO
NO
YES
YES
...

result:

ok 5000 lines

Test #5:

score: 0
Accepted
time: 18ms
memory: 31560kb

input:

2000
32 16 47 21 12 29 8 37 50 11 22 44 1 17 3 16 19 43 27 23 32 20 28 12 30 36 12 13 24 22 30 7 45 27 33 19 3 7 3 2 33 13 3 40 26 34 42 8 25 42 28 16 48 31 46 43 45 4 37 35 37 46 43 13 3 12 40 20 8 20 47 6 19 3 16 8 21 37 24 30 44 49 34 21 18 41 23 38 13 9 39 50 40 43 17 2 15 31 43 17 8 11 4 41 35 ...

output:

YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
YES
YES
YES
YES
NO
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YE...

result:

ok 5000 lines

Test #6:

score: 0
Accepted
time: 9ms
memory: 32108kb

input:

2000
393 319 1075 467 1727 78 1638 314 1362 1450 906 1073 899 1271 1520 1329 1545 170 962 1240 234 1392 593 184 1177 1387 426 130 1896 1179 407 1322 607 1589 1825 1959 1525 1442 499 1177 139 998 682 1095 1944 1626 1161 917 831 1289 553 1406 653 644 1694 1476 1342 451 52 881 1519 1465 792 1544 862 13...

output:

NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
YES
YES
NO
NO
YES
YES
NO
YES
YES
NO
NO
YES
YES
NO
NO
YES
YES
NO
YES
YES
NO
NO
YES
YES
NO
NO
YES
YES
NO
NO
YES
YES
NO
NO
YES
YES
NO
YES
YES
NO
NO
YES
YES
NO
NO
YES
YES
NO
NO
YES
YES
NO
YES
YES
NO
NO
YES
YES
NO
NO
YES
YES
NO
YES
YES
NO
NO
YES
YES
NO
NO
YES
YES
NO
NO
YES
...

result:

ok 5000 lines

Test #7:

score: 0
Accepted
time: 12ms
memory: 32440kb

input:

2000
1600 1598 1596 1594 1592 1590 1588 1586 1584 1582 1580 1578 1576 1574 1572 1570 1568 1566 1564 1562 1560 1558 1556 1554 1552 1550 1548 1546 1544 1542 1540 1538 1536 1534 1532 1530 1528 1526 1524 1522 1520 1518 1516 1514 1512 1510 1508 1506 1504 1502 1500 1498 1496 1494 1492 1490 1488 1486 1484 ...

output:

YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
YES
YES
YES
NO
NO
NO
NO
NO
NO
YES
YES
YES
NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
NO
YES
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
YES
NO
NO
NO
NO
N...

result:

ok 5000 lines

Subtask #2:

score: 0
Time Limit Exceeded

Dependency #1:

100%
Accepted

Test #8:

score: 0
Time Limit Exceeded

input:

2000
2 6 4 1 2 7 2 2 7 6 8 4 8 7 4 5 5 10 8 7 1 1 3 1 1 5 10 2 6 1 5 10 4 5 3 1 1 9 10 9 6 2 5 2 1 10 3 8 4 3 1 3 7 6 10 1 7 1 7 1 1 6 5 10 9 8 1 10 7 5 2 9 9 8 5 3 10 7 4 3 3 9 5 8 4 3 1 6 3 4 1 4 1 9 2 5 5 6 3 10 10 7 1 4 5 4 10 1 10 2 7 4 10 10 3 2 7 4 5 8 3 6 1 6 6 8 10 3 7 8 6 9 4 1 5 8 6 8 5 3...

output:

NO
YES
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
NO
NO
NO
NO
YES
NO
NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
N...

result:


Subtask #3:

score: 0
Time Limit Exceeded

Test #27:

score: 0
Time Limit Exceeded

input:

100000
2 7 4 20 14 19 16 3 15 15 6 18 12 2 2 16 14 15 2 9 5 16 12 6 10 9 18 6 15 11 7 15 20 7 12 1 12 17 4 19 15 5 6 19 3 1 6 18 19 15 3 1 3 3 16 8 20 20 1 3 3 11 1 4 5 20 10 2 19 9 13 20 11 11 5 9 19 3 19 16 13 7 16 20 8 9 19 14 11 9 9 20 16 20 7 6 13 15 3 4 15 15 4 10 15 3 16 5 18 17 19 7 7 2 10 2...

output:

NO
NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO...

result:


Subtask #4:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%