답안 #544957

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
544957 2022-04-03T08:25:15 Z byunjaewoo Matryoshka (JOI16_matryoshka) C++17
100 / 100
1489 ms 92792 KB
#include <bits/stdc++.h>
using namespace std;

const int S=(1<<19), Nmax=200010;
class SegTree {
public:
    void Update(int k, int v) {Update(1, 1, S, k, v);}
    int Query(int l, int r) {return Query(1, 1, S, l, r);}
private:
    int Tree[2*S];
    void Update(int node, int s, int e, int k, int v) {
        if(s==e) {
            Tree[node]=max(Tree[node], v);
            return;
        }
        int lch=2*node, rch=lch+1, m=(s+e)/2;
        if(k<=m) Update(lch, s, m, k, v);
        else Update(rch, m+1, e, k, v);
        Tree[node]=max(Tree[lch], Tree[rch]);
    }
    int Query(int node, int s, int e, int l, int r) {
        if(s>r || l>e) return 0;
        if(l<=s && e<=r) return Tree[node];
        int lch=2*node, rch=lch+1, m=(s+e)/2;
        return max(Query(lch, s, m, l, r), Query(rch, m+1, e, l, r));
    }
}T;
int N, Q, cntx, cnty, ans[Nmax];
struct Data {int x, y, op;};
set<int> Sx, Sy;
map<int, int> Mx, My;
vector<Data> V;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>N>>Q;
    for(int i=1; i<=N; i++) {
        int x, y; cin>>x>>y;
        Sx.insert(x); Sy.insert(y);
        V.push_back({x, y, 0});
    }
    for(int i=1; i<=Q; i++) {
        int x, y; cin>>x>>y;
        Sx.insert(x); Sy.insert(y);
        V.push_back({x, y, i});
    }
    for(int i:Sx) Mx[i]=++cntx;
    for(int i:Sy) My[i]=++cnty;
    sort(V.begin(), V.end(), [](Data u, Data v) {return (u.x!=v.x)?(u.x>v.x):((u.y!=v.y)?(u.y<v.y):(u.op<v.op));});
    for(Data i:V) {
        i.x=Mx[i.x], i.y=My[i.y];
        int tmp=T.Query(1, i.y);
        if(i.op) ans[i.op]=tmp;
        else T.Update(i.y, tmp+1);
    }
    for(int i=1; i<=Q; i++) cout<<ans[i]<<"\n";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 3 ms 724 KB Output is correct
23 Correct 5 ms 1236 KB Output is correct
24 Correct 6 ms 1240 KB Output is correct
25 Correct 5 ms 1316 KB Output is correct
26 Correct 6 ms 1236 KB Output is correct
27 Correct 6 ms 1276 KB Output is correct
28 Correct 5 ms 1244 KB Output is correct
29 Correct 5 ms 980 KB Output is correct
30 Correct 2 ms 524 KB Output is correct
31 Correct 6 ms 1216 KB Output is correct
32 Correct 6 ms 1312 KB Output is correct
33 Correct 6 ms 1244 KB Output is correct
34 Correct 6 ms 1236 KB Output is correct
35 Correct 5 ms 1244 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 3 ms 724 KB Output is correct
23 Correct 5 ms 1236 KB Output is correct
24 Correct 6 ms 1240 KB Output is correct
25 Correct 5 ms 1316 KB Output is correct
26 Correct 6 ms 1236 KB Output is correct
27 Correct 6 ms 1276 KB Output is correct
28 Correct 5 ms 1244 KB Output is correct
29 Correct 5 ms 980 KB Output is correct
30 Correct 2 ms 524 KB Output is correct
31 Correct 6 ms 1216 KB Output is correct
32 Correct 6 ms 1312 KB Output is correct
33 Correct 6 ms 1244 KB Output is correct
34 Correct 6 ms 1236 KB Output is correct
35 Correct 5 ms 1244 KB Output is correct
36 Correct 914 ms 49108 KB Output is correct
37 Correct 586 ms 47920 KB Output is correct
38 Correct 363 ms 32376 KB Output is correct
39 Correct 200 ms 9716 KB Output is correct
40 Correct 212 ms 10192 KB Output is correct
41 Correct 495 ms 32248 KB Output is correct
42 Correct 147 ms 8800 KB Output is correct
43 Correct 129 ms 8908 KB Output is correct
44 Correct 1441 ms 92648 KB Output is correct
45 Correct 1489 ms 92544 KB Output is correct
46 Correct 1483 ms 92792 KB Output is correct
47 Correct 1366 ms 92180 KB Output is correct
48 Correct 1307 ms 92708 KB Output is correct
49 Correct 1309 ms 92136 KB Output is correct
50 Correct 1323 ms 92704 KB Output is correct