답안 #1005827

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1005827 2024-06-23T06:36:28 Z Trisanu_Das Fire (BOI24_fire) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    ios_base::sync_with_stdio(0); cin.tie(nullptr);    
    int n, m; cin >> n >> m;
    vector<int> l(n + 1), r(n + 1);
    for (int i = 1; i <= n; i++){
        cin >> l[i] >> r[i];
        if (!r[i]) r[i] = m;
        else r[i]--;
        if (l[i] > r[i]) r[i] += m;
    }
    vector<pair<int, int> > all;
    for (int i = 1; i <= n; i++) all.push_back({l[i], r[i]});
    sort(all.begin(), all.end());
    vector<pair<int, int> > tmp;
    int i = 0;
    while (i < n){
        int j = i;
        while (j < n && all[i].ff == all[j].ff) j++;
        tmp.push_back({all[j - 1].second, all[j - 1].first});
        i = j;
    }
    all = tmp;
    sort(all.begin(), all.end());
    tmp.clear();
    i = 0;
    while (i < all.size()){
        int j = i;
        while (j < all.size() && all[i].first == all[j].first) j++;
        tmp.pb({all[i].ss, all[i].ff});
        i = j;
    }
    all = tmp;
    sort(all.begin(), all.end());
    n = (int) all.size();
    vector<int> log(n + 1);
    for (int i = 2; i <= n; i++)log[i] = log[i / 2] + 1;
    const int lg = log[n];
    vector<vector<pii>> sp(n, vector<pii>(lg + 1));
    for (int i = 0; i < n; i++) sp[i][0] = {all[i].ss, i};
    for (int k = 1; k <= lg; k++)
        for (int i = 0; i + (1 << k) <= n; i++)
            sp[i][k] = max(sp[i][k - 1], sp[i + (1 << (k - 1))][k - 1]);
    auto get = [&](int l, int r){
        int k = log[r - l + 1];
        return max(sp[l][k], sp[r - (1 << k) + 1][k]);
    };
    vector<int> ls;
    for (int i = 0; i < n; i++) ls.pb(all[i].ff);
    vector<int> :: iterator it1, it2;
    vector<int> g(n);
    for (int i = 0; i < n; i++){
        auto &[l, r] = all[i];
        it1 = lower_bound(ls.begin(), ls.end(), l);
        it2 = upper_bound(ls.begin(), ls.end(), r + 1); it2--;
        int lb = max(i + 1, (int) (it1 - ls.begin())), rb = (int) (it2 - ls.begin());
        if (lb > rb){
            g[i] = -1;
            continue;
        }
        g[i] = get(lb, rb).ss;
    }
    int out = n + 1;
    for (int i = 0; i < n; i++){
        int j = i, cnt = 1, rr = all[i].ff + m - 1;
        while (j != -1 && all[j].ss < rr){
            j = g[j];
            cnt++;
        }
        if (j != -1) out = min(out, cnt);
    }
    cout<<((out > n) ? -1 : out)<<"\n";
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:21:32: error: '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'struct std::pair<int, int>'} has no member named 'ff'
   21 |         while (j < n && all[i].ff == all[j].ff) j++;
      |                                ^~
Main.cpp:21:45: error: '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'struct std::pair<int, int>'} has no member named 'ff'
   21 |         while (j < n && all[i].ff == all[j].ff) j++;
      |                                             ^~
Main.cpp:29:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |     while (i < all.size()){
      |            ~~^~~~~~~~~~~~
Main.cpp:31:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |         while (j < all.size() && all[i].first == all[j].first) j++;
      |                ~~^~~~~~~~~~~~
Main.cpp:32:13: error: 'class std::vector<std::pair<int, int> >' has no member named 'pb'
   32 |         tmp.pb({all[i].ss, all[i].ff});
      |             ^~
Main.cpp:32:24: error: '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'struct std::pair<int, int>'} has no member named 'ss'
   32 |         tmp.pb({all[i].ss, all[i].ff});
      |                        ^~
Main.cpp:32:35: error: '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'struct std::pair<int, int>'} has no member named 'ff'
   32 |         tmp.pb({all[i].ss, all[i].ff});
      |                                   ^~
Main.cpp:41:19: error: 'pii' was not declared in this scope
   41 |     vector<vector<pii>> sp(n, vector<pii>(lg + 1));
      |                   ^~~
Main.cpp:41:19: error: template argument 1 is invalid
Main.cpp:41:19: error: template argument 2 is invalid
Main.cpp:41:22: error: template argument 1 is invalid
   41 |     vector<vector<pii>> sp(n, vector<pii>(lg + 1));
      |                      ^~
Main.cpp:41:22: error: template argument 2 is invalid
Main.cpp:41:41: error: template argument 2 is invalid
   41 |     vector<vector<pii>> sp(n, vector<pii>(lg + 1));
      |                                         ^
Main.cpp:41:50: error: expression list treated as compound expression in initializer [-fpermissive]
   41 |     vector<vector<pii>> sp(n, vector<pii>(lg + 1));
      |                                                  ^
Main.cpp:42:35: error: invalid types 'int[int]' for array subscript
   42 |     for (int i = 0; i < n; i++) sp[i][0] = {all[i].ss, i};
      |                                   ^
Main.cpp:42:52: error: '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'struct std::pair<int, int>'} has no member named 'ss'
   42 |     for (int i = 0; i < n; i++) sp[i][0] = {all[i].ss, i};
      |                                                    ^~
Main.cpp:45:15: error: invalid types 'int[int]' for array subscript
   45 |             sp[i][k] = max(sp[i][k - 1], sp[i + (1 << (k - 1))][k - 1]);
      |               ^
Main.cpp:45:30: error: invalid types 'int[int]' for array subscript
   45 |             sp[i][k] = max(sp[i][k - 1], sp[i + (1 << (k - 1))][k - 1]);
      |                              ^
Main.cpp:45:44: error: invalid types 'int[int]' for array subscript
   45 |             sp[i][k] = max(sp[i][k - 1], sp[i + (1 << (k - 1))][k - 1]);
      |                                            ^
Main.cpp: In lambda function:
Main.cpp:48:22: error: invalid types 'int[int]' for array subscript
   48 |         return max(sp[l][k], sp[r - (1 << k) + 1][k]);
      |                      ^
Main.cpp:48:32: error: invalid types 'int[int]' for array subscript
   48 |         return max(sp[l][k], sp[r - (1 << k) + 1][k]);
      |                                ^
Main.cpp: In function 'int main()':
Main.cpp:51:36: error: 'class std::vector<int>' has no member named 'pb'
   51 |     for (int i = 0; i < n; i++) ls.pb(all[i].ff);
      |                                    ^~
Main.cpp:51:46: error: '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'struct std::pair<int, int>'} has no member named 'ff'
   51 |     for (int i = 0; i < n; i++) ls.pb(all[i].ff);
      |                                              ^~
Main.cpp:67:41: error: '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'struct std::pair<int, int>'} has no member named 'ff'
   67 |         int j = i, cnt = 1, rr = all[i].ff + m - 1;
      |                                         ^~
Main.cpp:68:34: error: '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'struct std::pair<int, int>'} has no member named 'ss'
   68 |         while (j != -1 && all[j].ss < rr){
      |                                  ^~