# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
60435 |
2018-07-24T07:53:01 Z |
정원준(#1745) |
Long Mansion (JOI17_long_mansion) |
C++11 |
|
3000 ms |
35388 KB |
#include <bits/stdc++.h>
#define L long long
using namespace std;
L n,q;
L sz[500010];
L cor[500010];
L lef[500010],rig[500010];
L lefte[500010],rigte[500010];
L trl[2000040],trr[2000040];
L chk[500050],chkcolor;
vector<L>v[500050];
void initl(L now,L S,L E){
trl[now]=n+1;
if(S==E) return;
L mid=(S+E)/2;
initl(now*2,S,mid);
initl(now*2,mid+1,E);
}
void updatel(L now,L S,L E,L loc,L val){
if(S>loc||E<loc) return;
if(S==E)
{
trl[now]=min(trl[now],val);
return;
}
L mid=(S+E)/2;
updatel(now*2,S,mid,loc,val);
updatel(now*2+1,mid+1,E,loc,val);
trl[now]=min(trl[now*2],trl[now*2+1]);
}
L getl(L now,L S,L E,L s,L e){
if(S>e||E<s) return n+1;
if(s<=S&&E<=e) return trl[now];
L mid=(S+E)/2;
return min(getl(now*2,S,mid,s,e),getl(now*2+1,mid+1,E,s,e));
}
void initr(L now,L S,L E){
trr[now]=-1;
if(S==E) return;
L mid=(S+E)/2;
initr(now*2,S,mid);
initr(now*2,mid+1,E);
}
void updater(L now,L S,L E,L loc,L val){
if(S>loc||E<loc) return;
if(S==E)
{
trr[now]=max(trr[now],val);
return;
}
L mid=(S+E)/2;
updater(now*2,S,mid,loc,val);
updater(now*2+1,mid+1,E,loc,val);
trr[now]=max(trr[now*2],trr[now*2+1]);
}
L getr(L now,L S,L E,L s,L e){
if(S>e||E<s) return -1;
if(s<=S&&E<=e) return trr[now];
L mid=(S+E)/2;
return max(getr(now*2,S,mid,s,e),getr(now*2+1,mid+1,E,s,e));
}
int main()
{
scanf("%lld",&n);
L i,j;
for(i=1;i<n;i++)
{
scanf("%lld",&cor[i]);
}
for(i=1;i<=n;i++)
{
scanf("%lld",&sz[i]);
for(j=1;j<=sz[i];j++)
{
L sctemp;
scanf("%lld",&sctemp);
v[i].push_back(sctemp);
}
}
initl(1,1,n);
initr(1,1,n);
for(i=1;i<=n;i++)
{
lef[i]=rig[i]=i;
updatel(1,1,n,i,lef[i]);
updater(1,1,n,i,rig[i]);
}
for(i=1;i<=22;i++)
{
for(j=1;j<=n;j++)
{
L templ=getl(1,1,n,1,lef[j]);
lefte[j]=min(lef[j],templ);
L tempr=getr(1,1,n,1,rig[j]);
rigte[j]=max(rig[j],tempr);
}
for(j=1;j<=n;j++)
{
lef[j]=lefte[j];
rig[j]=rigte[j];
updatel(1,1,n,i,lef[i]);
updater(1,1,n,i,rig[i]);
}
}
for(i=1;i<=n;i++)
{
chkcolor++;
lef[i]=rig[i]=i;
for(j=0;j<v[i].size();j++)
{
chk[v[i][j]]=chkcolor;
}
while(1)
{
if(lef[i]>1&&chk[cor[lef[i]-1]]==chkcolor)
{
lef[i]--;
for(j=0;j<v[lef[i]].size();j++)
{
chk[v[lef[i]][j]]=chkcolor;
}
}
else if(rig[i]<n&&chk[cor[rig[i]]]==chkcolor)
{
rig[i]++;
for(j=0;j<v[rig[i]].size();j++)
{
chk[v[rig[i]][j]]=chkcolor;
}
}
else break;
}
}
/*for(i=1;i<=n;i++)
{
printf("%lld %lld\n",lef[i],rig[i]);
}*/
scanf("%lld",&q);
for(i=1;i<=q;i++)
{
L st,ed;
scanf("%lld %lld",&st,&ed);
puts(lef[st]<=ed&&ed<=rig[st]?"YES":"NO");
}
}
Compilation message
long_mansion.cpp: In function 'int main()':
long_mansion.cpp:123:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(j=0;j<v[i].size();j++)
~^~~~~~~~~~~~
long_mansion.cpp:132:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(j=0;j<v[lef[i]].size();j++)
~^~~~~~~~~~~~~~~~~
long_mansion.cpp:140:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(j=0;j<v[rig[i]].size();j++)
~^~~~~~~~~~~~~~~~~
long_mansion.cpp:77:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld",&n);
~~~~~^~~~~~~~~~~
long_mansion.cpp:81:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld",&cor[i]);
~~~~~^~~~~~~~~~~~~~~~
long_mansion.cpp:85:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld",&sz[i]);
~~~~~^~~~~~~~~~~~~~~
long_mansion.cpp:89:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld",&sctemp);
~~~~~^~~~~~~~~~~~~~~~
long_mansion.cpp:153:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld",&q);
~~~~~^~~~~~~~~~~
long_mansion.cpp:157:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld %lld",&st,&ed);
~~~~~^~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
12408 KB |
Output is correct |
2 |
Correct |
58 ms |
12740 KB |
Output is correct |
3 |
Correct |
130 ms |
13160 KB |
Output is correct |
4 |
Correct |
44 ms |
13160 KB |
Output is correct |
5 |
Correct |
68 ms |
13160 KB |
Output is correct |
6 |
Correct |
53 ms |
13160 KB |
Output is correct |
7 |
Correct |
40 ms |
13160 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
12408 KB |
Output is correct |
2 |
Correct |
58 ms |
12740 KB |
Output is correct |
3 |
Correct |
130 ms |
13160 KB |
Output is correct |
4 |
Correct |
44 ms |
13160 KB |
Output is correct |
5 |
Correct |
68 ms |
13160 KB |
Output is correct |
6 |
Correct |
53 ms |
13160 KB |
Output is correct |
7 |
Correct |
40 ms |
13160 KB |
Output is correct |
8 |
Correct |
195 ms |
18160 KB |
Output is correct |
9 |
Correct |
232 ms |
19628 KB |
Output is correct |
10 |
Correct |
225 ms |
20692 KB |
Output is correct |
11 |
Correct |
274 ms |
21156 KB |
Output is correct |
12 |
Correct |
193 ms |
21156 KB |
Output is correct |
13 |
Correct |
175 ms |
22340 KB |
Output is correct |
14 |
Correct |
185 ms |
22344 KB |
Output is correct |
15 |
Correct |
206 ms |
22672 KB |
Output is correct |
16 |
Correct |
186 ms |
22672 KB |
Output is correct |
17 |
Correct |
198 ms |
22672 KB |
Output is correct |
18 |
Correct |
225 ms |
22672 KB |
Output is correct |
19 |
Correct |
160 ms |
22672 KB |
Output is correct |
20 |
Correct |
213 ms |
22672 KB |
Output is correct |
21 |
Correct |
189 ms |
22672 KB |
Output is correct |
22 |
Correct |
186 ms |
22672 KB |
Output is correct |
23 |
Correct |
191 ms |
22672 KB |
Output is correct |
24 |
Correct |
217 ms |
22672 KB |
Output is correct |
25 |
Correct |
208 ms |
22672 KB |
Output is correct |
26 |
Correct |
179 ms |
22672 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3052 ms |
35388 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
12408 KB |
Output is correct |
2 |
Correct |
58 ms |
12740 KB |
Output is correct |
3 |
Correct |
130 ms |
13160 KB |
Output is correct |
4 |
Correct |
44 ms |
13160 KB |
Output is correct |
5 |
Correct |
68 ms |
13160 KB |
Output is correct |
6 |
Correct |
53 ms |
13160 KB |
Output is correct |
7 |
Correct |
40 ms |
13160 KB |
Output is correct |
8 |
Correct |
195 ms |
18160 KB |
Output is correct |
9 |
Correct |
232 ms |
19628 KB |
Output is correct |
10 |
Correct |
225 ms |
20692 KB |
Output is correct |
11 |
Correct |
274 ms |
21156 KB |
Output is correct |
12 |
Correct |
193 ms |
21156 KB |
Output is correct |
13 |
Correct |
175 ms |
22340 KB |
Output is correct |
14 |
Correct |
185 ms |
22344 KB |
Output is correct |
15 |
Correct |
206 ms |
22672 KB |
Output is correct |
16 |
Correct |
186 ms |
22672 KB |
Output is correct |
17 |
Correct |
198 ms |
22672 KB |
Output is correct |
18 |
Correct |
225 ms |
22672 KB |
Output is correct |
19 |
Correct |
160 ms |
22672 KB |
Output is correct |
20 |
Correct |
213 ms |
22672 KB |
Output is correct |
21 |
Correct |
189 ms |
22672 KB |
Output is correct |
22 |
Correct |
186 ms |
22672 KB |
Output is correct |
23 |
Correct |
191 ms |
22672 KB |
Output is correct |
24 |
Correct |
217 ms |
22672 KB |
Output is correct |
25 |
Correct |
208 ms |
22672 KB |
Output is correct |
26 |
Correct |
179 ms |
22672 KB |
Output is correct |
27 |
Execution timed out |
3052 ms |
35388 KB |
Time limit exceeded |
28 |
Halted |
0 ms |
0 KB |
- |