QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#123846#2644. Cats or Dogslmeowdn0 1ms30148kbC++144.0kb2023-07-13 19:40:442023-07-13 19:40:46

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-13 19:40:46]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:30148kb
  • [2023-07-13 19:40:44]
  • 提交

answer

#include "catdog.h"
#include<bits/stdc++.h>
#define fi first
#define se second
#define eb emplace_back
#define mp make_pair
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef __int128 i128;
template<typename T,typename U>
T ceil(T x, U y) {return (x>0?(x+y-1)/y:x/y);}
template<typename T,typename U>
T floor(T x, U y) {return (x>0?x/y:(x-y+1)/y);}
template<class T,class S>
bool chmax(T &a,const S b) {return (a<b?a=b,1:0);}
template<class T,class S>
bool chmin(T &a,const S b) {return (a>b?a=b,1:0);}
int popcnt(int x) {return __builtin_popcount(x);}
int popcnt(ll x)  {return __builtin_popcountll(x);}
int topbit(int x) {return (x==0?-1:31-__builtin_clz(x));}
int topbit(ll x)  {return (x==0?-1:63-__builtin_clzll(x));}
int lowbit(int x) {return (x==0?-1:__builtin_ctz(x));}
int lowbit(ll x)  {return (x==0?-1:__builtin_ctzll(x));}
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vp;
typedef tuple<int,int,int> tiii;

const int N=1e5+5,inf=0x3f3f3f3f;
int n,dfn[N],tick,sz[N],son[N],top[N],dn[N],id[N],f[N][3],g[N][3],anc[N];
vi e[N];

struct Mat {
  int a[3][3];
  Mat(int x=0) {
    a[0][0]=a[1][1]=a[2][2]=x;
    a[0][1]=a[1][2]=a[2][0]=inf;
    a[0][2]=a[1][0]=a[2][1]=inf;
  }
} G[N],A[N],T[N],C,D,E;
Mat operator * (const Mat &a,const Mat &b) {
  Mat c(inf);
  rep(i,0,2) rep(j,0,2) {
    chmin(c.a[i][j],a.a[i][0]+b.a[0][j]);
    chmin(c.a[i][j],a.a[i][1]+b.a[1][j]);
    chmin(c.a[i][j],a.a[i][2]+b.a[2][j]);
  }
  return c;
}

namespace SegT {
  int ls[N<<1],rs[N<<1],tot=1; Mat s[N<<1];
  void build(int p,int l,int r) {
    if(l==r) {s[p]=T[id[l]]; return;} int mid=l+r>>1;
    build(ls[p]=++tot,l,mid), build(rs[p]=++tot,mid+1,r);
    s[p]=s[rs[p]]*s[ls[p]];
  }
  Mat qry(int p,int l,int r,int x,int y) {
    if(l==x&&r==y) return s[p]; int mid=l+r>>1;
    if(y<=mid) return qry(ls[p],l,mid,x,y);
    else if(x>mid) return qry(rs[p],mid+1,r,x,y);
    else return qry(rs[p],mid+1,r,mid+1,y)*qry(ls[p],l,mid,x,mid);
  }
  void mdf(int p,int l,int r,int x) {
    if(l==r) {s[p]=T[id[l]]; return;} int mid=l+r>>1;
    if(x<=mid) mdf(ls[p],l,mid,x); else mdf(rs[p],mid+1,r,x);
    s[p]=s[rs[p]]*s[ls[p]];
  }
}

