답안 #260696

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
260696 2020-08-10T18:19:32 Z fadi57 Long Mansion (JOI17_long_mansion) C++14
10 / 100
3000 ms 27508 KB
#include <bits/stdc++.h>
 
using namespace std;
 
#define ll long long

const int mx=500020;
int c[mx];
ll b[mx];

vector<ll>keys[mx];
ll mxright[mx];
ll mxleft[mx];
ll n,m;
int leftt[mx];int rightt[mx];
int last[mx];
int canr(int i){
    if(leftt[mxright[i]]>=mxleft[i]&&leftt[mxright[i]]!=-1&&mxright[i]<n){
       return 1;
    }return 0;
}int canl(int i){
    if(rightt[mxleft[i]-1]<=mxright[i]&&rightt[mxleft[i]-1]!=-1&&mxleft[i]>1){
       return 1;
    }return 0;
}
int main()
{
  
  cin>>n;
  for(ll i=1;i<n;i++){
      cin>>c[i];
  }
  
  for(ll i=1;i<=n;i++){
      cin>>b[i];
      for(ll j=0;j<b[i];j++){
          ll x;
          cin>>x;
          keys[i].push_back(x);
      }
  }
  
    memset(last ,-1 ,sizeof last);
    
    for(int i=1;i<n;i++){
        for(int j:keys[i]){
            last[j]=i;
        }
        leftt[i]=last[c[i]];
    } 
    memset(last ,-1 ,sizeof last);
    
      for(int i=n-1;i>=1;i--){
        for(int j:keys[i+1]){
            last[j]=i+1;
        }
       rightt[i]=last[c[i]];
    }
    for(ll i=1;i<=n;i++){
        
       ll myr=i;
        ll myl=i; mxleft[i]=i;  mxright[i]=i;
        while(1){
          ll xx=0;ll xo=0;
       
          if(canr(i)){
              xx=1;
              
              myr++;
            mxright[i]=myr;
             
          }
          if(canl(i)){
              xo=1;
             
             
              myl--;  mxleft[i]=myl;
               mxleft[i]=min(mxleft[i],mxleft[mxleft[i]]);
               mxright[i]=max(mxright[i],mxright[mxleft[i]]);
        
          }
            if(xo||xx){
                
            }else{
                break;
               
            }
        } 
     
  }
  ll q;cin>>q;
  for(ll i=0;i<q;i++){
      ll x,y;cin>>x>>y;
     //cout<<mxleft[x]<<" "<<mxright[x];
      if(mxleft[x]<=y&&y<=mxright[x]){
         cout<<"YES";
      }else{cout<<"NO";}
      cout<<'\n';
  }

}
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 14336 KB Output is correct
2 Correct 29 ms 14336 KB Output is correct
3 Correct 41 ms 14464 KB Output is correct
4 Correct 27 ms 14328 KB Output is correct
5 Correct 27 ms 14336 KB Output is correct
6 Correct 27 ms 14336 KB Output is correct
7 Correct 27 ms 14336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 14336 KB Output is correct
2 Correct 29 ms 14336 KB Output is correct
3 Correct 41 ms 14464 KB Output is correct
4 Correct 27 ms 14328 KB Output is correct
5 Correct 27 ms 14336 KB Output is correct
6 Correct 27 ms 14336 KB Output is correct
7 Correct 27 ms 14336 KB Output is correct
8 Correct 1492 ms 16760 KB Output is correct
9 Correct 1488 ms 16504 KB Output is correct
10 Correct 1600 ms 16720 KB Output is correct
11 Correct 1549 ms 16888 KB Output is correct
12 Correct 1463 ms 16632 KB Output is correct
13 Correct 1503 ms 16760 KB Output is correct
14 Correct 1488 ms 16832 KB Output is correct
15 Correct 1487 ms 16836 KB Output is correct
16 Correct 1469 ms 17144 KB Output is correct
17 Correct 1522 ms 16872 KB Output is correct
18 Correct 1559 ms 16904 KB Output is correct
19 Correct 1509 ms 16816 KB Output is correct
20 Correct 1470 ms 17088 KB Output is correct
21 Correct 1467 ms 17104 KB Output is correct
22 Correct 1493 ms 16796 KB Output is correct
23 Correct 1495 ms 16620 KB Output is correct
24 Correct 1481 ms 16724 KB Output is correct
25 Correct 1480 ms 16796 KB Output is correct
26 Correct 1506 ms 16764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2613 ms 26340 KB Output is correct
2 Execution timed out 3061 ms 27508 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 14336 KB Output is correct
2 Correct 29 ms 14336 KB Output is correct
3 Correct 41 ms 14464 KB Output is correct
4 Correct 27 ms 14328 KB Output is correct
5 Correct 27 ms 14336 KB Output is correct
6 Correct 27 ms 14336 KB Output is correct
7 Correct 27 ms 14336 KB Output is correct
8 Correct 1492 ms 16760 KB Output is correct
9 Correct 1488 ms 16504 KB Output is correct
10 Correct 1600 ms 16720 KB Output is correct
11 Correct 1549 ms 16888 KB Output is correct
12 Correct 1463 ms 16632 KB Output is correct
13 Correct 1503 ms 16760 KB Output is correct
14 Correct 1488 ms 16832 KB Output is correct
15 Correct 1487 ms 16836 KB Output is correct
16 Correct 1469 ms 17144 KB Output is correct
17 Correct 1522 ms 16872 KB Output is correct
18 Correct 1559 ms 16904 KB Output is correct
19 Correct 1509 ms 16816 KB Output is correct
20 Correct 1470 ms 17088 KB Output is correct
21 Correct 1467 ms 17104 KB Output is correct
22 Correct 1493 ms 16796 KB Output is correct
23 Correct 1495 ms 16620 KB Output is correct
24 Correct 1481 ms 16724 KB Output is correct
25 Correct 1480 ms 16796 KB Output is correct
26 Correct 1506 ms 16764 KB Output is correct
27 Correct 2613 ms 26340 KB Output is correct
28 Execution timed out 3061 ms 27508 KB Time limit exceeded
29 Halted 0 ms 0 KB -