QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#387866#8544. Colorful Graph 2ucup-team027#Compile Error//C++233.7kb2024-04-12 22:10:352024-04-12 22:10:36

Judging History

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

  • [2024-04-12 22:10:36]
  • 评测
  • [2024-04-12 22:10:35]
  • 提交

answer

#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,fma,popcnt")
#include <bits/stdc++.h>
using namespace std;

namespace std {
	template<>
	struct hash<pair<int, int>> {
	public:
		size_t operator() (const pair<int, int> &x) const {
			return 998244353LL * x.first + x.second;
		}
	};
}

inline char gc() { // like getchar()
	static char buf[1 << 16];
	static size_t bc, be;
	if (bc >= be) {
		buf[0] = 0, bc = 0;
		be = fread(buf, 1, sizeof(buf), stdin);
	}
	return buf[bc++]; // returns 0 on EOF
}

int readInt() {
	int a, c;
	while ((a = gc()) < 40);
	if (a == '-') return -readInt();
	while ((c = gc()) >= 48) a = a * 10 + c - 480;
	return a - 48;
}

void solve() {
    int n = readInt(), m = readInt();
    vector<vector<int>> g(n);
    unordered_set<pair<int, int>> edges;
    for (int i = 0; i < m; i++) {
        int x = readInt(), y = readInt();
        g[x].push_back(y);
        g[y].push_back(x);
        edges.insert({x, y});
        edges.insert({y, x});
    }
    for (int i = 0; i < n; i++) {
        g[i].push_back((i+1) % n);
    }

    unordered_map<pair<int, int>, int> nxt;
    for (int piv = 0; piv < n; piv++) {
        sort(g[piv].begin(), g[piv].end(), [&](int x, int y){
            if (x < piv && y < piv) return x < y;
            if (x > piv && y > piv) return x < y;
            if (x > piv) return true;
            return false;
        });

        for (int i = 1; i < g[piv].size(); i++) {
            nxt[{g[piv][i-1], piv}] = g[piv][i];
        }
        nxt[{g[piv].back(), piv}] = (piv-1+n) % n;
    }

    /*
    for (auto [p, nn]: nxt) {
        cout << p.first << ' ' << p.second << ' ' << nn << '\n';
    }
    */
    
    vector<vector<int>> pols;
    unordered_set<pair<int, int>> vis;
    for (auto [pp, nxx]: nxt) {
        auto [x, y] = pp;
        if (vis.count({x, y})) continue;
        
        vector<int> pol; pol.push_back(x);
        int curx = x, cury = y;
        while (!vis.count({curx, cury})) {
            vis.insert({curx, cury});
            pol.push_back(cury);
            int nx = nxt[{curx, cury}];
            curx = cury;
            cury = nx;
        }

        /*
        cout << "POLYGON\n";
        for (int i: pol) cout << i << ' ';
        cout << '\n';
        */

        pols.push_back(pol);
    }

    map<pair<int, int>, vector<int>> mpe;
    for (int j = 0; j < pols.size(); j++) {
        auto &pol = pols[j];
        for (int i = 1; i < pol.size(); i++) {
            int x = pol[i], y = pol[i-1];
            if (x > y) swap(x, y);
            if (edges.count({x, y})) {
                mpe[{x, y}].push_back(j);
            }
        }
    }

    int sz = pols.size();
    vector<vector<int>> g2(sz);
    for (auto [pp, ed]: mpe) {
        g2[ed[0]].push_back(ed[1]);
        g2[ed[1]].push_back(ed[0]);
    }

    vector<int> ans(n, -1);
    stack<int> st;
    st.push(0);
    vector<int> vis2(sz);
    while (st.size()) {
        int u = st.top(); st.pop();
        vis2[u] = 1;

        int has0 = 0, has1 = 0;
        for (int i: pols[u]) {
            if (ans[i] == 0) has0 = 1;
            if (ans[i] == 1) has1 = 1;
        }

        int col;
        if (has0 == 0) col = 0;
        else col = 1;

        for (int i: pols[u]) {
            if (ans[i] != -1) continue;
            ans[i] = col;
            col ^= 1;
        }

        for (int v: g2[u]) {
            if (vis2[v]) continue;
            st.push(v); 
        }
    }

    for (int i: ans) if (i) cout << "R"; else cout << "B";
    cout << '\n';
}

signed main(){
    ios::sync_with_stdio(0), cin.tie(0);
    
    int t = readInt();
    while (t--) {
        solve();
    }
}

Details

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:3:
/usr/include/c++/13/bits/allocator.h: In destructor ‘constexpr 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’ ‘constexpr 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/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:53:
/usr/include/c++/13/bits/stl_vector.h:133:14: note: called from here
  133 |       struct _Vector_impl
      |              ^~~~~~~~~~~~