Submission #934249

# Submission time Handle Problem Language Result Execution time Memory
934249 2024-02-27T04:16:36 Z VinhLuu Factories (JOI14_factories) C++17
Compilation error
0 ms 0 KB
// REPUTATION RATING = -100

#include <bits/stdc++.h>
#define int long long
#define ll long long
#define fi first
#define se second
#define pb push_back
#define all(lmao) lmao.begin(), lmao.end()
#include "factories.h"
using namespace std;

typedef pair<int,int> pii;
typedef tuple<int,int,int> tp;
const int N = 5e5 + 5;
const int oo = 1e9;
const int mod = 1e9 + 7;

int n, q, st[N << 1], f[N][22], in[N], en[N], demin, d[N], a[N];

vector<pii> p[N];

void dfs(int u,int v){
    in[u] = ++demin;
    a[in[u]] = u;
    if(u == 1) for(int i = 0; i <= 20; i ++) f[u][i] = u;
    else{
        f[u][0] = v;
        for(int i = 1; i <= 20; i ++) f[u][i] = f[f[u][i - 1]][i - 1];
    }
    for(auto jj : p[u]){
        int j = jj.fi;
        int w = jj.se;
        if(j == v) continue;
        d[j] = d[u] + w;
        dfs(j, u);
    }
    en[u] = demin;
}

bool kt(int u,int v){
    return in[u] <= in[v] && in[v] <= en[u];
}

int lca(int u,int v){
    if(kt(u, v)) return u;
    else{
        int kq = u;
        for(int i = 20; i >= 0; i --){
            if(kt(f[u][i], v)) kq = f[u][i];
            else u = f[u][i];
        }
        return kq;
    }
}

void update(int i,int x){
    i += n - 1;
    st[i] = x;
    while(i > 1){
        i /= 2;
        st[i] = min(st[i << 1], st[i << 1|1]);
    }
}

int get(int l,int r){
    r++;
    int ret = 1e9;
    for(l += n - 1, r += n - 1; l < r; l /= 2, r /= 2){
        if(l & 1) ret = min(ret, st[l ++]);
        if(r & 1) ret = min(ret, st[-- r]);
    }
    return ret;
}

void Init(int N, int*A, int*B, int*D){
    n = N;
    for(int i = 0; i < n - 1; i ++){
        int x = A[i] + 1, y = B[i] + 1, w = D[i];
        p[x].pb({y, w});
        p[y].pb({x, w});
    }
    dfs(1, 0);
    for(int i = 1; i <= 2 * n; i ++) st[i] = oo;
}

long long Query(int S, int*X, int T,int*Y){
    int ans = (int)1e16;
    for(int time = 0; time <= 1; time ++){
        for(auto j : X) update(in[j], in[j]);
        for(auto j : Y){
            int u = get(in[j], en[j]);
            if(u == oo) continue;
            u = a[u];
            ans = min(ans, d[j] + d[u] - 2 * d[lca(u, j)]);
        }
        for(auto j : X) update(in[j], oo);
        if(time == 0) swap(X, Y);
    }
    return ans;
}

//#define LOCAL

#ifdef LOCAL

signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    #define task "v"
    if(fopen(task ".inp","r")){
        freopen(task ".inp","r",stdin);
        freopen(task ".out","w",stdout);
    }

//    cin >> n >> q;
//    for(int i = 1; i <= 2 * n; i ++) st[i] = (int)1e9;
//    for(int i = 1; i <= n - 1; i ++){
//        int x, y; cin >> x >> y;
//        p[x].pb(y);
//        p[y].pb(x);
//    }
//    dfs(1, 0);
}
#endif // LOCAL

Compilation message

factories.cpp: In function 'long long int Query(long long int, long long int*, long long int, long long int*)':
factories.cpp:90:22: error: 'begin' was not declared in this scope
   90 |         for(auto j : X) update(in[j], in[j]);
      |                      ^
factories.cpp:90:22: note: suggested alternatives:
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:95,
                 from factories.cpp:3:
