Submission #1091809

# Submission time Handle Problem Language Result Execution time Memory
1091809 2024-09-22T08:08:47 Z akim9905 None (JOI16_matryoshka) C++17
51 / 100
235 ms 23624 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;
    }
};

typedef array<int,3> arr;

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

int ans[MAX];

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

    sort(A+1,A+N+1,[](pii a, pii b){
        if (a.F==b.F) return a.S>b.S;
        return a.F<b.F;
    });
    sort(C+1,C+Q+1,[](auto a, auto b){
        if (a[0]==b[0]) return a[1]>b[1];
        return a[0]<b[0];
    });
    cmprs(Y);

    for (int i=1; i<=N; i++) A[i].S=lb(all(Y),A[i].S)-Y.begin()+1;
    for (int i=1; i<=Q; i++) C[i][1]=lb(all(Y),C[i][1])-Y.begin()+1;

    segtr seg; seg.rst(MAX);
    for (int i=N; i>=1; i--) {
        D[i]=seg.qry(0,A[i].S)+1;
        seg.upd(A[i].S,D[i]);
    }

    segtr segq; segq.rst(MAX);
    for (int i=Q,j=N; i>=1; i--) {
        auto [a,b,idx]=C[i];
        while (j>=1 && a<=A[j].F) segq.upd(A[j].S,D[j]), j--;
        ans[idx]=segq.qry(0,b);
    }    

    for (int i=1; i<=Q; i++) cout<<ans[i]<<endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6744 KB Output is correct
2 Correct 3 ms 6748 KB Output is correct
3 Correct 3 ms 6608 KB Output is correct
4 Correct 3 ms 6748 KB Output is correct
5 Correct 3 ms 6748 KB Output is correct
6 Correct 3 ms 6748 KB Output is correct
7 Correct 3 ms 6748 KB Output is correct
8 Correct 3 ms 6748 KB Output is correct
9 Correct 2 ms 6616 KB Output is correct
10 Correct 3 ms 6748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6744 KB Output is correct
2 Correct 3 ms 6748 KB Output is correct
3 Correct 3 ms 6608 KB Output is correct
4 Correct 3 ms 6748 KB Output is correct
5 Correct 3 ms 6748 KB Output is correct
6 Correct 3 ms 6748 KB Output is correct
7 Correct 3 ms 6748 KB Output is correct
8 Correct 3 ms 6748 KB Output is correct
9 Correct 2 ms 6616 KB Output is correct
10 Correct 3 ms 6748 KB Output is correct
11 Correct 3 ms 6748 KB Output is correct
12 Correct 3 ms 6748 KB Output is correct
13 Correct 2 ms 6748 KB Output is correct
14 Correct 3 ms 6744 KB Output is correct
15 Correct 3 ms 6748 KB Output is correct
16 Correct 3 ms 6744 KB Output is correct
17 Correct 4 ms 6752 KB Output is correct
18 Correct 5 ms 6748 KB Output is correct
19 Correct 3 ms 6744 KB Output is correct
20 Correct 3 ms 6748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6744 KB Output is correct
2 Correct 3 ms 6748 KB Output is correct
3 Correct 3 ms 6608 KB Output is correct
4 Correct 3 ms 6748 KB Output is correct
5 Correct 3 ms 6748 KB Output is correct
6 Correct 3 ms 6748 KB Output is correct
7 Correct 3 ms 6748 KB Output is correct
8 Correct 3 ms 6748 KB Output is correct
9 Correct 2 ms 6616 KB Output is correct
10 Correct 3 ms 6748 KB Output is correct
11 Correct 3 ms 6748 KB Output is correct
12 Correct 3 ms 6748 KB Output is correct
13 Correct 2 ms 6748 KB Output is correct
14 Correct 3 ms 6744 KB Output is correct
15 Correct 3 ms 6748 KB Output is correct
16 Correct 3 ms 6744 KB Output is correct
17 Correct 4 ms 6752 KB Output is correct
18 Correct 5 ms 6748 KB Output is correct
19 Correct 3 ms 6744 KB Output is correct
20 Correct 3 ms 6748 KB Output is correct
21 Correct 3 ms 6748 KB Output is correct
22 Correct 4 ms 6720 KB Output is correct
23 Correct 5 ms 6968 KB Output is correct
24 Correct 4 ms 6748 KB Output is correct
25 Correct 5 ms 6748 KB Output is correct
26 Correct 5 ms 6748 KB Output is correct
27 Correct 5 ms 6748 KB Output is correct
28 Correct 5 ms 6872 KB Output is correct
29 Correct 7 ms 6748 KB Output is correct
30 Correct 4 ms 6748 KB Output is correct
31 Correct 4 ms 6748 KB Output is correct
32 Correct 5 ms 6748 KB Output is correct
33 Correct 4 ms 6748 KB Output is correct
34 Correct 4 ms 6872 KB Output is correct
35 Correct 4 ms 6744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6744 KB Output is correct
2 Correct 3 ms 6748 KB Output is correct
3 Correct 3 ms 6608 KB Output is correct
4 Correct 3 ms 6748 KB Output is correct
5 Correct 3 ms 6748 KB Output is correct
6 Correct 3 ms 6748 KB Output is correct
7 Correct 3 ms 6748 KB Output is correct
8 Correct 3 ms 6748 KB Output is correct
9 Correct 2 ms 6616 KB Output is correct
10 Correct 3 ms 6748 KB Output is correct
11 Correct 3 ms 6748 KB Output is correct
12 Correct 3 ms 6748 KB Output is correct
13 Correct 2 ms 6748 KB Output is correct
14 Correct 3 ms 6744 KB Output is correct
15 Correct 3 ms 6748 KB Output is correct
16 Correct 3 ms 6744 KB Output is correct
17 Correct 4 ms 6752 KB Output is correct
18 Correct 5 ms 6748 KB Output is correct
19 Correct 3 ms 6744 KB Output is correct
20 Correct 3 ms 6748 KB Output is correct
21 Correct 3 ms 6748 KB Output is correct
22 Correct 4 ms 6720 KB Output is correct
23 Correct 5 ms 6968 KB Output is correct
24 Correct 4 ms 6748 KB Output is correct
25 Correct 5 ms 6748 KB Output is correct
26 Correct 5 ms 6748 KB Output is correct
27 Correct 5 ms 6748 KB Output is correct
28 Correct 5 ms 6872 KB Output is correct
29 Correct 7 ms 6748 KB Output is correct
30 Correct 4 ms 6748 KB Output is correct
31 Correct 4 ms 6748 KB Output is correct
32 Correct 5 ms 6748 KB Output is correct
33 Correct 4 ms 6748 KB Output is correct
34 Correct 4 ms 6872 KB Output is correct
35 Correct 4 ms 6744 KB Output is correct
36 Correct 219 ms 19656 KB Output is correct
37 Correct 142 ms 19084 KB Output is correct
38 Correct 70 ms 11976 KB Output is correct
39 Correct 134 ms 17604 KB Output is correct
40 Correct 136 ms 17860 KB Output is correct
41 Correct 163 ms 19140 KB Output is correct
42 Correct 97 ms 16580 KB Output is correct
43 Correct 71 ms 16936 KB Output is correct
44 Incorrect 235 ms 23624 KB Output isn't correct
45 Halted 0 ms 0 KB -