QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#120448#3550. Hoof and Brainpandapythoner#Compile Error//C++145.1kb2023-07-06 18:19:062024-05-31 14:21:52

Judging History

你现在查看的是最新测评结果

  • [2024-05-31 14:21:52]
  • 评测
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-06 18:19:06]
  • 提交

answer

#ifndef LOCAL
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,fma")
#endif


#include <bits/stdc++.h>


using namespace std;


#define ll long long
#define flt double
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()


mt19937 rnd(1243);


#ifdef LOCAL
bool local = true;
#else
bool local = false;
#endif

int n, m;
vector<vector<int>> g;
vector<vector<int>> rg;
int q;
vector<pair<int, int>> asks;
vector<int> rs;
vector<int> in_cycle;
int usdc;
vector<int> usd;
int bndc;
vector<int> bnd;
vector<vector<int>> gd_pr, usd_pr;
vector<vector<int>> su, sv;

/*
void dfs(int v){
    int good = false;
    usd[v] = usdc - 1;
    for(auto to: g[v]){
        if(bnd[to] == bndc){
            continue;
        }
        if(usd[to] == usdc - 1){
            good = true;
        } else if(usd[to] == usdc) {
            if(in_cycle[to]){
                good = true;
            }
        } else{
            dfs(to);
            if(in_cycle[to]){
                good = true;
            }
        }
    }
    usd[v] = usdc;
    in_cycle[v] = good;
}
*/

void dfs1(int u, int v){
    if(u > v){
        // swap(u, v);
    }
    if(usd_pr[u][v] != 0){
        return;
    }
    usd_pr[u][v] = 1;
    if(u == v){
        usd_pr[u][v] = 2;
        gd_pr[u][v] = 0;
        return;
    }
    bool gdu = false;
    bool gdv = false;
    for(auto to: g[u]){
        int nu = to;
        auto nv = v;
        if(nu > nv){
            swap(nu, nv);
        }
        if(usd_pr[nu][nv] == 1){
            gdu = true;
            break;
        } else if(usd_pr[nu][nv] == 2){
            if(gd_pr[nu][nv]){
                gdu = true;
                break;
            }
        } else{
            dfs1(nu, nv);
            if(gd_pr[nu][nv]){
                gdu = true;
                break;
            }
        }
    }
    if(gdu){
        for(auto to: g[v]){
            auto nu = u;
            auto nv = to;
            if(nu > nv){
                swap(nu, nv);
            }
            if(usd_pr[nu][nv] == 1){
                gdv = true;
                break;
            } else if(usd_pr[nu][nv] == 2){
                if(gd_pr[nu][nv]){
                    gdv = true;
                    break;
                }
            } else{
                dfs1(nu, nv);
                if(gd_pr[nu][nv]){
                    gdv = true;
                    break;
                }
            }
        }
    }
    gd_pr[u][v] = (gdu && gdv);
    usd_pr[u][v] = 2;
}

void solve_fuck(){
    usd.assign(n, 0);
    usdc = 10;
    bnd.assign(n, 0);
    bndc = 10;
    gd_pr.assign(n, vector<int>(n, 1));
    su.assign(n, vector<int>(n));
    sv.assign(n, vector<int>(n));
    queue<pair<int, int>> hp;
    for(int u = 0; u < n; u += 1){
        for(int v = 0; v < n; v += 1){
            su[u][v] = g[u].size();
            sv[u][v] = g[v].size();
            if(u == v || g[u].empty() || g[v].empty()){
                gd_pr[u][v] = 0;
                hp.push(make_pair(u, v));
            }
        }
    }
    while(!hp.empty()){
        auto [u, v] = hp.front();
        hp.pop();
        for(auto to: rg[u]){
            su[to][v] -= 1;
            if(gd_pr[to][v] == 1 && su[to][v] == 0){
                gd_pr[to][v] = 0;
                hp.push(make_pair(to, v));
            }
        }
        for(auto to: rg[v]){
            sv[u][to] -= 1;
            if(gd_pr[u][to] == 1 && sv[u][to] == 0){
                gd_pr[u][to] = 0;
                hp.push(make_pair(u, to));
            }
        }
    }
    /*
    for(int u = 0; u < n; u += 1){
        for(int v = 0; v < n; v += 1){
            if(usd_pr[u][v] == 0){
                dfs1(u, v);
            }
        }
    }
    */
    rs.resize(q);
    for(int i = 0; i < q; i += 1){
        auto [u, v] = asks[i];
        if(u > v){
            swap(u, v);
        }
        if(gd_pr[u][v]){
            rs[i] = 0;
        } else{
            rs[i] = 1;
        }
    }
}


int32_t main(){
    if(!local){
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
    }
    ll t = 1;
    if(local){
        t = 1e6;
    }
    while(t--){
        cin >> n >> m;
        g.assign(n, vector<int>());
        rg.assign(n, vector<int>());
        for(int i = 0; i < m; i += 1){
            int u, v;
            cin >> u >> v;
            --u;
            --v;
            g[u].push_back(v);
            rg[v].push_back(u);
        }
        for(int v = 0; v < n; v += 1){
            shuffle(all(g[v]), rnd);
        }
        cin >> q;
        asks.resize(q);
        for(int i = 0; i < q; i += 1){
            int a, b;
            cin >> a >> b;
            --a;
            --b;
            asks[i] = make_pair(a, b);
        }
        solve_fuck();
        for(int i = 0; i < q; i += 1){
            if(rs[i] == 0){
                cout << 'H';
            } else{
                cout << 'B';
            }
        }
        cout << "\n";
    }
    return 0;
}

Details

answer.code: In function ‘void solve_fuck()’:
answer.code:153:14: warning: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
  153 |         auto [u, v] = hp.front();
      |              ^
answer.code:181:14: warning: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
  181 |         auto [u, v] = asks[i];
      |              ^
In file included from /usr/include/c++/13/string:43,
                 from /usr/include/c++/13/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:52,
                 from answer.code:7:
/usr/include/c++/13/bits/allocator.h: In destructor ‘std::_Vector_base<std::vector<int>, std::allocator<std::vector<int> > >::_Vector_impl::~_Vector_impl()’:
/usr/include/c++/13/bits/allocator.h:184:7: error: inlining failed in call to ‘always_inline’ ‘std::allocator< <template-parameter-1-1> >::~allocator() noexcept [with _Tp = std::vector<int>]’: target specific option mismatch
  184 |       ~allocator() _GLIBCXX_NOTHROW { }
      |       ^
In file included from /usr/include/c++/13/vector:66,
                 from /usr/include/c++/13/queue:63,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:157:
/usr/include/c++/13/bits/stl_vector.h:133:14: note: called from here
  133 |       struct _Vector_impl
      |              ^~~~~~~~~~~~