Submission #70683

#TimeUsernameProblemLanguageResultExecution timeMemory
70683Just_Solve_The_ProblemLong Mansion (JOI17_long_mansion)C++11
10 / 100
3005 ms89992 KiB
#include <bits/stdc++.h>

using namespace std;

const int N = (int)1e5 + 7;

int n;
int c[N];
vector < int > keys[N];
pair < int, int > lr[N];
int has[N];

main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    scanf("%d", &c[i]);
  }
  for (int i = 1; i <= n; i++) {
    int siz;
    scanf("%d", &siz);
    for (int j = 0; j < siz; j++) {
      int x;
      scanf("%d", &x);
      keys[i].push_back(x);
    }
    lr[i] = {i, i};
  }
  for (int i = 1; i <= n; i++) {
    int ok = 1;
    for (int to : keys[i]) {
      has[to] = i;
    }
    while (ok) {
      ok = 0;
      while (has[c[lr[i].second]] == i) {
        lr[i].second++;
        for (int to : keys[lr[i].second]) {
          has[to] = i;
        }
        ok = 1;
      }
      while (has[c[lr[i].first - 1]] == i) {
        lr[i].first--;
        for (int to : keys[lr[i].first]) {
          has[to] = i;
        }
        ok = 1;
      }
    }
  }
//  for (int i = 1; i <= n; i++) {
//    printf("%d %d\n", lr[i].first, lr[i].second);
//  }
  int q;
  scanf("%d", &q);
  while (q--) {
    int l, r;
    scanf("%d %d", &l, &r);
    if (lr[l].first <= r && r <= lr[l].second) {
      puts("YES");
    } else {
      puts("NO");
    }
  }
}

Compilation message (stderr)

long_mansion.cpp:13:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
long_mansion.cpp: In function 'int main()':
long_mansion.cpp:14:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &n);
   ~~~~~^~~~~~~~~~
long_mansion.cpp:16:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &c[i]);
     ~~~~~^~~~~~~~~~~~~
long_mansion.cpp:20:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &siz);
     ~~~~~^~~~~~~~~~~~
long_mansion.cpp:23:12: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
       scanf("%d", &x);
       ~~~~~^~~~~~~~~~
long_mansion.cpp:55:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &q);
   ~~~~~^~~~~~~~~~
long_mansion.cpp:58:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &l, &r);
     ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...