/usr/include/c++/10/valarray:1224:5: note:   'std::begin'
 1224 |     begin(const valarray<_Tp>& __va)
      |     ^~~~~
In file included from /usr/include/c++/10/filesystem:46,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:129,
                 from factories.cpp:3:
/usr/include/c++/10/bits/fs_dir.h:549:3: note:   'std::filesystem::__cxx11::begin'
  549 |   begin(recursive_directory_iterator __iter) noexcept
      |   ^~~~~
factories.cpp:90:22: error: 'end' was not declared in this scope
   90 |         for(auto j : X) update(in[j], in[j]);
      |                      ^
factories.cpp:90:22: note: suggested alternatives:
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:95,
                 from factories.cpp:3:
/usr/include/c++/10/valarray:1244:5: note:   'std::end'
 1244 |     end(const valarray<_Tp>& __va)
      |     ^~~
In file included from /usr/include/c++/10/filesystem:46,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:129,
                 from factories.cpp:3:
/usr/include/c++/10/bits/fs_dir.h:554:3: note:   'std::filesystem::__cxx11::end'
  554 |   end(recursive_directory_iterator) noexcept
      |   ^~~
factories.cpp:91:22: error: 'begin' was not declared in this scope
   91 |         for(auto j : Y){
      |                      ^
factories.cpp:91:22: note: suggested alternatives:
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:95,
                 from factories.cpp:3:
/usr/include/c++/10/valarray:1224:5: note:   'std::begin'
 1224 |     begin(const valarray<_Tp>& __va)
      |     ^~~~~
In file included from /usr/include/c++/10/filesystem:46,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:129,
                 from factories.cpp:3:
/usr/include/c++/10/bits/fs_dir.h:549:3: note:   'std::filesystem::__cxx11::begin'
  549 |   begin(recursive_directory_iterator __iter) noexcept
      |   ^~~~~
factories.cpp:91:22: error: 'end' was not declared in this scope
   91 |         for(auto j : Y){
      |                      ^
factories.cpp:91:22: note: suggested alternatives:
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:95,
                 from factories.cpp:3:
/usr/include/c++/10/valarray:1244:5: note:   'std::end'
 1244 |     end(const valarray<_Tp>& __va)
      |     ^~~
In file included from /usr/include/c++/10/filesystem:46,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:129,
                 from factories.cpp:3:
/usr/include/c++/10/bits/fs_dir.h:554:3: note:   'std::filesystem::__cxx11::end'
  554 |   end(recursive_directory_iterator) noexcept
      |   ^~~
factories.cpp:97:22: error: 'begin' was not declared in this scope
   97 |         for(auto j : X) update(in[j], oo);
      |                      ^
factories.cpp:97:22: note: suggested alternatives:
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:95,
                 from factories.cpp:3:
/usr/include/c++/10/valarray:1224:5: note:   'std::begin'
 1224 |     begin(const valarray<_Tp>& __va)
      |     ^~~~~
In file included from /usr/include/c++/10/filesystem:46,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:129,
                 from factories.cpp:3:
/usr/include/c++/10/bits/fs_dir.h:549:3: note:   'std::filesystem::__cxx11::begin'
  549 |   begin(recursive_directory_iterator __iter) noexcept
      |   ^~~~~
factories.cpp:97:22: error: 'end' was not declared in this scope
   97 |         for(auto j : X) update(in[j], oo);
      |                      ^
factories.cpp:97:22: note: suggested alternatives:
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:95,
                 from factories.cpp:3:
/usr/include/c++/10/valarray:1244:5: note:   'std::end'
 1244 |     end(const valarray<_Tp>& __va)
      |     ^~~
In file included from /usr/include/c++/10/filesystem:46,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:129,
                 from factories.cpp:3:
/usr/include/c++/10/bits/fs_dir.h:554:3: note:   'std::filesystem::__cxx11::end'
  554 |   end(recursive_directory_iterator) noexcept
      |   ^~~