void make(int u,bool flag=1) {
  rep(j,0,2) G[u].a[0][j]=g[u][j];
  G[u].a[1][0]=g[u][0]+1, G[u].a[1][1]=g[u][1];
  G[u].a[2][0]=g[u][0]+1, G[u].a[2][2]=g[u][2];
  G[u].a[1][2]=G[u].a[2][1]=inf;
  T[u]=G[u]*A[u];
  if(flag) SegT::mdf(1,1,n,dfn[u]);
}
void dfs1(int u,int fa) {
  sz[u]=1; f[u][0]=f[u][1]=f[u][2]=0;
  for(int v:e[u]) if(v!=fa) {
    dfs1(v,u), sz[u]+=sz[v], anc[v]=u;
    if(sz[v]>sz[son[u]]) son[u]=v;
  }
}
int dfs2(int u,int tp) {
  top[u]=tp, dfn[u]=++tick, id[tick]=u;
  A[u]=E; make(u,0);
  if(son[u]) dn[u]=dfs2(son[u],tp);
  else return dn[u]=u;
  for(int v:e[u]) if(v!=son[u]&&v!=anc[u]) dfs2(v,v);
  return dn[u];
}
void mdf(int u) {
  make(u); int x=top[u], y=dn[u];
  Mat tran=SegT::qry(1,1,n,dfn[x],dfn[y]);
  if(anc[x]) rep(j,0,2) {
    g[anc[x]][0]-=min(f[x][0],min(f[x][1],f[x][2])+1);
    g[anc[x]][1]-=min(f[x][0],min(f[x][1],f[x][2]+1));
    g[anc[x]][2]-=min(f[x][0],min(f[x][2],f[x][1]+1));
  }
  rep(j,0,2) f[x][j]=tran.a[0][j];
  if(anc[x]) {
    g[anc[x]][0]+=min(f[x][0],min(f[x][1],f[x][2])+1);
    g[anc[x]][1]+=min(f[x][0],min(f[x][1],f[x][2]+1));
    g[anc[x]][2]+=min(f[x][0],min(f[x][2],f[x][1]+1));
    mdf(anc[x]);
  }
}
int qry() {return min(f[1][0],min(f[1][1],f[1][2]));}

void initialize(int N,vi A,vi B) {
  E=C=D=Mat(inf);
  E.a[0][0]=E.a[0][1]=E.a[0][2]=E.a[1][1]=E.a[2][2]=0;
  C.a[0][1]=C.a[1][1]=D.a[0][2]=D.a[2][2]=0;
  n=N;
  rep(i,0,n-2) {
    int u=A[i], v=B[i];
    e[u].eb(v), e[v].eb(u);
  }
  dfs1(1,0), dfs2(1,1);
  SegT::build(1,1,n);
}
int cat(int v) {A[v]=C; mdf(v); return qry();}
int dog(int v) {A[v]=D; mdf(v); return qry();}
int neighbor(int v) {A[v]=E; mdf(v); return qry();}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 8
Accepted
time: 0ms
memory: 28316kb

input:

2
2 1
75
1 2
1 1
3 1
3 2
1 1
2 2
3 1
3 2
2 2
3 2
1 1
3 1
1 2
2 1
3 2
2 2
3 2
1 2
3 1
1 1
3 2
3 1
1 2
3 2
2 1
2 2
3 2
3 1
2 1
1 2
3 1
1 1
3 2
3 1
1 2
3 2
2 1
3 1
1 1
1 2
3 1
3 2
2 1
1 2
3 1
2 1
3 2
2 2
3 1
2 1
3 2
2 2
3 2
2 2
3 1
3 2
1 1
3 1
2 2
1 1
3 1
1 1
3 2
2 2
3 2
3 1
2 2
2 1
3 1
2 1
3 2
1 2
3 1...

output:

0
0
0
0
0
1
0
0
0
0
0
0
0
1
0
0
0
1
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
1
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
1
0
1
0
0
0
0
0
0
0
1
0
1
0

result:

ok 75 lines

Test #2:

score: -8
Wrong Answer
time: 1ms
memory: 30148kb

input:

9
5 3
4 9
5 4
4 1
5 7
7 6
4 8
2 3
32
2 9
2 5
1 1
2 2
1 4
1 3
3 3
2 3
3 1
2 7
3 4
1 4
3 2
3 7
1 6
3 4
2 7
2 8
3 7
3 9
3 5
1 4
3 6
2 1
1 7
3 4
3 8
1 2
3 2
3 3
3 7
1 9

output:

0
0
1
1
2
4
2
2
2
2
0
2
2
1
2
0
-1
-1
-6
-6
-7
-7
-10
-9
-8
-9
-12
-11
-12
-13
-16
-15

result:

wrong answer 14th lines differ - expected: '2', found: '1'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #1:

0%