QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#380694 | #7181. Graph Cuts | ucup-team992# | TL | 2709ms | 28408kb | C++20 | 3.2kb | 2024-04-07 08:49:05 | 2024-04-07 08:49:06 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define ar array
typedef int uci;
#define int long long
#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<ar<int, 2>> edges;
edges.push_back({});
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;
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({});
for(auto t : adj[i]){
sides[0].back().set(t.F);
}
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]){
bigadj[t.F][i] = t.S;
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]){
sides[1-state[v]][big[t.F]].flip(v);
sides[state[v]][big[t.F]].flip(v);
}
for(auto [i, c] : adj[v]){
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';
adj[edges[lsb][0]].erase(edges[lsb][1]);
adj[edges[lsb][1]].erase(edges[lsb][0]);
}else{
bool found = false;
for(auto &t : lbig){
int st = 1-state[t];
int ind = big[t];
if(sides[st][ind].count() == 0)
continue;
auto a = sides[st][ind]._Find_first();
sides[st][ind].reset(a);
if(big[a] != -1){
sides[state[t]][big[a]].reset(t);
}
cout << bigadj[t][a] << '\n';
found = true;
bigadj[a].erase(t);
bigadj[t].erase(a);
break;
}
if(!found){
cout << 0 << '\n';
}
}
}
}
}
uci main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3672kb
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: 0
Accepted
time: 0ms
memory: 3564kb
input:
0 0 0
output:
result:
ok q=0
Test #3:
score: 0
Accepted
time: 0ms
memory: 3680kb
input:
0 0 1 ?
output:
0
result:
ok q=1
Test #4:
score: 0
Accepted
time: 21ms
memory: 4020kb
input:
1000 2000 1 50 1 88 331 1 1 352 1 497 2 32 2 282 550 2 989 2 334 3 3 665 4 38 4 69 4 343 4 451 589 4 917 4 89 5 5 162 675 5 681 6 7 22 127 7 7 592 7 672 787 7 8 310 107 9 9 137 184 9 9 244 378 9 446 9 9 658 883 9 65 10 75 10 414 10 10 468 686 10 245 11 269 11 11 386 403 11 493 11 394 12 493 12 565 1...
output:
1 4 5 8 9 10 12 14 16 18 19 25 27 29 33 38 39 40 42 47 48 49 50 56 58 59 62 63 67 69 70 71 73 75 79 81 82 83 84 87 89 91 94 97 101 103 104 106 107 108 109 110 113 114 115 118 120 121 122 125 126 129 130 131 132 133 134 135 137 145 147 148 34 149 152 153 154 155 156 157 159 160 163 167 171 105 173 17...
result:
ok q=100000
Test #5:
score: 0
Accepted
time: 826ms
memory: 28408kb
input:
447 99681 2 1 1 3 4 1 1 5 1 6 1 7 1 8 9 1 10 1 1 11 1 12 1 13 1 14 1 15 1 16 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 1 1 26 27 1 28 1 1 29 30 1 31 1 1 32 33 1 1 34 1 35 36 1 37 1 38 1 39 1 40 1 1 41 1 42 43 1 44 1 45 1 46 1 1 47 48 1 49 1 1 50 1 51 1 52 53 1 54 1 55 1 1 56 57 1 1 58 59 1 60 1 1 6...
output:
6
result:
ok q=100000
Test #6:
score: 0
Accepted
time: 860ms
memory: 27064kb
input:
447 99681 1 2 3 1 4 1 5 1 1 6 7 1 8 1 9 1 10 1 11 1 1 12 13 1 14 1 15 1 1 16 1 17 18 1 19 1 1 20 21 1 22 1 23 1 24 1 1 25 26 1 27 1 28 1 1 29 1 30 31 1 32 1 1 33 1 34 35 1 1 36 37 1 38 1 1 39 40 1 41 1 42 1 43 1 1 44 45 1 46 1 47 1 48 1 49 1 50 1 1 51 1 52 1 53 1 54 1 55 56 1 1 57 58 1 1 59 1 60 61 ...
output:
70 44 110 103 88 113 85 161 171 172 21 43 5 176 40 46 47 41 18 53 3 55 11 37 69 79 82 2 94 1 4 6 7 8 9 10 12 13 14 15 16 17 19 20 24 25 26 27 28 29 30 31 32 33 34 35 36 38 45 48 49 51 52 54 57 58 59 60 61 62 63 64 65 66 67 68 71 72 73 75 77 78 81 83 86 90 91 42 92 93 95 96 102 76 105 106 109 111 118...
result:
ok q=100000
Test #7:
score: 0
Accepted
time: 1523ms
memory: 27508kb
input:
447 99681 1 2 3 1 1 4 1 5 6 1 7 1 8 1 1 9 10 1 11 1 1 12 1 13 1 14 15 1 16 1 17 1 18 1 1 19 1 20 21 1 1 22 23 1 1 24 25 1 1 26 1 27 1 28 29 1 1 30 1 31 32 1 1 33 34 1 1 35 36 1 37 1 1 38 39 1 40 1 1 41 42 1 1 43 44 1 45 1 46 1 47 1 48 1 49 1 50 1 51 1 1 52 53 1 54 1 55 1 56 1 57 1 58 1 59 1 60 1 61 ...
output:
180 25 1 91 101 107 137 13 54 57 61 71 72 78 23 40 93 37 103 124 126 138 139 145 150 151 154 160 168 8 175 102 68 158 34 77 94 118 185 159 186 106 128 26 162 172 62 90 21 184 7 20 120 188 82 92 112 33 59 130 144 152 173 174 181 189 191 161 192 193 196 205 211 45 89 142 35 153 127 163 166 212 221 222...
result:
ok q=100000
Test #8:
score: 0
Accepted
time: 2709ms
memory: 26984kb
input:
447 99681 2 1 1 3 4 1 1 5 6 1 1 7 1 8 1 9 10 1 1 11 12 1 1 13 14 1 15 1 1 16 1 17 18 1 1 19 20 1 21 1 22 1 1 23 24 1 1 25 26 1 27 1 28 1 29 1 30 1 1 31 32 1 33 1 34 1 35 1 1 36 37 1 38 1 39 1 40 1 1 41 42 1 43 1 1 44 45 1 1 46 1 47 48 1 1 49 50 1 51 1 52 1 1 53 1 54 1 55 1 56 57 1 1 58 59 1 60 1 1 6...
output:
0 84 93 27 111 120 127 141 20 151 152 177 189 191 217 220 235 240 241 292 188 264 294 309 203 290 303 330 369 30 32 99 375 379 118 169 202 259 312 320 353 414 417 29 302 378 396 428 441 342 465 156 286 472 47 155 1 2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 21 22 23 24 25 26 28 31 33 34 35 36 37 38 ...
result:
ok q=100000
Test #9:
score: -100
Time Limit Exceeded
input:
447 99681 2 1 3 1 1 4 5 1 6 1 7 1 1 8 9 1 10 1 1 11 12 1 13 1 1 14 15 1 1 16 17 1 18 1 1 19 20 1 1 21 1 22 23 1 1 24 1 25 26 1 1 27 28 1 29 1 1 30 31 1 32 1 1 33 34 1 1 35 1 36 37 1 1 38 1 39 40 1 41 1 1 42 43 1 44 1 1 45 1 46 1 47 48 1 1 49 50 1 1 51 52 1 53 1 54 1 1 55 56 1 1 57 1 58 59 1 1 60 61 ...
output:
0 0 0 0 0 0 0 0 81 102 379 526 547 364 378 809 823 824 970 138 184 191 583 629 288 322 636 393 733 767 281 726 838 991 416 95 540 861 984 1027 1073 1080 371 237 437 682 816 882 1126 166 308 43 101 131 211 111 301 339 404 488 546 310 255 556 576 611 656 90 436 535 267 700 258 703 712 746 753 319 755 ...