Submission #284336

# Submission time Handle Problem Language Result Execution time Memory
284336 2020-08-27T08:55:04 Z Alexa2001 None (JOI16_matryoshka) C++17
100 / 100
341 ms 16368 KB
#include <bits/stdc++.h>

using namespace std;

const int Nmax = 2e5 + 5;

int A[Nmax], B[Nmax], C[Nmax], D[Nmax], ans[Nmax];
vector<int> as;

int n, q;


class AIB
{
    int a[Nmax];

    int ub(int x)
    {
        return (x&(-x));
    }

public:
    int query(int x)
    {
        x = lower_bound(as.begin(), as.end(), x) - as.begin() + 1;

        int ans = 0;
        for(; x<=n; x+=ub(x))
            ans = max(ans, a[x]);
        return ans;
    }

    void update(int pos, int val)
    {
        pos = lower_bound(as.begin(), as.end(), pos) - as.begin() + 1;

        for(; pos; pos-=ub(pos))
            a[pos] = max(a[pos], val);
    }
} aib;

void add(int x)
{
    int res = aib.query(x);
    aib.update(x, res+1);
}

int main()
{
  //  freopen("input", "r", stdin);
    cin.tie(0); cin.sync_with_stdio(false);

    cin >> n >> q;

    int i;

    for(i=1; i<=n; ++i) cin >> A[i] >> B[i];
    for(i=1; i<=q; ++i) cin >> C[i] >> D[i];

    vector<int> ord1(n), ord2(q);
    iota(ord1.begin(), ord1.end(), 1);
    iota(ord2.begin(), ord2.end(), 1);

    sort(ord1.begin(), ord1.end(), [] (int x, int y) { if(B[x] == B[y]) return A[x] > A[y]; return B[x] < B[y]; } );
    sort(ord2.begin(), ord2.end(), [] (int x, int y) { return D[x] < D[y]; } );

    for(i=1; i<=n; ++i) as.push_back(A[i]);
    sort(as.begin(), as.end());
    as.erase( unique(as.begin(), as.end()), as.end() );

    i = 0;
    for(auto id : ord2)
    {
        while(i < n && B[ord1[i]] <= D[id])
            add(A[ord1[i]]), ++i;

        ans[id] = aib.query(C[id]);
    }

    for(i=1; i<=q; ++i) cout << ans[i] << '\n';

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 2 ms 512 KB Output is correct
23 Correct 3 ms 512 KB Output is correct
24 Correct 3 ms 488 KB Output is correct
25 Correct 3 ms 512 KB Output is correct
26 Correct 3 ms 512 KB Output is correct
27 Correct 3 ms 512 KB Output is correct
28 Correct 2 ms 512 KB Output is correct
29 Correct 2 ms 512 KB Output is correct
30 Correct 2 ms 512 KB Output is correct
31 Correct 3 ms 512 KB Output is correct
32 Correct 3 ms 512 KB Output is correct
33 Correct 3 ms 512 KB Output is correct
34 Correct 3 ms 512 KB Output is correct
35 Correct 3 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 2 ms 512 KB Output is correct
23 Correct 3 ms 512 KB Output is correct
24 Correct 3 ms 488 KB Output is correct
25 Correct 3 ms 512 KB Output is correct
26 Correct 3 ms 512 KB Output is correct
27 Correct 3 ms 512 KB Output is correct
28 Correct 2 ms 512 KB Output is correct
29 Correct 2 ms 512 KB Output is correct
30 Correct 2 ms 512 KB Output is correct
31 Correct 3 ms 512 KB Output is correct
32 Correct 3 ms 512 KB Output is correct
33 Correct 3 ms 512 KB Output is correct
34 Correct 3 ms 512 KB Output is correct
35 Correct 3 ms 512 KB Output is correct
36 Correct 300 ms 13424 KB Output is correct
37 Correct 265 ms 12824 KB Output is correct
38 Correct 100 ms 5620 KB Output is correct
39 Correct 180 ms 10352 KB Output is correct
40 Correct 180 ms 10864 KB Output is correct
41 Correct 293 ms 12644 KB Output is correct
42 Correct 131 ms 9580 KB Output is correct
43 Correct 96 ms 9712 KB Output is correct
44 Correct 306 ms 15984 KB Output is correct
45 Correct 329 ms 15984 KB Output is correct
46 Correct 341 ms 16240 KB Output is correct
47 Correct 306 ms 15728 KB Output is correct
48 Correct 306 ms 16240 KB Output is correct
49 Correct 297 ms 15856 KB Output is correct
50 Correct 292 ms 16368 KB Output is correct