답안 #1091805

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1091805 2024-09-22T07:48:47 Z akim9905 Matryoshka (JOI16_matryoshka) C++17
51 / 100
2000 ms 11696 KB
#include <bits/stdc++.h>
using namespace std;

#define fileio() freopen("input.txt","r",stdin); freopen("output.txt","w",stdout)
#define fio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(x) (x).begin(), (x).end()
#define allr(x) x.rbegin(), x.rend()
#define cmprs(x) sort(all(x)),x.erase(unique(all(x)),x.end())
#define endl "\n"
#define sp " "
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define F first
#define S second
#define rz resize
#define sz(a) (int)(a.size())
#define clr(a) a.clear()

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef tuple<int, int, int> tpi;
typedef tuple<ll, ll, ll> tpl;
typedef pair<double, ll> pdl;
typedef pair<double, int> pdi;

const int dx[] = {1,-1,0,0,1,1,-1,-1};
const int dy[] = {0,0,1,-1,1,-1,1,-1};
const ll MOD = 1e9+7;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const int MAX = 202020; // PLZ CHK!

struct segtr{
    //0-indexed!
    vector<ll> tr, a;
    int n;
    void rst(int sz) {
        n=sz;
        tr.resize((n+1)<<1);
    }
    void upd(int i, ll v) {
        tr[i+n] = max(tr[i+n], v); i+=n; //AWARE OF UPD POLICY!!
        for (i>>=1; i; i>>=1) tr[i] = max(tr[i<<1], tr[i<<1|1]);
    }

    ll qry(int l, int r) {
        ll ret = -LINF;
        for (l+=n, r+=n; l<=r; l>>=1, r>>=1) {
            if (l&1) ret = max(ret, tr[l++]);
            if (~r&1) ret = max(ret, tr[r--]);
        }
        return ret;
    }
};

int N,Q;
pii A[MAX],C[MAX];

int main() {
    fio();
    cin>>N>>Q;
    for (int i=1; i<=N; i++) {
        int x,y; cin>>x>>y;
        A[i]={x,y};
    }    

    while (Q--) {
        int x,y;
        cin>>x>>y;
        vector<pii> B; B.pb({0,0});
        vector<int> Y; Y.pb(0);
        for (int i=1; i<=N; i++) {
            if (x<=A[i].F && A[i].S<=y) {
                B.pb(A[i]);
                Y.pb(A[i].S);
            }
        }
        sort(all(B),[](pii a, pii b){
            if (a.F==b.F) return a.S>b.S;
            return a.F<b.F;
        });
        cmprs(Y);

        int M=sz(B)-1;
        for (int i=1; i<=M; i++) {
            B[i].S=lb(all(Y),B[i].S)-Y.begin()+1;
        }

        segtr seg; seg.rst(M+10);
        vector<int> dp(M+10);
        
        for (int i=M; i>=1; i--) {
            dp[i]=seg.qry(0,B[i].S)+1;
            seg.upd(B[i].S,dp[i]);
        }

        cout<<*max_element(all(dp))<<endl;
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 48 ms 348 KB Output is correct
23 Correct 206 ms 604 KB Output is correct
24 Correct 134 ms 604 KB Output is correct
25 Correct 282 ms 604 KB Output is correct
26 Correct 151 ms 628 KB Output is correct
27 Correct 122 ms 616 KB Output is correct
28 Correct 294 ms 600 KB Output is correct
29 Correct 241 ms 628 KB Output is correct
30 Correct 136 ms 600 KB Output is correct
31 Correct 199 ms 652 KB Output is correct
32 Correct 205 ms 560 KB Output is correct
33 Correct 197 ms 600 KB Output is correct
34 Correct 194 ms 604 KB Output is correct
35 Correct 202 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 48 ms 348 KB Output is correct
23 Correct 206 ms 604 KB Output is correct
24 Correct 134 ms 604 KB Output is correct
25 Correct 282 ms 604 KB Output is correct
26 Correct 151 ms 628 KB Output is correct
27 Correct 122 ms 616 KB Output is correct
28 Correct 294 ms 600 KB Output is correct
29 Correct 241 ms 628 KB Output is correct
30 Correct 136 ms 600 KB Output is correct
31 Correct 199 ms 652 KB Output is correct
32 Correct 205 ms 560 KB Output is correct
33 Correct 197 ms 600 KB Output is correct
34 Correct 194 ms 604 KB Output is correct
35 Correct 202 ms 604 KB Output is correct
36 Execution timed out 2068 ms 11696 KB Time limit exceeded
37 Halted 0 ms 0 KB -