Submission #83925

# Submission time Handle Problem Language Result Execution time Memory
83925 2018-11-11T18:12:35 Z Bodo171 Long Mansion (JOI17_long_mansion) C++14
100 / 100
1330 ms 137316 KB
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
const int nmax=500005;
struct intv
{
    int l,r;
}in[nmax];
vector<int> v[nmax];
int rmq[20][nmax];
int st[nmax],c[nmax],lst[nmax],nxt[nmax];
int n,q,i,j,p,nr,x,u,y;
bool ok;
void mrg(intv &a,intv b)
{
    if(b.l<a.l) a.l=b.l;
    if(b.r>a.r) a.r=b.r;
}
void dublaje()
{
    for(i=1;i<=18;i++)
        for(j=1;j<=n-(1<<i)+1;j++)
           rmq[i][j]=min(rmq[i-1][j],rmq[i-1][j+(1<<(i-1))]);
}
int extinde(int l,int r)
{
    int t=r+1;
    for(p=18;p>=0;p--)
        if(t+(1<<p)-1<=n&&rmq[p][t]>=l)
               t+=(1<<p);
    return (t-1);
}
int main()
{
    //freopen("data.in","r",stdin);
    ios_base::sync_with_stdio(false);
    cin>>n;
    for(i=1;i<n;i++)
        cin>>c[i];
    for(i=1;i<=n;i++)
    {
        cin>>nr;
        for(j=1;j<=nr;j++)
        {
            cin>>x;
            v[i].push_back(x);
        }
    }
    for(i=1;i<n;i++)
    {
        for(j=0;j<v[i].size();j++)
            lst[v[i][j]]=i;
        rmq[0][i+1]=lst[c[i]];
    }
    dublaje();
    for(i=1;i<=n;i++)
        lst[i]=n+1;
    for(i=n;i>=1;i--)
    {
        nxt[i]=lst[c[i]];
        for(j=0;j<v[i].size();j++)
            lst[v[i][j]]=i;

    }
    for(i=1;i<=n;i++)
    {
        in[i].l=i;in[i].r=i;
        ok=1;
        in[i].r=extinde(in[i].l,in[i].r);
        while(u>0&&ok)
        {
            ok=0;
            if(nxt[st[u]]<=in[i].r)
            {
                ok=1;
                mrg(in[i],in[st[u]]);
                u--;
            }
            in[i].r=extinde(in[i].l,in[i].r);
        }
        st[++u]=i;
    }
    cin>>q;
    for(i=1;i<=q;i++)
    {
        cin>>x>>y;
        if(y>=in[x].l&&y<=in[x].r) cout<<"YES\n";
        else cout<<"NO\n";
    }
    return 0;
}

Compilation message

long_mansion.cpp: In function 'int main()':
long_mansion.cpp:52:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(j=0;j<v[i].size();j++)
                 ~^~~~~~~~~~~~
long_mansion.cpp:62:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(j=0;j<v[i].size();j++)
                 ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 22 ms 12540 KB Output is correct
