Submission #409441

# Submission time Handle Problem Language Result Execution time Memory
409441 2021-05-20T18:24:30 Z duality Long Mansion (JOI17_long_mansion) C++11
25 / 100
3000 ms 53552 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);
        while (it != S.begin()) {
            it--;
            b = *it;
            if (i <= b) update(0,N-1,i,b,0,i,b);
            else break;
        }
    }
    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: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:136:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  136 |     scanf("%d",&Q);
      |     ~~~~~^~~~~~~~~
long_mansion.cpp:138:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  138 |         scanf("%d %d",&X,&Y);
      |         ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 17 ms 23884 KB Output is correct
2 Correct 16 ms 24076 KB Output is correct
3 Correct 17 ms 24288 KB Output is correct
4 Correct 17 ms 24068 KB Output is correct
5 Correct 15 ms 23964 KB Output is correct
6 Correct 16 ms 24080 KB Output is correct
7 Correct 155 ms 24160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 23884 KB Output is correct
2 Correct 16 ms 24076 KB Output is correct
3 Correct 17 ms 24288 KB Output is correct
4 Correct 17 ms 24068 KB Output is correct
5 Correct 15 ms 23964 KB Output is correct
6 Correct 16 ms 24080 KB Output is correct
7 Correct 155 ms 24160 KB Output is correct
8 Correct 147 ms 29856 KB Output is correct
9 Correct 150 ms 29812 KB Output is correct
10 Correct 148 ms 30352 KB Output is correct
11 Correct 148 ms 30688 KB Output is correct
12 Correct 141 ms 29512 KB Output is correct
13 Correct 144 ms 30020 KB Output is correct
14 Correct 159 ms 30072 KB Output is correct
15 Correct 146 ms 30012 KB Output is correct
16 Correct 138 ms 29764 KB Output is correct
17 Correct 144 ms 29956 KB Output is correct
18 Correct 144 ms 30036 KB Output is correct
19 Correct 146 ms 30084 KB Output is correct
20 Correct 166 ms 30020 KB Output is correct
21 Correct 138 ms 29832 KB Output is correct
22 Correct 142 ms 29952 KB Output is correct
23 Correct 287 ms 29988 KB Output is correct
24 Correct 284 ms 29896 KB Output is correct
25 Correct 295 ms 29892 KB Output is correct
26 Correct 322 ms 29824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 294 ms 32416 KB Output is correct
2 Correct 277 ms 39504 KB Output is correct
3 Correct 259 ms 39220 KB Output is correct
4 Correct 287 ms 39556 KB Output is correct
5 Correct 286 ms 39536 KB Output is correct
6 Correct 214 ms 38888 KB Output is correct
7 Correct 204 ms 38596 KB Output is correct
8 Correct 202 ms 38492 KB Output is correct
9 Correct 207 ms 38684 KB Output is correct
10 Correct 201 ms 38600 KB Output is correct
11 Correct 199 ms 38488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 23884 KB Output is correct
2 Correct 16 ms 24076 KB Output is correct
3 Correct 17 ms 24288 KB Output is correct
4 Correct 17 ms 24068 KB Output is correct
5 Correct 15 ms 23964 KB Output is correct
6 Correct 16 ms 24080 KB Output is correct
7 Correct 155 ms 24160 KB Output is correct
8 Correct 147 ms 29856 KB Output is correct
9 Correct 150 ms 29812 KB Output is correct
10 Correct 148 ms 30352 KB Output is correct
11 Correct 148 ms 30688 KB Output is correct
12 Correct 141 ms 29512 KB Output is correct
13 Correct 144 ms 30020 KB Output is correct
14 Correct 159 ms 30072 KB Output is correct
15 Correct 146 ms 30012 KB Output is correct
16 Correct 138 ms 29764 KB Output is correct
17 Correct 144 ms 29956 KB Output is correct
18 Correct 144 ms 30036 KB Output is correct
19 Correct 146 ms 30084 KB Output is correct
20 Correct 166 ms 30020 KB Output is correct
21 Correct 138 ms 29832 KB Output is correct
22 Correct 142 ms 29952 KB Output is correct
23 Correct 287 ms 29988 KB Output is correct
24 Correct 284 ms 29896 KB Output is correct
25 Correct 295 ms 29892 KB Output is correct
26 Correct 322 ms 29824 KB Output is correct
27 Correct 294 ms 32416 KB Output is correct
28 Correct 277 ms 39504 KB Output is correct
29 Correct 259 ms 39220 KB Output is correct
30 Correct 287 ms 39556 KB Output is correct
31 Correct 286 ms 39536 KB Output is correct
32 Correct 214 ms 38888 KB Output is correct
33 Correct 204 ms 38596 KB Output is correct
34 Correct 202 ms 38492 KB Output is correct
35 Correct 207 ms 38684 KB Output is correct
36 Correct 201 ms 38600 KB Output is correct
37 Correct 199 ms 38488 KB Output is correct
38 Execution timed out 3076 ms 53552 KB Time limit exceeded
39 Halted 0 ms 0 KB -