Submission #935229

# Submission time Handle Problem Language Result Execution time Memory
935229 2024-02-28T22:19:52 Z asdasdqwer None (JOI16_matryoshka) C++14
100 / 100
436 ms 27520 KB
#include <bits/stdc++.h>
using namespace std;

#define pii array<int,2>

signed main() {
    int n,q;cin>>n>>q;
    vector<pii> dolls(n);
    for (auto &x:dolls) {
        cin>>x[0]>>x[1];
    }

    sort(dolls.begin(), dolls.end(), [](const pii &x, const pii &y) {
        if (x[0] != y[0]) return x[0] > y[0];
        return x[1] < y[1];
    });

    vector<pii> quer(q);
    for (auto &x:quer)cin>>x[0]>>x[1];

    vector<pii> srtQuer = quer;

    sort(srtQuer.begin(), srtQuer.end(), [](const pii &x, const pii &y) {
        if (x[0] != y[0]) return x[0] < y[0];
        return x[1] < y[1];
    });

    map<pii,int> ans;
    while (srtQuer.size() && srtQuer.back()[0] > dolls[0][0]) {
        ans[srtQuer.back()] = 0;
        srtQuer.pop_back();
    }

    dolls.push_back({-1, -1});
    vector<int> lis;

    for (int i=0;i<n;i++) {
        auto it = upper_bound(lis.begin(), lis.end(), dolls[i][1]);
        if (it == lis.end()) {
            lis.push_back(dolls[i][1]);
        }

        else {
            int dis = (int)distance(lis.begin(), it);
            lis[dis] = dolls[i][1];
        }

        while (srtQuer.size() && srtQuer.back()[0] > dolls[i+1][0]) {
            pii qq = srtQuer.back();srtQuer.pop_back();
            auto it2 = upper_bound(lis.begin(), lis.end(), qq[1]);
            ans[qq] = (int)distance(lis.begin(), it2);
        }
    }

    for (auto x:quer) {
        cout<<ans[x]<<"\n";
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 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 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 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 0 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 348 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 1 ms 348 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
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 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 0 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 348 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 1 ms 348 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 2 ms 636 KB Output is correct
23 Correct 3 ms 604 KB Output is correct
24 Correct 3 ms 604 KB Output is correct
25 Correct 3 ms 600 KB Output is correct
26 Correct 3 ms 604 KB Output is correct
27 Correct 3 ms 600 KB Output is correct
28 Correct 3 ms 600 KB Output is correct
29 Correct 3 ms 856 KB Output is correct
30 Correct 2 ms 348 KB Output is correct
31 Correct 3 ms 604 KB Output is correct
32 Correct 3 ms 604 KB Output is correct
33 Correct 4 ms 604 KB Output is correct
34 Correct 4 ms 600 KB Output is correct
35 Correct 4 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 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 0 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 348 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 1 ms 348 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 2 ms 636 KB Output is correct
23 Correct 3 ms 604 KB Output is correct
24 Correct 3 ms 604 KB Output is correct
25 Correct 3 ms 600 KB Output is correct
26 Correct 3 ms 604 KB Output is correct
27 Correct 3 ms 600 KB Output is correct
28 Correct 3 ms 600 KB Output is correct
29 Correct 3 ms 856 KB Output is correct
30 Correct 2 ms 348 KB Output is correct
31 Correct 3 ms 604 KB Output is correct
32 Correct 3 ms 604 KB Output is correct
33 Correct 4 ms 604 KB Output is correct
34 Correct 4 ms 600 KB Output is correct
35 Correct 4 ms 604 KB Output is correct
36 Correct 325 ms 23456 KB Output is correct
37 Correct 329 ms 23832 KB Output is correct
38 Correct 102 ms 6872 KB Output is correct
39 Correct 275 ms 19892 KB Output is correct
40 Correct 285 ms 20704 KB Output is correct
41 Correct 317 ms 24088 KB Output is correct
42 Correct 141 ms 9692 KB Output is correct
43 Correct 118 ms 11056 KB Output is correct
44 Correct 436 ms 27264 KB Output is correct
45 Correct 379 ms 26688 KB Output is correct
46 Correct 409 ms 26216 KB Output is correct
47 Correct 376 ms 25648 KB Output is correct
48 Correct 397 ms 27112 KB Output is correct
49 Correct 389 ms 27520 KB Output is correct
50 Correct 388 ms 26168 KB Output is correct