QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#380708#7181. Graph Cutsucup-team992#RE 0ms0kbC++203.8kb2024-04-07 09:08:522024-04-07 09:08:54

Judging History

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

  • [2024-04-07 09:08:54]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-04-07 09:08:52]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define F first
#define S second
#define ar array
typedef int uci;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

void solve(){
    int n, m;
    cin >> n >> m;

    vector<int> deg(n);
    vector<int> lbig;
    vector<int> big(n, -1);
    vector<int> state(n);
    vector<vector<bitset<100000>>> sides(2);
    vector<unordered_map<int, int>> adj(n);
    vector<bitset<100000>> bitadj(n);
    vector<ar<int, 2>> edges;
    edges.push_back({});
    vector<vector<int>> sizes(2);
    for(int i{}; i < m; ++i){
        int u, v;
        cin >> u >> v;
        u--, v--;

        edges.push_back({u, v});
        adj[u][v] = i+1;
        adj[v][u] = i+1;
        bitadj[u].set(v);
        bitadj[v].set(u);
        deg[u]++, deg[v]++;
    }

    int sq = sqrt(n);
    for(int i{}; i < n; ++i){
        if(deg[i] >= sq){
            big[i] = sides[0].size();
            lbig.push_back(i);
            sides[0].push_back({});
            sizes[0].push_back(0);
            for(auto t : adj[i]){
                sides[0].back().set(t.F);
                sizes[0].back()++;
            }
            sizes[1].push_back(0);
            sides[1].push_back({});
        }
    }

    int q;
    cin >> q;

    vector<unordered_map<int, int>> bigadj(n);
    for(int i : lbig){
        vector<int> te;
        for(auto &t : adj[i]){
            if(big[t.F] == -1)
                bigadj[t.F][i] = t.S;
            if(big[i] == -1)
                bigadj[i][t.F] = t.S;
            te.push_back(t.F);
        }
        for(auto &t : te){
            adj[t].erase(i);
            adj[i].erase(t);
        }
    }


    bitset<100001> gv{};
    for(int i{}; i < q; ++i){
        char c;
        cin >> c;
        if(c == '+' || c == '-'){
            int v;
            cin >> v;
            v--;

            state[v] = 1-state[v];
                for(auto &t : bigadj[v]){
                    if(bitadj[v][t.F] && big[t.F] != -1){
                        sizes[1-state[v]][big[t.F]]--;
                        sides[1-state[v]][big[t.F]].flip(v);
                        sizes[state[v]][big[t.F]]++;
                        sides[state[v]][big[t.F]].flip(v);
                    }
                }
            for(auto [i, c] : adj[v]){
                if(!bitadj[v][i])
                    continue;
                if(state[i] != state[v]){
                    gv.set(c);
                }else{
                    gv.reset(c);
                }
            }
        }else{
            int lsb = gv._Find_first();
            if(lsb != 100001){
                gv.reset(lsb);
                cout << lsb << '\n';
                bitadj[edges[lsb][0]].reset(edges[lsb][1]);
                bitadj[edges[lsb][1]].reset(edges[lsb][0]);
            }else{
                bool found = false;
                for(auto &t : lbig){
                    int st = 1-state[t];
                    int ind = big[t];
                    if(sizes[st][ind] == 0)
                        continue;
                    int a = sides[st][ind]._Find_first();
                    sides[st][ind].reset(a);
                    sizes[st][ind]--;
                    if(big[a] != -1){
                        sides[state[t]][big[a]].reset(t);
                        sizes[state[t]][big[a]]--;
                    }
                    
                    cout << bigadj[t][a] << '\n';
                    found = true;
                    bitadj[a].reset(t);
                    bitadj[t].reset(a);
                    break;
                }
                if(!found){
                    cout << 0 << '\n';
                }
            }
        }
    }
}

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

    solve();
}

详细

Test #1:

score: 0
Runtime Error

input:

4 5
1 2
1 3
1 4
2 3
2 4
10
+ 1
+ 2
?
?
?
?
?
- 2
?
?

output:


result: