QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#366615 | #7181. Graph Cuts | Giga_Cronos# | RE | 1ms | 3596kb | C++20 | 4.4kb | 2024-03-25 05:55:47 | 2024-03-25 05:55:47 |
Judging History
answer
///Giga_Cronos Template from UH Top
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops", "omit-frame-pointer", "inline")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx,avx2,fma,tune=native")
#pragma GCC option("arch=native", "no-zero-upper") // Enable AVX
using namespace std;
///Macros
#define int long long
#define pb push_back
#define fs first
#define sc second
#define pf push_front
#define all(x) x.begin() , x.end()
#define rall(x) x.rbegin() , x.rend()
#define sz(x) (int)(x.size())
#define mid ((L+R)/2)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector< pii > vpii;
typedef vector<vi> vvi;
typedef vector<vpii> vvpii;
typedef pair<vi,vi> pvv;
typedef __int128_t int128;
typedef long double ld;
typedef unsigned long long ull;
typedef unsigned int ui;
///Constraints:
const int inf = ((1ll<<31ll)-1ll);
const long long INF = (((1ll<<60ll)-1ll)*2ll)+1ll;
const ull mod=998244353;
const ld pi = acos(-1);
const ld eps=1e-8;
/// Functions:
#define lg2(x) 31 - __builtin_clz(x)
#define lg2ll(x) 63ll - __builtin_clzll(x)
#define lgx(x,b) ( log(x) / log(b) )
/*#include<ext/pb_ds/assoc_container.hpp> // Common file
#include<ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
//comenta el define long long int
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// find_by_order
// order_of_key */
mt19937_64 rnd(chrono::steady_clock::now().time_since_epoch().count());
/// Quick Pow------------------------------------------------
int qpow(int a, int b) {
int res = 1;
for (; b; b /= 2, a = (a*a)%mod) {
if (b % 2) {
res =(res*a)%mod;
}
}
return res;
}
int qpow(int a, int b,int mod) {
int res = 1;
for (; b; b /= 2, a = (a*a)%mod) {
if (b % 2) {
res =(res*a)%mod;
}
}
return res;
}
///Inverso Modular
int InverM(int a,int b)
{
int eso=a%b;
if(eso==0)
return 0;
int ans=(1-(int128)b*InverM(b,eso))/eso;
if(ans<0)
ans+=b;
return ans;
}
const int MAXN=200'005;
/// Variables-----------------------------------------------
int n,m,q,k;
vector<vector<pair<int,bitset<320>>>> Bis;
vector<bitset<320>> Edges;
vvi NodE;
vpii Ed;
void Add(int u){
for(auto &p:Bis[u]){
Edges[p.fs]^=p.sc;
}
}
int Find(){
int aris=-1;
for(int i=0;i<k;i++){
if(Edges[i].any()){
for(int j=0;j<320;j++){
if(Edges[i][j]){
aris=i*320+j;
Edges[i][j]=0;
break;
}
}
break;
}
}
if(aris==-1)return -1;
for(auto &p:Bis[Ed[aris].fs]){
if(p.fs==aris/320){
p.sc[aris%320]=0;
break;
}
}
for(auto &p:Bis[Ed[aris].sc]){
if(p.fs==aris/320){
p.sc[aris%320]=0;
break;
}
}
return aris;
}
void problem()
{
cin>>n>>m;
k=(m+319)/320;
Bis.assign(n,vector<pair<int,bitset<320>>>());
Edges.assign(k,bitset<320>());
NodE.assign(n,vi());
for(int i=0;i<m;i++){
int a,b;
cin>>a>>b;a--,b--;
NodE[a].pb(i);
NodE[b].pb(i);
Ed.pb({a,b});
}
bitset<320> F;
for(int i=0;i<n;i++){
int cur=0;
int flag=320;
for(int j=0 ,flag=320;j<k;j++,flag+=320){
bool ok=false;
while(cur<sz(NodE[i]) && NodE[i][cur]<flag){
F[NodE[i][cur]-j*k]=1;
ok=true;
cur++;
}
if(ok){
Bis[i].push_back({j,F});
F.reset();
}
}
}
cin>>q;
while(q--){
int u;
char c;cin>>c;
if(c=='?'){
int d=Find();
d++;
cout<<d<<'\n';
}else{
cin>>u;
u--;
Add(u);
}
}
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.setf(ios::fixed);
cout.precision(12);
// freopen("a.in","r",stdin);
// freopen("a.out","w",stdout);
int tc=1;
//cin>>tc;
while(tc--)
{
problem();
cout<<'\n';
}
}
///Tips
//Busqueda Binaria
//Precomputing
//Dinamic Programming
//Revisar constraints
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3560kb
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: 1ms
memory: 3532kb
input:
0 0 0
output:
result:
ok q=0
Test #3:
score: 0
Accepted
time: 1ms
memory: 3596kb
input:
0 0 1 ?
output:
0
result:
ok q=1
Test #4:
score: -100
Runtime Error
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...