QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#425009 | #8109. Postcards | AFewSuns | WA | 134ms | 76032kb | C++20 | 4.6kb | 2024-05-29 21:15:00 | 2024-05-29 21:15:00 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
namespace my_std{
#define ll long long
#define bl bool
ll my_pow(ll a,ll b,ll mod){
ll res=1;
if(!b) return 1;
while(b){
if(b&1) res=(res*a)%mod;
a=(a*a)%mod;
b>>=1;
}
return res;
}
ll qpow(ll a,ll b){
ll res=1;
if(!b) return 1;
while(b){
if(b&1) res*=a;
a*=a;
b>>=1;
}
return res;
}
#define db double
#define pf printf
#define pc putchar
#define fr(i,x,y) for(register ll i=(x);i<=(y);i++)
#define pfr(i,x,y) for(register ll i=(x);i>=(y);i--)
#define go(u) for(ll i=head[u];i;i=e[i].nxt)
#define enter pc('\n')
#define space pc(' ')
#define fir first
#define sec second
#define MP make_pair
#define il inline
#define inf 8e18
#define random(x) rand()*rand()%(x)
#define inv(a,mod) my_pow((a),(mod-2),(mod))
il ll read(){
ll sum=0,f=1;
char ch=0;
while(!isdigit(ch)){
if(ch=='-') f=-1;
ch=getchar();
}
while(isdigit(ch)){
sum=sum*10+(ch^48);
ch=getchar();
}
return sum*f;
}
il void write(ll x){
if(x<0){
x=-x;
pc('-');
}
if(x>9) write(x/10);
pc(x%10+'0');
}
il void writeln(ll x){
write(x);
enter;
}
il void writesp(ll x){
write(x);
space;
}
}
using namespace my_std;
vector<pair<ll,ll> > vec[3030];
vector<ll> e[110];
ll n,m,q,siz[3030],dfn[3030],st[3030],ed[3030],tot=0;
ll sum[3030][3030],a[110][3],b[110],num=0,lstans=0;
ll mp[3030],sta[110],top=0,Fa[3030],ecnt[110][110];
ll sizz[110],dfnn[110],low[110],tott=0,blg[110],cntt=0,d[110];
bl ck[3030],pd[500050],vis[110];
struct node{
ll u,v;
}E[500050];
void dfs(ll fa,ll u){
ck[u]=1;
dfn[++tot]=u;
st[u]=tot;
siz[u]=1;
fr(i,0,(ll)vec[u].size()-1){
ll v=vec[u][i].fir,id=vec[u][i].sec;
if(!ck[v]){
pd[id]=1;
dfs(u,v);
siz[u]+=siz[v];
}
}
ed[u]=tot;
}
il bl cmp(ll x,ll y){
return st[x]<st[y];
}
il ll calc(ll l1,ll r1,ll l2,ll r2){
return sum[r1][r2]-sum[l1-1][r2]-sum[r2][l2-1]+sum[l1-1][l2-1];
}
il ll query(ll x){
pfr(i,num,1) if(st[b[i]]<=st[x]&&st[x]<=ed[b[i]]) return i;
return 0;
}
void tarjan(ll u){
dfnn[u]=low[u]=++tott;
vis[u]=1;
sta[++top]=u;
fr(i,0,(ll)e[u].size()-1){
ll v=e[u][i];
if(!dfnn[v]){
tarjan(v);
low[u]=min(low[u],low[v]);
}
else if(vis[u]) low[u]=min(low[u],dfn[v]);
}
if(dfnn[u]==low[u]){
blg[u]=++cntt;
vis[u]=0;
while(sta[top]!=u){
blg[sta[top]]=cntt;
vis[sta[top]]=0;
top--;
}
top--;
}
}
il void clr(){
fr(i,1,num) e[i].clear();
fr(i,1,num) mp[b[i]]=Fa[b[i]]=sizz[i]=dfnn[i]=low[i]=blg[i]=d[i]=vis[i]=0;
fr(i,1,num) fr(j,1,num) ecnt[i][j]=0;
num=top=tott=cntt=0;
}
int main(){
n=read();
m=read();
q=read();
fr(i,1,m){
E[i].u=read();
E[i].v=read();
vec[E[i].u].push_back(MP(E[i].v,i));
vec[E[i].v].push_back(MP(E[i].u,i));
}
dfs(0,1);
fr(i,1,m){
if(pd[i]) continue;
sum[st[E[i].u]][st[E[i].v]]++;
sum[st[E[i].v]][st[E[i].u]]++;
}
fr(i,1,n) fr(j,1,n) sum[i][j]+=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1];
while(q--){
ll r=read();
fr(i,1,r){
a[i][0]=(read()+lstans)%m+1;
a[i][1]=read();
a[i][2]=read();
if(pd[a[i][0]]){
if(st[E[a[i][0]].u]<st[E[a[i][0]].v]) b[++num]=E[a[i][0]].v;
else b[++num]=E[a[i][0]].u;
}
}
b[++num]=1;
sort(b+1,b+num+1,cmp);
fr(i,1,num) mp[b[i]]=i;
sta[++top]=b[1];
fr(i,2,num){
while(top&&ed[sta[top]]<st[b[i]]) top--;
Fa[b[i]]=sta[top];
sta[++top]=b[i];
}
fr(i,1,num){
fr(j,1,num){
ll tmp=calc(st[b[i]],ed[b[i]],st[b[j]],ed[b[j]]);
ecnt[i][j]+=tmp;
if(Fa[b[i]]) ecnt[mp[Fa[b[i]]]][j]-=tmp;
if(Fa[b[j]]) ecnt[i][mp[Fa[b[j]]]]-=tmp;
if(Fa[b[i]]&&Fa[b[j]]) ecnt[mp[Fa[b[i]]]][mp[Fa[b[j]]]]+=tmp;
}
}
fr(i,1,num){
sizz[i]=siz[b[i]];
if(Fa[b[i]]) sizz[mp[Fa[b[i]]]]-=siz[b[i]];
}
fr(i,1,r){
if(pd[a[i][0]]){
ll u=query(E[a[i][0]].u),v=query(E[a[i][0]].v);
ecnt[u][v]+=(!a[i][1]);
ecnt[v][u]+=(!a[i][2]);
}
else{
ll u=query(E[a[i][0]].u),v=query(E[a[i][0]].v);
ecnt[u][v]-=a[i][1];
ecnt[v][u]-=a[i][2];
}
}
fr(i,1,num) fr(j,1,num) if(i!=j&&ecnt[i][j]) e[i].push_back(j);
top=0;
fr(i,1,num) if(!dfnn[i]) tarjan(i);
fr(i,1,num) fr(j,0,(ll)e[i].size()-1) if(blg[i]!=blg[e[i][j]]) d[i]++;
ll tmp=0;
fr(i,1,num){
if(d[i]) continue;
if(!tmp) tmp=i;
else tmp=-1;
}
if(tmp==-1) writeln(0);
else{
ll ans=0;
fr(i,1,num) if(blg[i]==tmp) ans+=sizz[i];
writeln(ans);
lstans+=ans;
}
clr();
}
}
/*
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
*/
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3788kb
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: 134ms
memory: 76032kb
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:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
wrong answer 1st numbers differ - expected: '3000', found: '0'