답안 #69454

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
69454 2018-08-21T00:22:14 Z Benq Long Mansion (JOI17_long_mansion) C++14
100 / 100
1277 ms 177720 KB
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 500005;

int N, C[MX], L[MX], R[MX];
int needL[MX], needR[MX];
vi posi[MX], Rneed[MX], Lneed[MX];
priority_queue<int> p[MX];

set<int> s;
deque<pi> d;

void tri0(int i) {
    auto it = s.lb(needL[i]); if (it == s.begin()) return;
    int j = *prev(it); if (i > j) return;
    if (i == 1) { d.pb({i,N}); return; }
    int num = j-i+1; int lef = num;
    while (lef) {
        int LEF = min(d.front().s,lef);
        d.front().s -= LEF, lef -= LEF;
        if (d.front().s == 0) d.pop_front();
    }
    d.push_front({i,num});
}

void tri1(int i) {
    auto it = s.ub(needR[i]); if (it == s.end()) return;
    int j = *it; if (j > i) return;
    if (i == N) { d.pb({i,N}); return; }
    int num = i-j+1; int lef = num;
    while (lef) {
        int LEF = min(d.front().s,lef);
        d.front().s -= LEF, lef -= LEF;
        if (d.front().s == 0) d.pop_front();
    }
    d.push_front({i,num});
}

void del() {
    d.front().s --;
    if (!d.front().s) d.pop_front();
}

void gen() {
    FOR(i,1,N+1) for (int j: posi[i]) p[j].push(-i);
    FOR(i,1,N+1) {
        needL[i] = (sz(p[C[i-1]]) ? -p[C[i-1]].top() : N+1);
        Lneed[needL[i]].pb(i);
        for (int j: posi[i]) p[j].pop();
    }
    FOR(i,1,N+1) for (int j: posi[i]) p[j].push(i);
    FORd(i,1,N+1) {
        needR[i] = (sz(p[C[i]]) ? p[C[i]].top() : 0);
        Rneed[needR[i]].pb(i);
        for (int j: posi[i]) p[j].pop();
    }
    FOR(i,1,N+1) {
        for (int j: Rneed[i-1]) s.insert(j);
        tri0(i);
        L[i] = d.front().f; 
        del();
    }
    s.clear(); assert(!sz(d));
    FORd(i,1,N+1) {
        for (int j: Lneed[i+1]) s.insert(j);
        tri1(i);
        R[i] = d.front().f; 
        del();
    }
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> N; FOR(i,1,N) cin >> C[i];
    FOR(i,1,N+1) {
        int B; cin >> B;
        F0R(j,B) {
            int A; cin >> A;
            posi[i].pb(A);
        }
    }
    gen();
    
    int Q; cin >> Q;
    F0R(i,Q) {
        int X,Y; cin >> X >> Y;
        if (L[X] <= Y && Y <= R[X]) cout << "YES";
        else cout << "NO";
        cout << "\n";
    }
}

