QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#423365 | #8109. Postcards | CharlieVinnie | RE | 0ms | 3896kb | C++20 | 3.7kb | 2024-05-27 22:50:50 | 2024-05-27 22:50:51 |
Judging History
answer
#include "bits/stdc++.h"
#ifdef DEBUG
#include "PrettyDebug.hpp"
#else
#define debug(...) [](){}()
#define debuga(...) [](){}()
#endif
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Rev(i,a,b) for(int i=a;i>=b;i--)
#define Fin(file) freopen(file,"r",stdin)
#define Fout(file) freopen(file,"w",stdout)
using namespace std; typedef long long ll;
constexpr int N=3e3+5; using pii = pair<int,int>;
int n,m,Q,a[N],b[N],fa[N],id[N],siz[N],pos[N],pcnt,ped[N],raw[N],G[N][N],dfn[N],low[N],dfscnt,st[N],tp,ins[N],cp[N],cpcnt; vector<pii> to[N]; vector<int> ed[N];
void dfs0(int u){
raw[pos[u]=++pcnt]=u; siz[u]=1; for(auto [v,e]:to[u]) if(!pos[v]) fa[v]=u,id[v]=e,dfs0(v),siz[u]+=siz[v];;; ped[u]=pcnt;
}
int Sum(int u,int v) { return G[ped[u]][ped[v]]-G[ped[u]][pos[v]-1]-G[pos[u]-1][ped[v]]+G[pos[u]-1][pos[v]-1]; }
void tarjan(int u){
dfn[u]=low[u]=++dfscnt; ins[st[++tp]=u]=1;
for(int v:ed[u]){
if(!dfn[v]) tarjan(v),low[u]=min(low[u],low[v]);
else if(ins[v]) low[u]=min(low[u],dfn[v]);
}
if(low[u]==dfn[u]){
int z; cpcnt++; do ins[z=st[tp--]]=0,cp[z]=cpcnt; while(z!=u);
}
}
signed main(){
atexit([](){cerr<<"Time = "<<clock()<<" ms"<<endl;});
ios::sync_with_stdio(0); cin.tie(0);
cin>>n>>m>>Q; For(i,1,m) { int x,y; cin>>x>>y; to[x].emplace_back(y,i); to[y].emplace_back(x,i); a[i]=x; b[i]=y; }
dfs0(1); debuga(fa,1,n); debuga(id,1,n);
For(u,1,n) for(auto [v,_]:to[u]) G[pos[u]][pos[v]]++;
For(i,1,n) For(j,1,n) G[i][j]+=G[i-1][j]+G[i][j-1]-G[i-1][j-1];
int Ans=0;
while(Q--){
int K,ans=0; cin>>K; int E[105]={0},ban[105][2]={0}; For(i,1,K) cin>>E[i]>>ban[i][0]>>ban[i][1],E[i]=(E[i]+Ans)%m+1;
int lis[105]={0},lcnt=0; lis[++lcnt]=1;
For(i,1,K) { int x=a[E[i]],y=b[E[i]]; if(id[x]==E[i]) lis[++lcnt]=x; else if(id[y]==E[i]) lis[++lcnt]=y; }
For(i,1,lcnt) ed[i].clear();
auto calc=[&](int u){
int res=0;
For(i,1,lcnt){
if(pos[lis[i]]<=pos[u]&&pos[u]<=ped[lis[i]]){
if(res==0||pos[lis[i]]>pos[lis[res]]) res=i;
}
}
assert(res); return res;
};
static int tmp[105][105]; vector<int> son[105];
For(i,1,lcnt) son[i].clear();
For(i,2,lcnt) son[calc(fa[lis[i]])].push_back(i);
For(i,1,lcnt) For(j,i+1,lcnt){
int res=Sum(lis[i],lis[j]);
for(int u:son[i]) res-=Sum(lis[u],lis[j]);
for(int v:son[j]) res-=Sum(lis[i],lis[v]);
for(int u:son[i]) for(int v:son[j]) res+=Sum(lis[u],lis[v]);
tmp[i][j]=res;
}
For(i,1,lcnt) ed[i].clear();
For(i,1,K){
int x=calc(a[E[i]]),y=calc(b[E[i]]);
if(!ban[i][0]) ed[x].push_back(y);
if(!ban[i][1]) ed[y].push_back(x);
tmp[min(x,y)][max(x,y)]--;
}
For(i,1,lcnt) For(j,i+1,lcnt){
assert(tmp[i][j]>=0);
if(tmp[i][j]>0) ed[i].push_back(j),ed[j].push_back(i);
}
dfscnt=tp=cpcnt=0; For(i,1,lcnt) dfn[i]=ins[i]=0;
For(u,1,lcnt) if(!dfn[u]) tarjan(u);
int Out[105]={0}; For(u,1,lcnt) for(int v:ed[u]) if(cp[u]!=cp[v]) Out[cp[u]]=1;
int O=0; For(i,1,cpcnt) if(!Out[i]) { if(O==0) O=i; else { O=-1; break; } }
if(O!=-1){
For(u,1,lcnt) if(cp[u]==O){
ans+=siz[lis[u]]; for(int v:son[u]) ans-=siz[lis[v]];
}
}
cout<<ans<<'\n';
Ans=(Ans+ans)%m;
}
return 0;
}
// CONTINUE, NON-STOPPING, FOR CHARLIEY
// START TYPING IF YOU DON'T KNOW WHAT TO DO
// STOP TYPING IF YOU DON'T KNOW WHAT YOU'RE DOING
// Started Coding On: May 27 Mon, 21 : 46 : 01
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3896kb
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
Runtime Error
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...