답안 #320929

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
320929 2020-11-10T09:19:03 Z lohacho Matryoshka (JOI16_matryoshka) C++14
100 / 100
634 ms 26192 KB
#include <bits/stdc++.h>

using namespace std;

using LL = long long;
const int MOD = (int)1e9 + 7;
const int NS = (int)8e5 + 4;
int N, Q;
struct Data{
    int a, b, num;
    bool operator<(const Data&r)const{
        return a < r.a || (a == r.a && b > r.b);
    }
};
Data doll[NS], ask[NS];
int ans[NS];
vector<int> srt;
int tree[NS * 4];

void push(int num, int s, int e, int pos, int val){
    if(pos < s || pos > e) return;
    if(s == e){
        tree[num] = max(tree[num], val);
        return;
    }
    push(num * 2, s, (s + e) / 2, pos, val), push(num * 2 + 1, (s + e) / 2 + 1, e, pos, val);
    tree[num] = max(tree[num * 2], tree[num * 2 + 1]);
}

int get(int num, int s, int e, int fs, int fe){
    if(fe < s || fs > e){
        return 0;
    }
    if(s >= fs && e <= fe){
        return tree[num];
    }
    return max(get(num * 2, s, (s + e) / 2, fs, fe), get(num * 2 + 1, (s + e) / 2 + 1, e, fs, fe));
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> N >> Q;
    for(int i = 1; i <= N; ++i){
        cin >> doll[i].a >> doll[i].b;
        srt.push_back(doll[i].a), srt.push_back(doll[i].b);
    }
    for(int i = 1; i <= Q; ++i){
        cin >> ask[i].a >> ask[i].b;
        srt.push_back(ask[i].a), srt.push_back(ask[i].b);
        ask[i].num = i;
    }
    sort(srt.begin(), srt.end());
    srt.erase(unique(srt.begin(), srt.end()), srt.end());
    for(int i = 1; i <= N; ++i){
        doll[i].a = lower_bound(srt.begin(), srt.end(), doll[i].a) - srt.begin() + 1;
        doll[i].b = lower_bound(srt.begin(), srt.end(), doll[i].b) - srt.begin() + 1;
    }
    for(int i = 1; i <= Q; ++i){
        ask[i].a = lower_bound(srt.begin(), srt.end(), ask[i].a) - srt.begin() + 1;
        ask[i].b = lower_bound(srt.begin(), srt.end(), ask[i].b) - srt.begin() + 1;
    }
    sort(doll + 1, doll + N + 1);
    sort(ask + 1, ask + Q + 1);
    int j = Q;
    for(int i = N; i >= 1; --i){
        while(j && ask[j].a > doll[i].a){
            ans[ask[j].num] = get(1, 1, (int)srt.size(), 1, ask[j].b);
            --j;
        }
        int val = get(1, 1, (int)srt.size(), 1, doll[i].b);
        push(1, 1, (int)srt.size(), doll[i].b, val + 1);
    }
    while(j){
        ans[ask[j].num] = get(1, 1, (int)srt.size(), 1, ask[j].b);
        --j;
    }
    for(int i = 1; i <= Q; ++i){
        cout << ans[i] << '\n';
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 2 ms 492 KB Output is correct
23 Correct 5 ms 620 KB Output is correct
24 Correct 4 ms 620 KB Output is correct
25 Correct 4 ms 620 KB Output is correct
26 Correct 4 ms 620 KB Output is correct
27 Correct 4 ms 620 KB Output is correct
28 Correct 4 ms 620 KB Output is correct
29 Correct 5 ms 620 KB Output is correct
30 Correct 4 ms 492 KB Output is correct
31 Correct 5 ms 620 KB Output is correct
32 Correct 4 ms 620 KB Output is correct
33 Correct 4 ms 620 KB Output is correct
34 Correct 4 ms 620 KB Output is correct
35 Correct 5 ms 620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 2 ms 492 KB Output is correct
23 Correct 5 ms 620 KB Output is correct
24 Correct 4 ms 620 KB Output is correct
25 Correct 4 ms 620 KB Output is correct
26 Correct 4 ms 620 KB Output is correct
27 Correct 4 ms 620 KB Output is correct
28 Correct 4 ms 620 KB Output is correct
29 Correct 5 ms 620 KB Output is correct
30 Correct 4 ms 492 KB Output is correct
31 Correct 5 ms 620 KB Output is correct
32 Correct 4 ms 620 KB Output is correct
33 Correct 4 ms 620 KB Output is correct
34 Correct 4 ms 620 KB Output is correct
35 Correct 5 ms 620 KB Output is correct
36 Correct 506 ms 17764 KB Output is correct
37 Correct 376 ms 14416 KB Output is correct
38 Correct 184 ms 9436 KB Output is correct
39 Correct 291 ms 12880 KB Output is correct
40 Correct 291 ms 13264 KB Output is correct
41 Correct 445 ms 14564 KB Output is correct
42 Correct 164 ms 11984 KB Output is correct
43 Correct 102 ms 12112 KB Output is correct
44 Correct 634 ms 25848 KB Output is correct
45 Correct 615 ms 25808 KB Output is correct
46 Correct 612 ms 25940 KB Output is correct
47 Correct 564 ms 25680 KB Output is correct
48 Correct 566 ms 26192 KB Output is correct
49 Correct 560 ms 25556 KB Output is correct
50 Correct 571 ms 26192 KB Output is correct