2 Correct 22 ms 12860 KB Output is correct
3 Correct 23 ms 13012 KB Output is correct
4 Correct 22 ms 13012 KB Output is correct
5 Correct 22 ms 13012 KB Output is correct
6 Correct 22 ms 13012 KB Output is correct
7 Correct 22 ms 13096 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 12540 KB Output is correct
2 Correct 22 ms 12860 KB Output is correct
3 Correct 23 ms 13012 KB Output is correct
4 Correct 22 ms 13012 KB Output is correct
5 Correct 22 ms 13012 KB Output is correct
6 Correct 22 ms 13012 KB Output is correct
7 Correct 22 ms 13096 KB Output is correct
8 Correct 904 ms 18944 KB Output is correct
9 Correct 876 ms 23348 KB Output is correct
10 Correct 875 ms 28016 KB Output is correct
11 Correct 880 ms 33140 KB Output is correct
12 Correct 855 ms 33348 KB Output is correct
13 Correct 889 ms 33516 KB Output is correct
14 Correct 890 ms 33560 KB Output is correct
15 Correct 878 ms 33640 KB Output is correct
16 Correct 902 ms 33836 KB Output is correct
17 Correct 916 ms 33836 KB Output is correct
18 Correct 876 ms 33836 KB Output is correct
19 Correct 889 ms 33836 KB Output is correct
20 Correct 881 ms 33836 KB Output is correct
21 Correct 894 ms 33836 KB Output is correct
22 Correct 927 ms 33836 KB Output is correct
23 Correct 893 ms 33836 KB Output is correct
24 Correct 895 ms 33836 KB Output is correct
25 Correct 861 ms 33836 KB Output is correct
26 Correct 871 ms 33836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1022 ms 52672 KB Output is correct
2 Correct 1010 ms 59592 KB Output is correct
3 Correct 1018 ms 66652 KB Output is correct
4 Correct 1016 ms 73812 KB Output is correct
5 Correct 1057 ms 75048 KB Output is correct
6 Correct 959 ms 75048 KB Output is correct
7 Correct 995 ms 75048 KB Output is correct
8 Correct 969 ms 75048 KB Output is correct
9 Correct 980 ms 75048 KB Output is correct
10 Correct 1002 ms 75048 KB Output is correct
11 Correct 948 ms 75048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 12540 KB Output is correct
2 Correct 22 ms 12860 KB Output is correct
3 Correct 23 ms 13012 KB Output is correct
4 Correct 22 ms 13012 KB Output is correct
5 Correct 22 ms 13012 KB Output is correct
6 Correct 22 ms 13012 KB Output is correct
7 Correct 22 ms 13096 KB Output is correct
8 Correct 904 ms 18944 KB Output is correct
9 Correct 876 ms 23348 KB Output is correct
10 Correct 875 ms 28016 KB Output is correct
11 Correct 880 ms 33140 KB Output is correct
12 Correct 855 ms 33348 KB Output is correct
13 Correct 889 ms 33516 KB Output is correct
14 Correct 890 ms 33560 KB Output is correct
15 Correct 878 ms 33640 KB Output is correct
16 Correct 902 ms 33836 KB Output is correct
17 Correct 916 ms 33836 KB Output is correct
18 Correct 876 ms 33836 KB Output is correct
19 Correct 889 ms 33836 KB Output is correct
20 Correct 881 ms 33836 KB Output is correct
21 Correct 894 ms 33836 KB Output is correct
22 Correct 927 ms 33836 KB Output is correct
23 Correct 893 ms 33836 KB Output is correct
24 Correct 895 ms 33836 KB Output is correct
25 Correct 861 ms 33836 KB Output is correct
26 Correct 871 ms 33836 KB Output is correct
27 Correct 1022 ms 52672 KB Output is correct
28 Correct 1010 ms 59592 KB Output is correct
29 Correct 1018 ms 66652 KB Output is correct
30 Correct 1016 ms 73812 KB Output is correct
31 Correct 1057 ms 75048 KB Output is correct
32 Correct 959 ms 75048 KB Output is correct
33 Correct 995 ms 75048 KB Output is correct
34 Correct 969 ms 75048 KB Output is correct
35 Correct 980 ms 75048 KB Output is correct
36 Correct 1002 ms 75048 KB Output is correct
37 Correct 948 ms 75048 KB Output is correct
38 Correct 1330 ms 112452 KB Output is correct
39 Correct 1283 ms 125424 KB Output is correct
40 Correct 1194 ms 125424 KB Output is correct
41 Correct 1289 ms 125424 KB Output is correct
42 Correct 1006 ms 125424 KB Output is correct
43 Correct 980 ms 125424 KB Output is correct
44 Correct 1092 ms 125424 KB Output is correct
45 Correct 1133 ms 125424 KB Output is correct
46 Correct 1112 ms 125424 KB Output is correct
47 Correct 1036 ms 125424 KB Output is correct
48 Correct 970 ms 125424 KB Output is correct
49 Correct 1185 ms 125424 KB Output is correct
50 Correct 1098 ms 125424 KB Output is correct
51 Correct 1098 ms 125424 KB Output is correct
52 Correct 1087 ms 125424 KB Output is correct
53 Correct 1153 ms 125424 KB Output is correct
54 Correct 1215 ms 137316 KB Output is correct
55 Correct 1170 ms 137316 KB Output is correct