Submission #1370430

#TimeUsernameProblemLanguageResultExecution timeMemory
1370430pirmyratgPassport (JOI23_passport)C++20
Compilation error
0 ms0 KiB
#include "bits/stdc++.h"
using namespace std;

const int N = 6000005;
long long n;
vector<pair<long long, long long>> z[N];
long long cnt[N][3];
long long bruh = 1e16;

void update(int id, int l, int r, int x, int y, int t){
    if(x > r || y < l) return;
    if(l >= x && y >= r){
        z[id + a].push_back({t, 1});
        return;
    }
    int mid = (l + r) / 2;
    update(id * 2, l, mid, x, y, t);
    update(id * 2 + 1, mid + 1, r, x, y, t);
}

void build(int id, int l, int r){
    if(l == r){
        z[l].push_back({id + a, 0});
        return;
    }
    int mid = (l + r) / 2;
    build(id * 2, l, mid);
    build(id * 2 + 1, mid + 1, r);
    z[id * 2 + a].push_back({id + a, 0});
    z[id * 2 + 1 + a].push_back({id + a, 0});
}

void bfs(int sta, int id){
    deque<int> q;
    q.push_front(sta);
    cnt[sta][id] = 0;
    while(q.size()){
        int pos = q.front();
        q.pop_front();
        for(auto p : z[pos]){
            if(cnt[p.first][id] == bruh){
                cnt[p.first][id] = p.second + cnt[pos][id];
                if(p.second) 
                	q.push_back(p.first);
                else 
                	q.push_front(p.first);
            }
        }
    }
}

void dijkstra(){
    priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> q;
    for(int i = 1; i <= a; ++i){
        if(cnt[i][2] < bruh)
            q.push({cnt[i][2], i});
    }
    while(q.size()){
        pair<long long, int> pos = q.top();
        q.pop();
        long long val = pos.first;
        int pos1 = pos.second;
        if(val > cnt[pos1][2]) 
        	continue;
        for(auto p : z[pos1]){
            if(cnt[p.first][2] > val + p.second){
                cnt[p.first][2] = val + p.second;
                q.push({cnt[p.first][2], (int)p.first});
            }
        }
    }
}

int main(){
    scanf("%d", &n);
    for(int i = 1; i <= n; ++i){
        int x, y;
        scanf("%d%d", &x, &y);
        update(1, 1, n, x, y, i);
    }
    build(1, 1, n);
    for(int i = 1; i <= n + n * 4; ++i){
        for(int j = 0; j <= 2; ++j)
            cnt[i][j] = bruh;
    }
    bfs(1, 0);
    bfs(a, 1);
    for(int i = 1; i <= n; ++i){
        if(cnt[i][1] + cnt[i][0] >= bruh) 
        	continue;
        cnt[i][2] = cnt[i][1] + cnt[i][0] - (i != 1 && i != a);
    }
    dijkstra();
    int c;
    scanf("%d", &c);
    while(c--){
        int x;
        scanf("%d", &x);
        if(cnt[x][2] >= bruh) 
        	puts("-1");
        else 
        printf("%lld\n", cnt[x][2]);
    }
    return 0;
}

Compilation message (stderr)

passport.cpp: In function 'void update(int, int, int, int, int, int)':
passport.cpp:13:16: error: 'a' was not declared in this scope
   13 |         z[id + a].push_back({t, 1});
      |                ^
passport.cpp: In function 'void build(int, int, int)':
passport.cpp:23:30: error: 'a' was not declared in this scope
   23 |         z[l].push_back({id + a, 0});
      |                              ^
passport.cpp:23:23: error: no matching function for call to 'std::vector<std::pair<long long int, long long int> >::push_back(<brace-enclosed initializer list>)'
   23 |         z[l].push_back({id + a, 0});
      |         ~~~~~~~~~~~~~~^~~~~~~~~~~~~
In file included from /usr/include/c++/13/vector:66,
                 from /usr/include/c++/13/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:53,
                 from passport.cpp:1:
/usr/include/c++/13/bits/stl_vector.h:1281:7: note: candidate: 'constexpr void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::pair<long long int, long long int>; _Alloc = std::allocator<std::pair<long long int, long long int> >; value_type = std::pair<long long int, long long int>]'
 1281 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/13/bits/stl_vector.h:1281:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const std::vector<std::pair<long long int, long long int> >::value_type&' {aka 'const std::pair<long long int, long long int>&'}
 1281 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/13/bits/stl_vector.h:1298:7: note: candidate: 'constexpr void std::vector<_Tp, _Alloc>::push_back(value_type&&) [with _Tp = std::pair<long long int, long long int>; _Alloc = std::allocator<std::pair<long long int, long long int> >; value_type = std::pair<long long int, long long int>]'
 1298 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/13/bits/stl_vector.h:1298:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<std::pair<long long int, long long int> >::value_type&&' {aka 'std::pair<long long int, long long int>&&'}
 1298 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
passport.cpp:29:16: error: 'a' was not declared in this scope
   29 |     z[id * 2 + a].push_back({id + a, 0});
      |                ^
passport.cpp: In function 'void dijkstra()':
passport.cpp:54:25: error: 'a' was not declared in this scope
   54 |     for(int i = 1; i <= a; ++i){
      |                         ^
passport.cpp: In function 'int main()':
passport.cpp:75:13: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
   75 |     scanf("%d", &n);
      |            ~^   ~~
      |             |   |
      |             |   long long int*
      |             int*
      |            %lld
passport.cpp:87:9: error: 'a' was not declared in this scope
   87 |     bfs(a, 1);
      |         ^
passport.cpp:75:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   75 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
passport.cpp:78:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   78 |         scanf("%d%d", &x, &y);
      |         ~~~~~^~~~~~~~~~~~~~~~
passport.cpp:95:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   95 |     scanf("%d", &c);
      |     ~~~~~^~~~~~~~~~
passport.cpp:98:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   98 |         scanf("%d", &x);
      |         ~~~~~^~~~~~~~~~