답안 #696329

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
696329 2023-02-06T08:55:58 Z Cross_Ratio Bread First Search (CCO21_day2problem2) C++14
25 / 25
154 ms 16172 KB
#include <bits/stdc++.h>
using namespace std;
int B[200005];
vector<int> adj[200005];
struct SegTree {
    vector<int> seg;
    int MAX;
    SegTree(int N) {
        int i;
        for(i=1;i<2*N;i*=2) {}
        seg.resize(i);
        MAX = i;
        for(i=0;i<MAX;i++) seg[i] = -1e9;
    }
    void add(int s, int e, int k, int n, int ns, int ne) {
        if(e<=ns||ne<=s) return;
        if(s<=ns&&ne<=e) {
            seg[n] = max(seg[n], k);
            return;
        }
        int mid = ns + ne >> 1;
        add(s, e, k, 2*n, ns, mid);
        add(s, e, k, 2*n+1, mid, ne);
    }
    int get_val(int n) {
        n += MAX/2;
        int v = seg[n];
        while(n != 0) {
            v = max(v, seg[n]);
            n /= 2;
        }
        return v;
    }
};
set<int> S;
signed main() {
    cin.sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int N, M;
    cin >> N >> M;
    int i, j;
    for(i=1;i<=N;i++) B[i] = i;
    for(i=0;i<M;i++) {
        int a, b;
        cin >> a >> b;
        if(a > b) swap(a, b);
        B[a] = max(B[a], b);
        adj[a].push_back(b);
    }
    SegTree tree(N+3);
    int MAX = tree.MAX;
    tree.add(1, 2, 0, 1, 0, MAX/2);
    int ma = 1;
    for(i=1;i<=N;i++) {
        ma = max(ma, B[i]);
        int v = tree.get_val(i);
        S.erase(i);
        for(int n : adj[i]) {
            S.insert(n);
        }
        //cout << v << ' ' << S.size() << '\n';
        //cout << i << " : " << ma << ' ' << v + (int)S.size() << '\n';
        tree.add(ma, N+1, v + (int)S.size(), 1, 0, MAX/2);
    }
    cout << N-1 - tree.get_val(N);
}

Compilation message

Main.cpp: In member function 'void SegTree::add(int, int, int, int, int, int)':
Main.cpp:21:22: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   21 |         int mid = ns + ne >> 1;
      |                   ~~~^~~~
Main.cpp: In function 'int main()':
Main.cpp:42:12: warning: unused variable 'j' [-Wunused-variable]
   42 |     int i, j;
      |            ^
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 3 ms 5020 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 4 ms 4952 KB Output is correct
7 Correct 3 ms 5028 KB Output is correct
8 Correct 3 ms 5028 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 3 ms 5020 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 4 ms 4952 KB Output is correct
7 Correct 3 ms 5028 KB Output is correct
8 Correct 3 ms 5028 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 3 ms 5020 KB Output is correct
14 Correct 2 ms 4948 KB Output is correct
15 Correct 2 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 4 ms 4952 KB Output is correct
18 Correct 3 ms 5028 KB Output is correct
19 Correct 3 ms 5028 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 3 ms 5076 KB Output is correct
24 Correct 3 ms 5032 KB Output is correct
25 Correct 8 ms 5332 KB Output is correct
26 Correct 7 ms 5332 KB Output is correct
27 Correct 8 ms 5332 KB Output is correct
28 Correct 7 ms 5320 KB Output is correct
29 Correct 4 ms 5204 KB Output is correct
30 Correct 16 ms 5816 KB Output is correct
31 Correct 12 ms 5784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 3 ms 5020 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 4 ms 4952 KB Output is correct
7 Correct 3 ms 5028 KB Output is correct
8 Correct 3 ms 5028 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 3 ms 5020 KB Output is correct
14 Correct 2 ms 4948 KB Output is correct
15 Correct 2 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 4 ms 4952 KB Output is correct
18 Correct 3 ms 5028 KB Output is correct
19 Correct 3 ms 5028 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 3 ms 5076 KB Output is correct
24 Correct 3 ms 5032 KB Output is correct
25 Correct 8 ms 5332 KB Output is correct
26 Correct 7 ms 5332 KB Output is correct
27 Correct 8 ms 5332 KB Output is correct
28 Correct 7 ms 5320 KB Output is correct
29 Correct 4 ms 5204 KB Output is correct
30 Correct 16 ms 5816 KB Output is correct
31 Correct 12 ms 5784 KB Output is correct
32 Correct 40 ms 7840 KB Output is correct
33 Correct 38 ms 8020 KB Output is correct
34 Correct 103 ms 13596 KB Output is correct
35 Correct 138 ms 14256 KB Output is correct
36 Correct 118 ms 14224 KB Output is correct
37 Correct 123 ms 14356 KB Output is correct
38 Correct 35 ms 7764 KB Output is correct
39 Correct 34 ms 8112 KB Output is correct
40 Correct 65 ms 10480 KB Output is correct
41 Correct 130 ms 14936 KB Output is correct
42 Correct 148 ms 16096 KB Output is correct
43 Correct 154 ms 16172 KB Output is correct
44 Correct 4 ms 4948 KB Output is correct
45 Correct 2 ms 5028 KB Output is correct