Submission #409442

# Submission time Handle Problem Language Result Execution time Memory
409442 2021-05-20T18:27:02 Z duality Long Mansion (JOI17_long_mansion) C++11
5 / 100
310 ms 33092 KB
#define DEBUG 0

#include <bits/stdc++.h>
using namespace std;

#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}

// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
    public:
        template<typename T>
        _Debug& operator,(T val) {
            cout << val << endl;
            return *this;
        }
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif

// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back

// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;

// ---------- END OF TEMPLATE ----------

int C[500000];
vi A[500000];
int pos[500000];
vi pos2[500000];
set<int> S;
int l[1 << 20],r[1 << 20];
int build(int s,int e,int i) {
    if (s == e) {
        l[i] = 0,r[i] = 1e9;
        return 0;
    }

    int mid = (s+e) / 2;
    build(s,mid,2*i+1),build(mid+1,e,2*i+2);
    l[i] = 0,r[i] = 1e9;
    return 0;
}
int update(int s,int e,int as,int ae,int i,int ll,int rr) {
    if ((s > ae) || (e < as)) return 0;
    else if ((s >= as) && (e <= ae)) {
        l[i] = max(l[i],ll),r[i] = min(r[i],rr);
        return 0;
    }

    int mid = (s+e) / 2;
    update(s,mid,as,ae,2*i+1,ll,rr),update(mid+1,e,as,ae,2*i+2,ll,rr);
    return 0;
}
int L[500000],R[500000];
int queryAll(int s,int e,int i) {
    if (s == e) {
        L[s] = l[i],R[s] = r[i];
        return 0;
    }

    int mid = (s+e) / 2;
    l[2*i+1] = max(l[2*i+1],l[i]);
    l[2*i+2] = max(l[2*i+2],l[i]);
    r[2*i+1] = min(r[2*i+1],r[i]);
    r[2*i+2] = min(r[2*i+2],r[i]);
    queryAll(s,mid,2*i+1),queryAll(mid+1,e,2*i+2);
    return 0;
}
int main() {
    int i,j;
    int N,Q,B;
    scanf("%d",&N);
    for (i = 0; i < N-1; i++) scanf("%d",&C[i]),C[i]--;
    for (i = 0; i < N; i++) {
        scanf("%d",&B);
        A[i].resize(B);
        for (j = 0; j < B; j++) scanf("%d",&A[i][j]),A[i][j]--;
    }

    build(0,N-1,0);
    for (i = 0; i < N; i++) pos[i] = N+1;
    for (i = N-1; i >= 0; i--) {
        S.insert(i);
        if (i < N-1) pos2[C[i]].pb(i);
        for (j = 0; j < A[i].size(); j++) {
            pos[A[i][j]] = i;
            while (!pos2[A[i][j]].empty()) {
                S.erase(pos2[A[i][j]].back());
                pos2[A[i][j]].pop_back();
            }
        }
        int b = (i == 0) ? N:pos[C[i-1]]-1;
        auto it = S.upper_bound(b);
        if (it != S.begin()) {
            it--;
            b = *it;
            if (i <= b) update(0,N-1,i,b,0,i,b);
        }
    }
    for (i = 0; i < N; i++) pos[i] = -1,pos2[i].clear();
    S.clear();
    for (i = 0; i < N; i++) {
        S.insert(i);
        if (i > 0) pos2[C[i-1]].pb(i);
        for (j = 0; j < A[i].size(); j++) {
            pos[A[i][j]] = i;
            while (!pos2[A[i][j]].empty()) {
                S.erase(pos2[A[i][j]].back());
                pos2[A[i][j]].pop_back();
            }
        }
        int b = (i == 0) ? 0:pos[C[i]]+1;
        auto it = S.lower_bound(b);
        if (it != S.end()) {
            b = *it;
            if (b <= i) update(0,N-1,b,i,0,b,i);
        }
    }
    queryAll(0,N-1,0);

    int X,Y;
    scanf("%d",&Q);
    for (i = 0; i < Q; i++) {
        scanf("%d %d",&X,&Y);
        X--,Y--;
        if ((Y >= L[X]) && (Y <= R[X])) printf("YES\n");
        else printf("NO\n");
    }

    return 0;
}

Compilation message

long_mansion.cpp: In function 'int main()':
long_mansion.cpp:117:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  117 |         for (j = 0; j < A[i].size(); j++) {
      |                     ~~^~~~~~~~~~~~~
long_mansion.cpp:137:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  137 |         for (j = 0; j < A[i].size(); j++) {
      |                     ~~^~~~~~~~~~~~~
long_mansion.cpp:104:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  104 |     scanf("%d",&N);
      |     ~~~~~^~~~~~~~~
long_mansion.cpp:105:36: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  105 |     for (i = 0; i < N-1; i++) scanf("%d",&C[i]),C[i]--;
      |                               ~~~~~^~~~~~~~~~~~
long_mansion.cpp:107:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  107 |         scanf("%d",&B);
      |         ~~~~~^~~~~~~~~
long_mansion.cpp:109:38: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  109 |         for (j = 0; j < B; j++) scanf("%d",&A[i][j]),A[i][j]--;
      |                                 ~~~~~^~~~~~~~~~~~~~~
long_mansion.cpp:154:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  154 |     scanf("%d",&Q);
      |     ~~~~~^~~~~~~~~
long_mansion.cpp:156:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  156 |         scanf("%d %d",&X,&Y);
      |         ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 19 ms 24012 KB Output is correct
2 Correct 20 ms 24076 KB Output is correct
3 Correct 20 ms 24288 KB Output is correct
4 Correct 19 ms 24044 KB Output is correct
5 Correct 18 ms 23948 KB Output is correct
6 Correct 18 ms 24080 KB Output is correct
7 Correct 19 ms 24076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 24012 KB Output is correct
2 Correct 20 ms 24076 KB Output is correct
3 Correct 20 ms 24288 KB Output is correct
4 Correct 19 ms 24044 KB Output is correct
5 Correct 18 ms 23948 KB Output is correct
6 Correct 18 ms 24080 KB Output is correct
7 Correct 19 ms 24076 KB Output is correct
8 Correct 146 ms 26188 KB Output is correct
9 Correct 151 ms 26100 KB Output is correct
10 Correct 149 ms 26368 KB Output is correct
11 Correct 157 ms 26728 KB Output is correct
12 Correct 142 ms 26384 KB Output is correct
13 Incorrect 146 ms 26480 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 305 ms 33092 KB Output is correct
2 Correct 310 ms 32852 KB Output is correct
3 Correct 283 ms 32928 KB Output is correct
4 Correct 303 ms 32852 KB Output is correct
5 Correct 303 ms 32912 KB Output is correct
6 Incorrect 228 ms 32812 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 19 ms 24012 KB Output is correct
2 Correct 20 ms 24076 KB Output is correct
3 Correct 20 ms 24288 KB Output is correct
4 Correct 19 ms 24044 KB Output is correct
5 Correct 18 ms 23948 KB Output is correct
6 Correct 18 ms 24080 KB Output is correct
7 Correct 19 ms 24076 KB Output is correct
8 Correct 146 ms 26188 KB Output is correct
9 Correct 151 ms 26100 KB Output is correct
10 Correct 149 ms 26368 KB Output is correct
11 Correct 157 ms 26728 KB Output is correct
12 Correct 142 ms 26384 KB Output is correct
13 Incorrect 146 ms 26480 KB Output isn't correct
14 Halted 0 ms 0 KB -