QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#425055 | #8109. Postcards | AFewSuns | AC ✓ | 957ms | 107300kb | C++20 | 4.5kb | 2024-05-29 21:48:44 | 2024-05-29 21:48:45 |
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[r1][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],dfnn[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[blg[i]]++;
ll tmp=0;
fr(i,1,cntt){
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();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 5768kb
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: 0
Accepted
time: 137ms
memory: 78516kb
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:
ok 5000 numbers
Test #3:
score: 0
Accepted
time: 58ms
memory: 90132kb
input:
2430 490875 33333 2 1 3 1 3 2 4 1 4 2 4 3 5 1 5 2 5 3 5 4 6 1 6 2 6 3 6 4 6 5 7 1 7 2 7 3 7 4 7 5 7 6 8 1 8 2 8 3 8 4 8 5 8 6 8 7 9 1 9 2 9 3 9 4 9 5 9 6 9 7 9 8 10 1 10 2 10 3 10 4 10 5 10 6 10 7 10 8 10 9 11 1 11 2 11 3 11 4 11 5 11 6 11 7 11 8 11 9 11 10 12 1 12 2 12 3 12 4 12 5 12 6 12 7 12 8 12...
output:
405 405 2430 405 2430 2430 1620 405 2430 2430 405 405 405 1620 2025 405 405 2025 0 405 405 405 405 405 2430 405 405 405 1620 405 405 1620 2430 2430 2430 405 2430 405 2430 1620 405 405 405 2430 1215 2025 2430 405 2025 2430 2430 1620 0 405 405 1215 405 2430 405 0 2430 405 405 0 2430 405 1215 405 2430 ...
result:
ok 33333 numbers
Test #4:
score: 0
Accepted
time: 55ms
memory: 83492kb
input:
2225 493960 50000 2 1 3 1 3 2 4 1 4 2 4 3 5 1 5 2 5 3 5 4 6 1 6 2 6 3 6 4 6 5 7 1 7 2 7 3 7 4 7 5 7 6 8 1 8 2 8 3 8 4 8 5 8 6 8 7 9 1 9 2 9 3 9 4 9 5 9 6 9 7 9 8 10 1 10 2 10 3 10 4 10 5 10 6 10 7 10 8 10 9 11 1 11 2 11 3 11 4 11 5 11 6 11 7 11 8 11 9 11 10 12 1 12 2 12 3 12 4 12 5 12 6 12 7 12 8 12...
output:
2225 2225 445 445 445 445 445 1780 2225 445 1780 1780 1335 2225 2225 2225 1780 445 445 445 2225 445 445 445 445 2225 2225 445 0 1780 445 445 445 445 445 445 1780 445 2225 445 445 0 445 445 2225 0 445 445 445 0 1780 0 445 445 445 0 445 2225 445 2225 2225 445 2225 445 0 445 2225 0 2225 445 2225 445 22...
result:
ok 50000 numbers
Test #5:
score: 0
Accepted
time: 64ms
memory: 96148kb
input:
2625 490896 23809 2 1 3 1 3 2 4 1 4 2 4 3 5 1 5 2 5 3 5 4 6 1 6 2 6 3 6 4 6 5 7 1 7 2 7 3 7 4 7 5 7 6 8 1 8 2 8 3 8 4 8 5 8 6 8 7 9 1 9 2 9 3 9 4 9 5 9 6 9 7 9 8 10 1 10 2 10 3 10 4 10 5 10 6 10 7 10 8 10 9 11 1 11 2 11 3 11 4 11 5 11 6 11 7 11 8 11 9 11 10 12 1 12 2 12 3 12 4 12 5 12 6 12 7 12 8 12...
output:
2625 375 2625 2250 1125 375 375 375 0 2250 375 1875 1125 2625 375 375 2625 1875 2625 2625 2250 2625 2250 375 375 375 2250 2625 2625 1875 2625 375 0 375 2625 2625 2625 2625 375 375 375 2625 375 375 2625 375 375 375 2250 375 2625 1125 1125 375 375 2625 2625 0 375 2625 375 375 0 2625 375 375 2625 2625 ...
result:
ok 23809 numbers
Test #6:
score: 0
Accepted
time: 79ms
memory: 77840kb
input:
3000 3000 250000 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50 51 ...
output:
407 687 1378 2124 15 1126 78 1253 990 2020 2664 1455 1888 1494 1448 2467 2995 2193 1673 2823 90 1836 2565 2990 1604 239 429 2943 812 498 1956 829 1164 1329 1703 1578 753 2550 2302 1961 1264 2612 1763 2379 1337 1509 673 1609 2489 643 1736 2003 128 1388 1283 432 2606 931 2283 1695 753 2088 363 1084 46...
result:
ok 250000 numbers
Test #7:
score: 0
Accepted
time: 63ms
memory: 77072kb
input:
3000 13800 250000 2 1 3 1 3 2 4 1 4 2 4 3 5 1 5 2 5 3 5 4 6 1 6 2 6 3 6 4 6 5 7 1 7 2 7 3 7 4 7 5 7 6 8 1 8 2 8 3 8 4 8 5 8 6 8 7 9 1 9 2 9 3 9 4 9 5 9 6 9 7 9 8 10 1 10 2 10 3 10 4 10 5 10 6 10 7 10 8 10 9 12 11 13 11 13 12 14 11 14 12 14 13 15 11 15 12 15 13 15 14 16 11 16 12 16 13 16 14 16 15 17 ...
output:
260 780 1360 2090 2650 930 2390 2790 2650 1970 1390 510 930 2390 620 2500 50 690 1210 1990 330 1200 2950 2880 630 1740 920 320 20 1700 570 2320 2900 1810 2950 70 850 440 570 1540 470 1400 2770 10 680 1150 1450 380 390 1880 130 340 1170 1980 2550 2360 1920 70 1010 450 2540 1030 2650 260 1010 1020 650...
result:
ok 250000 numbers
Test #8:
score: 0
Accepted
time: 79ms
memory: 107300kb
input:
3000 448510 250000 2 1 3 1 3 2 4 1 4 2 4 3 5 1 5 2 5 3 5 4 6 1 6 2 6 3 6 4 6 5 7 1 7 2 7 3 7 4 7 5 7 6 8 1 8 2 8 3 8 4 8 5 8 6 8 7 9 1 9 2 9 3 9 4 9 5 9 6 9 7 9 8 10 1 10 2 10 3 10 4 10 5 10 6 10 7 10 8 10 9 11 1 11 2 11 3 11 4 11 5 11 6 11 7 11 8 11 9 11 10 12 1 12 2 12 3 12 4 12 5 12 6 12 7 12 8 1...
output:
300 2700 1500 300 2700 2700 2100 1500 2400 600 2100 2700 2100 1200 2100 300 600 2700 1500 2700 600 300 1800 1500 2700 900 2700 300 1200 1500 1200 2100 1200 1500 900 2400 1200 2100 2100 2700 1800 1200 900 1200 2100 2700 2100 2100 1500 300 2400 2700 1200 1800 600 2100 2100 2700 600 2100 600 1800 300 2...
result:
ok 250000 numbers
Test #9:
score: 0
Accepted
time: 47ms
memory: 74000kb
input:
2800 9200 41666 2 1 3 1 3 2 4 1 4 2 4 3 5 1 5 2 5 3 5 4 6 1 6 2 6 3 6 4 6 5 7 1 7 2 7 3 7 4 7 5 7 6 9 8 10 8 10 9 11 8 11 9 11 10 12 8 12 9 12 10 12 11 13 8 13 9 13 10 13 11 13 12 14 8 14 9 14 10 14 11 14 12 14 13 16 15 17 15 17 16 18 15 18 16 18 17 19 15 19 16 19 17 19 18 20 15 20 16 20 17 20 18 20...
output:
21 14 21 28 42 7 63 14 28 21 14 63 63 63 14 14 14 7 21 42 21 14 63 28 14 14 42 42 21 21 7 21 28 21 42 42 28 42 42 28 63 28 14 7 42 14 21 42 42 28 42 7 42 42 14 28 63 28 14 28 14 42 14 42 63 42 14 7 42 14 28 14 21 7 21 42 7 28 28 14 21 21 63 21 42 14 42 14 28 63 21 42 7 42 63 42 14 7 42 63 21 21 7 14...
result:
ok 41666 numbers
Test #10:
score: 0
Accepted
time: 52ms
memory: 76692kb
input:
2940 20972 15625 2 1 3 1 3 2 4 1 4 2 4 3 5 1 5 2 5 3 5 4 6 1 6 2 6 3 6 4 6 5 7 1 7 2 7 3 7 4 7 5 7 6 8 1 8 2 8 3 8 4 8 5 8 6 8 7 9 1 9 2 9 3 9 4 9 5 9 6 9 7 9 8 10 1 10 2 10 3 10 4 10 5 10 6 10 7 10 8 10 9 11 1 11 2 11 3 11 4 11 5 11 6 11 7 11 8 11 9 11 10 12 1 12 2 12 3 12 4 12 5 12 6 12 7 12 8 12 ...
output:
90 480 150 525 60 840 300 600 960 240 60 525 420 90 75 90 60 360 960 450 120 150 225 75 525 75 840 120 60 150 360 420 300 300 105 375 360 90 270 15 180 360 360 630 420 60 225 60 360 240 60 525 360 600 90 180 90 210 360 540 180 30 90 60 180 180 120 525 480 630 105 600 60 525 15 210 90 315 525 120 420...
result:
ok 15625 numbers
Test #11:
score: 0
Accepted
time: 85ms
memory: 73848kb
input:
2809 5618 5000 1 54 1 2 2 55 2 3 3 56 3 4 4 57 4 5 5 58 5 6 6 59 6 7 7 60 7 8 8 61 8 9 9 62 9 10 10 63 10 11 11 64 11 12 12 65 12 13 13 66 13 14 14 67 14 15 15 68 15 16 16 69 16 17 17 70 17 18 18 71 18 19 19 72 19 20 20 73 20 21 21 74 21 22 22 75 22 23 23 76 23 24 24 77 24 25 25 78 25 26 26 79 26 27...
output:
9 46 10 250 240 81 408 84 484 175 63 48 57 154 8 198 84 350 18 308 50 285 114 368 54 196 55 336 30 72 120 192 76 260 368 108 250 108 255 56 170 320 8 336 4 198 200 120 252 255 10 30 625 48 9 30 500 150 30 168 418 112 576 247 18 30 253 414 65 462 216 60 352 72 380 84 6 28 42 170 437 25 400 182 170 22...
result:
ok 5000 numbers
Test #12:
score: 0
Accepted
time: 39ms
memory: 5656kb
input:
20 100 12500 7 12 14 16 3 8 1 16 5 13 9 16 2 18 10 20 9 12 1 6 5 17 11 15 6 16 4 11 1 12 5 15 6 14 4 10 12 13 5 20 3 19 11 13 13 20 17 20 4 18 9 10 2 19 6 15 13 15 6 10 3 18 2 20 15 16 4 9 5 14 3 20 4 5 5 19 18 19 4 15 16 17 17 18 9 15 10 16 14 19 5 16 2 5 3 10 1 11 8 9 3 6 5 12 13 14 1 4 2 15 7 14 ...
output:
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ...
result:
ok 12500 numbers
Test #13:
score: 0
Accepted
time: 40ms
memory: 7676kb
input:
8 7 100000 4 2 7 6 8 6 6 1 3 2 5 2 2 1 5 0 0 1 1 0 1 3 0 1 4 0 1 5 0 1 5 5 0 1 6 0 1 0 1 0 1 0 1 2 1 0 5 6 0 1 0 1 0 1 0 1 2 1 0 3 0 1 5 5 0 1 6 0 1 0 0 1 1 0 1 3 0 1 5 3 1 0 4 0 1 5 0 1 6 0 1 0 0 1 5 2 0 1 4 0 1 5 0 1 6 1 0 0 0 1 5 2 0 1 3 0 1 4 1 0 5 1 0 6 0 1 5 1 0 1 2 0 1 3 0 1 5 0 1 6 1 0 5 0 0...
output:
2 0 0 3 0 1 0 1 0 3 0 3 3 0 0 2 0 1 2 2 0 3 0 0 1 0 1 0 3 0 3 0 3 0 3 0 2 1 2 2 1 3 3 3 1 3 1 1 1 3 3 0 2 3 0 3 2 0 3 1 1 1 0 1 0 3 0 3 1 2 1 0 2 1 3 3 0 0 1 3 3 0 1 0 2 3 0 1 0 3 2 3 3 2 2 2 0 1 1 1 0 3 1 1 2 2 2 2 0 1 3 1 3 3 0 1 0 1 3 1 3 2 2 3 3 3 1 0 2 0 1 0 2 0 3 1 3 1 3 3 3 2 0 0 1 0 3 3 0 1 ...
result:
ok 100000 numbers
Test #14:
score: 0
Accepted
time: 132ms
memory: 77568kb
input:
3000 2999 100000 32 23 1819 1600 1795 530 263 65 2688 1258 540 186 835 75 2780 1758 1483 753 859 394 387 97 100 56 616 199 824 136 1633 834 2086 789 1582 60 733 309 47 29 545 237 2418 1559 966 250 1032 929 1590 600 1980 983 2378 325 1504 1309 2583 1446 2510 976 2631 1099 1278 1264 2643 331 151 59 13...
output:
2901 2979 2944 2988 2986 2990 2992 2981 2994 2994 2991 2993 2988 2995 2993 2990 2976 2968 2967 2989 2993 2968 2984 2991 2991 2990 2990 2988 2981 2992 2991 2989 2995 2989 2978 2983 2922 2985 2991 2980 2993 2978 2985 2995 2975 2990 2986 2990 2979 2935 2990 2986 2993 2983 2979 2993 2971 2934 2993 2994 ...
result:
ok 100000 numbers
Test #15:
score: 0
Accepted
time: 366ms
memory: 76724kb
input:
2999 2998 17857 2123 1486 1916 1560 1615 335 948 870 453 88 818 350 2502 1982 2819 1992 1333 711 1436 1282 397 362 1314 525 2926 564 94 90 2835 1610 2994 1891 2011 325 1844 211 1186 4 2006 221 1832 1700 2763 2518 607 348 2483 1077 449 352 2241 1457 2317 2149 1250 886 2180 850 1162 73 1142 1054 1118 ...
output:
2843 2826 2914 1 2717 2881 2584 2903 2727 2932 2840 1 2789 2863 2902 2913 26 2830 2317 2889 2909 2888 2876 2934 11 2853 2565 2910 2919 2937 2748 2904 2884 2922 2895 2876 2855 2703 2889 2716 2945 2769 2916 2901 2829 2875 2726 2939 2939 2769 2902 2261 2778 2924 2698 2346 2932 2898 2683 2766 2297 2809 ...
result:
ok 17857 numbers
Test #16:
score: 0
Accepted
time: 957ms
memory: 76052kb
input:
2999 2998 5000 1095 1092 624 381 1167 916 2307 1155 1976 1067 584 282 2978 936 1383 247 481 279 1185 1015 2097 2008 2268 2080 393 217 1528 1417 1590 1009 1353 66 1054 370 526 169 1790 591 2287 2129 1959 855 2679 2364 903 654 256 101 752 595 1683 904 2494 485 236 64 2796 1904 2037 1038 2396 934 2898 ...
output:
12 2331 1600 2487 2530 1970 2388 2627 2525 2728 2445 2394 2588 2263 940 1895 2332 2393 2549 0 2551 914 2361 2366 0 0 1 2311 1 2261 2605 2300 2650 2306 2528 2568 2640 2311 2466 2512 2527 2197 4 4 2374 1867 2690 2003 8 2508 2272 2728 1 8 3 1568 904 2455 1 2246 2259 2707 2628 2287 1 1637 0 2556 2409 0 ...
result:
ok 5000 numbers