Submission #69923

# Submission time Handle Problem Language Result Execution time Memory
69923 2018-08-22T03:09:25 Z MatheusLealV Long Mansion (JOI17_long_mansion) C++17
10 / 100
3000 ms 34856 KB
#include <bits/stdc++.h>
#define N 500050
using namespace std;

int n, q, c[N], L[N], R[N];

int e[N];

vector<int> pos[N], T[N];

void solve(int l, int r, int i)
{
    while(true)
    {
        L[i] = l;

        R[i] = r;

        bool ok = false;

        if(r < n)
        {
            int q = upper_bound(pos[c[r]].begin(), pos[c[r]].end(), r) - lower_bound(pos[c[r]].begin(), pos[c[r]].end(), l);
            
            if(q) r = max(r + 1, R[r]), ok = 1;//solve(l, max(r + 1, R[r]), i), ok = 1;
        }

        if(l > 1 and !ok)
        {
            int q = upper_bound(pos[c[l - 1]].begin(), pos[c[l - 1]].end(), r) - lower_bound(pos[c[l - 1]].begin(), pos[c[l - 1]].end(), l);

            if(q) l = min(l - 1, L[l]), ok = 1;;//solve(min(l - 1, L[l]), r, i);        
        }

        if(!ok) break;
    }
}

int main()
{
    ios::sync_with_stdio(false); cin.tie(0);

    cin>>n;

    for(int i = 1; i < n; i++) cin>>c[i];

    for(int i = 1; i <= n; i++)
    {
        L[i] = R[i] = i;

        int a, b;

        cin>>a;

        for(int x = 1; x <= a; x++)
        {
            cin>>b;

            pos[b].push_back(i);

            T[i].push_back(b);
        }
    }

    for(int i = n; i >= 1; i--)
    {
    	e[i] = i;

    	for(auto x: T[i])
    	{
    		if(x == c[i])
    		{
    			e[i] = e[i + 1];

    			while(e[i] <= n)
    			{
           			 int q = upper_bound(pos[c[e[i]]].begin(), pos[c[e[i]]].end(), e[i]) - lower_bound(pos[c[e[i]]].begin(), pos[c[e[i]]].end(), i);

           			 if(q) e[i] ++;

           			 else break;
    			}

    			break;
    		}
    	}
 
    }

    for(int i = 1; i <= n; i++)
    {
        if(L[i - 1] <= i and i <= R[i - 1])
        {
            int q = upper_bound(pos[c[i - 1]].begin(), pos[c[i - 1]].end(), e[i]) - lower_bound(pos[c[i - 1]].begin(), pos[c[i - 1]].end(), i);

            if(q) L[i] = L[i - 1], R[i] = max(R[i - 1], e[i]);

            else L[i] = i, R[i] = e[i];
        }

       else solve(i, i, i);
    }

    cin>>q;

    for(int i = 1; i <= q; i++)
    {
        int x, y;

        cin>>x>>y;

        if(L[x] <= y and y <= R[x]) cout<<"YES\n";

        else cout<<"NO\n";
    }
}
# Verdict Execution time Memory Grader output
1 Correct 26 ms 23928 KB Output is correct
2 Correct 125 ms 24240 KB Output is correct
3 Correct 418 ms 24260 KB Output is correct
4 Correct 26 ms 24368 KB Output is correct
5 Correct 26 ms 24404 KB Output is correct
6 Correct 26 ms 24464 KB Output is correct
7 Correct 26 ms 24688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 23928 KB Output is correct
2 Correct 125 ms 24240 KB Output is correct
3 Correct 418 ms 24260 KB Output is correct
4 Correct 26 ms 24368 KB Output is correct
5 Correct 26 ms 24404 KB Output is correct
6 Correct 26 ms 24464 KB Output is correct
7 Correct 26 ms 24688 KB Output is correct
8 Correct 163 ms 28820 KB Output is correct
9 Correct 142 ms 28912 KB Output is correct
10 Correct 249 ms 28988 KB Output is correct
11 Correct 559 ms 29272 KB Output is correct
12 Correct 139 ms 29272 KB Output is correct
13 Correct 151 ms 29272 KB Output is correct
14 Correct 131 ms 29272 KB Output is correct
15 Correct 172 ms 29272 KB Output is correct
16 Correct 151 ms 29272 KB Output is correct
17 Correct 150 ms 29272 KB Output is correct
18 Correct 158 ms 29272 KB Output is correct
19 Correct 153 ms 29272 KB Output is correct
20 Correct 149 ms 29272 KB Output is correct
21 Correct 171 ms 29368 KB Output is correct
22 Correct 154 ms 29368 KB Output is correct
23 Correct 157 ms 29368 KB Output is correct
24 Correct 147 ms 29368 KB Output is correct
25 Correct 138 ms 29368 KB Output is correct
26 Correct 160 ms 29368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3015 ms 34856 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 26 ms 23928 KB Output is correct
2 Correct 125 ms 24240 KB Output is correct
3 Correct 418 ms 24260 KB Output is correct
4 Correct 26 ms 24368 KB Output is correct
5 Correct 26 ms 24404 KB Output is correct
6 Correct 26 ms 24464 KB Output is correct
7 Correct 26 ms 24688 KB Output is correct
8 Correct 163 ms 28820 KB Output is correct
9 Correct 142 ms 28912 KB Output is correct
10 Correct 249 ms 28988 KB Output is correct
11 Correct 559 ms 29272 KB Output is correct
12 Correct 139 ms 29272 KB Output is correct
13 Correct 151 ms 29272 KB Output is correct
14 Correct 131 ms 29272 KB Output is correct
15 Correct 172 ms 29272 KB Output is correct
16 Correct 151 ms 29272 KB Output is correct
17 Correct 150 ms 29272 KB Output is correct
18 Correct 158 ms 29272 KB Output is correct
19 Correct 153 ms 29272 KB Output is correct
20 Correct 149 ms 29272 KB Output is correct
21 Correct 171 ms 29368 KB Output is correct
22 Correct 154 ms 29368 KB Output is correct
23 Correct 157 ms 29368 KB Output is correct
24 Correct 147 ms 29368 KB Output is correct
25 Correct 138 ms 29368 KB Output is correct
26 Correct 160 ms 29368 KB Output is correct
27 Execution timed out 3015 ms 34856 KB Time limit exceeded
28 Halted 0 ms 0 KB -