QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#423347 | #8109. Postcards | _qwqUwU | WA | 262ms | 42584kb | C++20 | 2.9kb | 2024-05-27 22:30:19 | 2024-05-27 22:30:21 |
Judging History
answer
#include<bits/stdc++.h>
#define pb push_back
#define P make_pair
#define fi first
#define se second
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define bit(s,x) (((s)>>(x))&1)
#define pnp(s) __builtin_popcount(s)
#define lb(x) (x&-x)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
inline ll read(){
ll x=0,f=1,c=getchar();
while(c<'0'||c>'9')f=(c=='-'?-1:1),c=getchar();
while(c>='0' && c<='9')x=x*10 + c-'0',c=getchar();
return x*f;
}
const int N=3002;
const int K=101;
const int M=5e5+3;
int n,m;
bitset<K>to[K];
int U[M],V[M],G[N][N],anc[N],dfn[N],siz[N],dep[N],tim;
inline void dfs1(int u){
dfn[u]=++tim;siz[u]=1;
rep(i,1,n)if(!dfn[i] && G[u][i]){
dep[i] = dep[u]+1; anc[i]=u;
dfs1(i);siz[u] += siz[i];
}
}
inline bool in(int u,int v){return dfn[u]<=dfn[v] && dfn[v]<dfn[u]+siz[u];}
inline void dfs2(int u,int op){
rep(i,1,n)if(anc[i] == u){
dfs2(i,op);
if(!op)rep(j,1,n)G[u][j] += G[i][j];
else rep(j,1,n)G[j][u] += G[j][i];
}
}
int main(){
//freopen("data.in","r",stdin);
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
n=read(),m=read();int QQ=read();
rep(i,1,m){
U[i]=read(),V[i]=read();
++G[U[i]][V[i]];
++G[V[i]][U[i]];
}
dfs1(1);dfs2(1,0),dfs2(1,1);
int lst=0;
while(QQ--){
int R=read();
vector<int>vec(1,1);
static int a[K],b[K],c[K];
rep(i,1,R){
int x=c[i]=(read()+lst)%m+1;
a[i]=read(),b[i]=read();
if(dep[U[x]] > dep[V[x]])swap(U[x],V[x]),swap(a[i],b[i]);
if(anc[V[x]] == U[x])vec.pb(V[x]);
}
sort(vec.begin(),vec.end(),[&](int x,int y){return dep[x]<dep[y];});
static int id[N];rep(i,0,vec.size()-1)id[vec[i]]=i;
auto get = [&](int v){
int res=1;
for(auto u:vec)if(in(u,v) && dep[res] < dep[u])res=u;
return id[res];
};
static int w[K][K];
const int N=vec.size()-1;
rep(i,0,N)rep(j,0,N)w[i][j]=0;
static int sz[K];
rep(i,0,N)sz[i]=siz[vec[i]];
per(i,N,0)rep(j,i+1,N)if(in(vec[i],vec[j]))sz[i]-=sz[j];
//rep(i,0,N)tmp[i]=get(anc[vec[i]]);
static vector<int>F[K];
rep(i,0,N)F[i].clear();
rep(i,1,N)F[get(anc[vec[i]])].pb(vec[i]);
rep(i,0,N)rep(j,0,N){
w[i][j]=G[vec[i]][vec[j]];
for(auto x:F[j])w[i][j]-=G[vec[i]][x];
for(auto x:F[i])w[i][j]-=G[x][vec[j]];
for(auto x:F[i])for(auto y:F[j])w[i][j]+=G[x][y];
}
rep(i,1,R){
int u=get(U[c[i]]),v=get(V[c[i]]);
if(a[i])--w[u][v];
if(b[i])--w[v][u];
}
rep(i,0,N) to[i].reset(),to[i].set(i);
rep(i,0,N)rep(j,0,N)assert(w[i][j]>=0);
rep(i,0,N)rep(j,0,N)if(w[i][j])to[j].set(i);
rep(i,1,R){
int u=get(U[c[i]]),v=get(V[c[i]]);
if(!a[i])to[v].set(u);
if(!b[i])to[u].set(v);
}
rep(k,0,N)rep(i,0,N)if(to[i][k])to[i] |= to[k];
int ans=0;
rep(i,0,N)if(to[i].count() == N+1)ans += sz[i];
printf("%d\n",ans);lst+=ans;
}
return 0;
}
/*
4 4 3
1 2
4 3
2 3
1 3
2
3 1 1
1 0 1
3
1 1 0
0 1 0
3 1 0
1
1 1 1
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 8188kb
input:
4 4 3 1 2 4 3 2 3 1 3 2 3 1 1 1 0 1 3 1 1 0 0 1 0 3 1 0 1 1 1 1
output:
3 1 0
result:
ok 3 number(s): "3 1 0"
Test #2:
score: -100
Wrong Answer
time: 262ms
memory: 42584kb
input:
3000 11860 5000 135 1279 1379 1627 1253 2516 338 1596 260 1086 1153 2182 527 732 500 2820 1395 1556 793 1491 2673 2746 1630 1792 1720 2871 443 2095 1095 1296 2008 2358 1685 1801 2356 2704 1856 2698 1798 2134 1683 1792 812 2977 43 1507 1297 1574 222 1563 1278 2168 1181 1851 1492 2757 432 1459 428 902...
output:
3000 3000 3000 3000 3000 3000 3000 3000 3000 3000 3000 3000 3000 3000 3000 2999 3000 3000 3000 3000 3000 3000 3000 3000 3000 3000 3000 3000 3000 3000 3000 3000 3000 3000 3000 3000 3000 3000 3000 3000 3000 3000 3000 3000 3000 3000 3000 3000 3000 3000 3000 3000 3000 3000 3000 3000 3000 3000 3000 3000 ...
result:
wrong answer 353rd numbers differ - expected: '1', found: '2999'