/* Look for:
* the exact constraints (multiple sets are too slow for n=10^6 :( ) 
* special cases (n=1?)
* overflow (ll vs int?)
* array bounds
* if you have no idea just guess the appropriate well-known algo instead of doing nothing :/
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 51704 KB Output is correct
2 Correct 53 ms 52000 KB Output is correct
3 Correct 54 ms 52424 KB Output is correct
4 Correct 51 ms 52424 KB Output is correct
5 Correct 53 ms 52424 KB Output is correct
6 Correct 51 ms 52424 KB Output is correct
7 Correct 51 ms 52424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 51704 KB Output is correct
2 Correct 53 ms 52000 KB Output is correct
3 Correct 54 ms 52424 KB Output is correct
4 Correct 51 ms 52424 KB Output is correct
5 Correct 53 ms 52424 KB Output is correct
6 Correct 51 ms 52424 KB Output is correct
7 Correct 51 ms 52424 KB Output is correct
8 Correct 179 ms 54516 KB Output is correct
9 Correct 236 ms 54524 KB Output is correct
10 Correct 199 ms 54836 KB Output is correct
11 Correct 202 ms 55248 KB Output is correct
12 Correct 162 ms 55248 KB Output is correct
13 Correct 169 ms 55248 KB Output is correct
14 Correct 181 ms 55248 KB Output is correct
15 Correct 173 ms 55248 KB Output is correct
16 Correct 169 ms 55248 KB Output is correct
17 Correct 178 ms 55248 KB Output is correct
18 Correct 176 ms 55248 KB Output is correct
19 Correct 189 ms 55248 KB Output is correct
20 Correct 195 ms 55248 KB Output is correct
21 Correct 166 ms 55248 KB Output is correct
22 Correct 205 ms 55248 KB Output is correct
23 Correct 168 ms 55248 KB Output is correct
24 Correct 194 ms 55248 KB Output is correct
25 Correct 191 ms 55248 KB Output is correct
26 Correct 168 ms 55248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 464 ms 70732 KB Output is correct
2 Correct 450 ms 70732 KB Output is correct
3 Correct 423 ms 70732 KB Output is correct
4 Correct 494 ms 70732 KB Output is correct
5 Correct 458 ms 70732 KB Output is correct
6 Correct 356 ms 70780 KB Output is correct
7 Correct 361 ms 71468 KB Output is correct
8 Correct 317 ms 71500 KB Output is correct
9 Correct 365 ms 71664 KB Output is correct
10 Correct 411 ms 71884 KB Output is correct
11 Correct 399 ms 71884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 51704 KB Output is correct
2 Correct 53 ms 52000 KB Output is correct
3 Correct 54 ms 52424 KB Output is correct
4 Correct 51 ms 52424 KB Output is correct
5 Correct 53 ms 52424 KB Output is correct
6 Correct 51 ms 52424 KB Output is correct
7 Correct 51 ms 52424 KB Output is correct
8 Correct 179 ms 54516 KB Output is correct
9 Correct 236 ms 54524 KB Output is correct
10 Correct 199 ms 54836 KB Output is correct
11 Correct 202 ms 55248 KB Output is correct
12 Correct 162 ms 55248 KB Output is correct
13 Correct 169 ms 55248 KB Output is correct
14 Correct 181 ms 55248 KB Output is correct
15 Correct 173 ms 55248 KB Output is correct
16 Correct 169 ms 55248 KB Output is correct
17 Correct 178 ms 55248 KB Output is correct
18 Correct 176 ms 55248 KB Output is correct
19 Correct 189 ms 55248 KB Output is correct
20 Correct 195 ms 55248 KB Output is correct
21 Correct 166 ms 55248 KB Output is correct
22 Correct 205 ms 55248 KB Output is correct
23 Correct 168 ms 55248 KB Output is correct
24 Correct 194 ms 55248 KB Output is correct
25 Correct 191 ms 55248 KB Output is correct
26 Correct 168 ms 55248 KB Output is correct
27 Correct 464 ms 70732 KB Output is correct
28 Correct 450 ms 70732 KB Output is correct
29 Correct 423 ms 70732 KB Output is correct
30 Correct 494 ms 70732 KB Output is correct
31 Correct 458 ms 70732 KB Output is correct
32 Correct 356 ms 70780 KB Output is correct
33 Correct 361 ms 71468 KB Output is correct
34 Correct 317 ms 71500 KB Output is correct
35 Correct 365 ms 71664 KB Output is correct
36 Correct 411 ms 71884 KB Output is correct
37 Correct 399 ms 71884 KB Output is correct
38 Correct 1277 ms 116684 KB Output is correct
39 Correct 1245 ms 140972 KB Output is correct
40 Correct 934 ms 140972 KB Output is correct
41 Correct 962 ms 165196 KB Output is correct
42 Correct 384 ms 165196 KB Output is correct
43 Correct 461 ms 165196 KB Output is correct
44 Correct 726 ms 165196 KB Output is correct
45 Correct 720 ms 165196 KB Output is correct
46 Correct 658 ms 165196 KB Output is correct
47 Correct 367 ms 165196 KB Output is correct
48 Correct 365 ms 165196 KB Output is correct
49 Correct 593 ms 165196 KB Output is correct
50 Correct 639 ms 165196 KB Output is correct
51 Correct 805 ms 165196 KB Output is correct
52 Correct 636 ms 165196 KB Output is correct
53 Correct 722 ms 165196 KB Output is correct
54 Correct 884 ms 177720 KB Output is correct
55 Correct 773 ms 177720 KB Output is correct