QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#308453 | #7181. Graph Cuts | kevinshan# | RE | 0ms | 16552kb | C++17 | 2.3kb | 2024-01-20 05:32:30 | 2024-01-20 05:32:30 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
vector<int> adj[maxn], seg[4*maxn];
set<int> res;
array<int, 2> e[maxn];
int n, m, q, ban[maxn], in[maxn], qu[maxn], ans[maxn];
map<int,int> ex;
void add(int val, int l, int r, int id = 1, int lx = 1, int rx = q)
{
if (lx > r || rx < l) return;
if (lx >= l && rx <= r) return void(seg[id].emplace_back(val));
add(val, l, r, id<<1, lx, (lx+rx)>>1);
add(val, l, r, id<<1|1, ((lx+rx)>>1) + 1, rx);
}
inline void upd(int i)
{
for (int id: adj[i]) if (!ban[id])
{
int j = e[id][0] ^ e[id][1] ^ i;
if (in[j]) res.erase(id);
else res.emplace(id);
}
in[i] = 1;
}
inline void rupd(int i)
{
for (int id: adj[i]) if (!ban[id])
{
int j = e[id][0] ^ e[id][1] ^ i;
if (in[j]) res.emplace(id);
else res.erase(id);
}
in[i] = 0;
}
void solve(int id = 1, int l = 1, int r = q)
{
for (int i: seg[id]) upd(i);
if (l == r)
{
if (qu[l])
{
ans[l] = res.size() ? *res.begin() : 0;
res.erase(ans[l]);
ban[ans[l]] = 1;
}
for (int i: seg[id]) rupd(i);
return;
}
solve(id<<1, l, (l+r)>>1);
solve(id<<1|1, ((l+r)>>1) + 1, r);
for (int i: seg[id]) rupd(i);
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
if (fopen("input.in", "r")) {
freopen("input.in", "r", stdin);
freopen("output.out", "w", stdout);
}
cin>>n>>m;
for (int i=1; i<=m; i++) cin>>e[i][0]>>e[i][1], adj[e[i][0]].emplace_back(i), adj[e[i][1]].emplace_back(i);
cin>>q;
for (int i=1; i<=q; i++)
{
char c; int x;
cin>>c;
if (c == '?') qu[i] = 1;
else
{
cin>>x;
if (!ex.count(x)) ex[x] = i;
else
{
// cout<<"ADD: "<<x<<" "<<ex[x]<<" "<<i-1<<"\n";
add(x, ex[x], i-1), ex.erase(x);
}
}
}
for (auto [u, v]: ex)
{
// cout<<"ADD: "<<u<<" "<<v<<" "<<q<<"\n";
add(u, v, q);
}
// cout<<"2\n3\n4\n5\n0\n1\n0";
solve();
for (int i=1; i<=q; i++) if (qu[i] == 1) cout<<ans[i]<<"\n";
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 16552kb
input:
4 5 1 2 1 3 1 4 2 3 2 4 10 + 1 + 2 ? ? ? ? ? - 2 ? ?
output:
2 3 4 5 0 1 0
result:
ok q=10
Test #2:
score: -100
Runtime Error
input:
0 0 0