QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#824558#9771. Guessing Gameucup-team159#RE 0ms3744kbC++2011.1kb2024-12-21 14:40:032024-12-21 14:40:08

Judging History

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

  • [2024-12-21 14:40:08]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3744kb
  • [2024-12-21 14:40:03]
  • 提交

answer

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < (t); ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define em emplace
#define pob pop_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define newline puts("")
#define vc vector
using namespace std;
template<class T> using vv = vc<vc<T>>;
template<class T> using PQ = priority_queue<T,vc<T>,greater<T>>;
using uint = unsigned; using ull = unsigned long long;
using vi = vc<int>; using vvi = vv<int>; using vvvi = vv<vi>;
using ll = long long; using vl = vc<ll>; using vvl = vv<ll>; using vvvl = vv<vl>;
using P = pair<int,int>; using vp = vc<P>; using vvp = vv<P>; using LP = pair<ll,ll>;
int geti(){int x;scanf("%d",&x);return x;}
vi pm(int n, int s=0) { vi a(n); iota(rng(a),s); return a;}
template<class T1,class T2>istream& operator>>(istream&i,pair<T1,T2>&v){return i>>v.fi>>v.se;}
template<class T1,class T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v){return o<<v.fi<<","<<v.se;}
template<class T>istream& operator>>(istream&i,vc<T>&v){rep(j,sz(v))i>>v[j];return i;}
template<class T>string join(const T&v,const string&d=""){stringstream s;rep(i,sz(v))(i?s<<d:s)<<v[i];return s.str();}
template<class T>ostream& operator<<(ostream&o,const vc<T>&v){if(sz(v))o<<join(v," ");return o;}
template<class T>void vin(vc<T>&a){int n;cin>>n;a=vc<T>(n);cin>>a;}
template<class T>void vin(vv<T>&a){int n,m;cin>>n>>m;a=vv<T>(n,vc<T>(m));cin>>a;}
template<class T1,class T2>void operator--(pair<T1,T2>&a,int){a.fi--;a.se--;}
template<class T1,class T2>void operator++(pair<T1,T2>&a,int){a.fi++;a.se++;}
template<class T>void operator--(vc<T>&a,int){for(T&x:a)x--;}
template<class T>void operator++(vc<T>&a,int){for(T&x:a)x++;}
template<class T1,class T2>void operator+=(vc<T1>&a,T2 b){for(T1&x:a)x+=b;}
template<class T1,class T2>void operator-=(vc<T1>&a,T2 b){for(T1&x:a)x-=b;}
template<class T1,class T2>void operator*=(vc<T1>&a,T2 b){for(T1&x:a)x*=b;}
template<class T1,class T2>void operator/=(vc<T1>&a,T2 b){for(T1&x:a)x/=b;}
template<class T>void operator+=(vc<T>&a,const vc<T>&b){a.insert(a.end(),rng(b));}
template<class T1,class T2>pair<T1,T2>operator+(const pair<T1,T2>&a,const pair<T1,T2>&b){return {a.fi+b.fi,a.se+b.se};}
template<class T1,class T2>pair<T1,T2>operator-(const pair<T1,T2>&a,const pair<T1,T2>&b){return {a.fi-b.fi,a.se-b.se};}
template<class T1,class T2>void operator+=(pair<T1,T2>&a,const pair<T1,T2>&b){a.fi+=b.fi;a.se+=b.se;}
template<class T1,class T2>void operator-=(pair<T1,T2>&a,const pair<T1,T2>&b){a.fi-=b.fi;a.se-=b.se;}
template<class T>pair<T,T>operator*(const pair<T,T>&a,T b){return {a.fi*b,a.se*b};}
template<class T1,class T2>bool mins(T1& x,const T2&y){if(y<x){x=y;return true;}else return false;}
template<class T1,class T2>bool maxs(T1& x,const T2&y){if(x<y){x=y;return true;}else return false;}
template<class T>T min(const vc<T>&a){return *min_element(rng(a));}
template<class T>T max(const vc<T>&a){return *max_element(rng(a));}
template<class Tx,class Ty>Tx dup(Tx x, Ty y){return (x+y-1)/y;}
template<class T>ll suma(const vc<T>&a){ll s=0;for(auto&&x:a)s+=x;return s;}
template<class T>ll suma(const vv<T>&a){ll s=0;for(auto&&x:a)s+=suma(x);return s;}
template<class T>void uni(T&a){sort(rng(a));a.erase(unique(rng(a)),a.end());}
template<class T>void prepend(vc<T>&a,const T&x){a.insert(a.begin(),x);}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return;}
#define yes { puts("Yes"); return;}
#define no { puts("No"); return;}
#define rtn(x) { cout<<(x)<<'\n'; return;} // flush!
#define yn {puts("Yes");}else{puts("No");}

// Union find
struct uf {
  vi d;
  uf(){}
  uf(int mx):d(mx,-1){}
  int root(int x) {
    if(d[x] < 0) return x;
    return d[x] = root(d[x]);
  }
  bool unite(int x, int y) {
    x = root(x); y = root(y);
    if(x == y) return false;
    if(d[x] > d[y]) swap(x,y);
    d[x] += d[y]; d[y] = x;
    return true;
  }
  bool same(int x, int y) { return root(x) == root(y);}
  int size(int x) { return -d[root(x)];}
  int operator[](int x) { return root(x);}
  int operator()(int x) { return size(x);}
};
//

// Segment tree with lazy prop
struct F {
  int d;
  F(int d=INF):d(d) {}
  F& operator+=(const F& f) {
    mins(d, f.d);
    return *this;
  }
  F operator+(const F& f) const { return F(*this) += f;}
};
ostream& operator<<(ostream&o,const F&f){return o<<f.d;}
struct G {
  int d;
  G(int d=INF):d(d) {}
  void operator()(F& f) const {
    mins(f.d,d);
  }
  void operator*=(const G& g) {
    mins(d,g.d);
  }
};
ostream& operator<<(ostream&o,const G&g){return o<<g.d;}
// template<typename F, typename G>
struct seg {
  struct FG {
    F f; G g;
    void apply(const G& _g) {
      _g(f);
      g *= _g;
    }
  };
  vector<FG> d; int n;
  seg(){}
  seg(int mx) {
    n = 1; while (n < mx) n <<= 1;
    d = vector<FG>(n<<1);
  }
  int width(int i) { return 1<<(__builtin_clz(i)-__builtin_clz(n));}
  void upd(int i) { d[i].f = d[i<<1].f+d[i<<1|1].f;}
  FG& operator[](int i) { return d[n+i];}
  void init() { drep(i,n) upd(i);}
  void prop(int i) {
    d[i<<1].apply(d[i].g);
    d[i<<1|1].apply(d[i].g);
    d[i].g = G();
  }
  void add(int l, int r, G g) { if (l < r) add(l,r,g,1,0,n);}
  void add(int a, int b, const G& g, int i, int l, int r) {
    if (a <= l && r <= b) {
      d[i].apply(g);
      return;
    }
    prop(i);
    int c = (l+r)>>1;
    if (a < c) add(a,b,g,i<<1,l,c);
    if (c < b) add(a,b,g,i<<1|1,c,r);
    upd(i);
  }
  void add(int v, F f, bool rpl=false) {
    int i = 1;
    for (int b = n; i < n; b >>= 1, i = i<<1|!!(v&b)) prop(i);
    if (rpl) d[i].f = f; else  d[i].f += f;
    while (i > 1) i >>= 1, upd(i);
  }
  void set(int v, F f) { add(v,f,true);}
  F get() { return d[1].f;}
  F get(int l, int r) { return (l < r) ? get(l,r,1,0,n) : F();}
  F get(int a, int b, int i, int l, int r) {
    if (a <= l && r <= b) return d[i].f;
    prop(i);
    int c = (l+r)>>1;
    F res;
    if (a < c) res += get(a,b,i<<1,l,c);
    if (c < b) res += get(a,b,i<<1|1,c,r);
    return res;
  }
// [segl_mxr]
};
//

// HL-decomposition
struct hl {
  int n, root;
  vvi to;
  seg t; // SEG
  hl(int n=0):n(n),to(n) {}
  void add(int a, int b) {
    to[a].pb(b);
    to[b].pb(a);
  }
  vi tsz, pa, dep;
  int tfs(int v, int p=-1) {
    pa[v] = p;
    tsz[v] = 1;
    rep(i,sz(to[v])) {
      int& u = to[v][i];
      if (u == p) swap(u, to[v].back());
      if (u == p) break;
      dep[u] = dep[v]+1;
      tsz[v] += tfs(u,v);
      if (tsz[u] > tsz[to[v][0]]) swap(u, to[v][0]);
    }
    if (~p) to[v].pop_back();
    return tsz[v];
  }
  vi in, out, nxt, kv;
  void dfs(int v) {
    in[v] = sz(kv); kv.pb(v);
    rep(i,sz(to[v])) {
      int u = to[v][i];
      nxt[u] = i ? u : nxt[v];
      dfs(u);
    }
    out[v] = sz(kv);
  }
  void init(int v=0) {
    tsz = pa = dep = vi(n);
    tfs(root = v);
    in = out = nxt = vi(n);
    nxt[root] = root;
    dfs(root);
    t = seg(n); // SEG
  }
  int up(int v, int l) {
    while (~v) {
      int u = nxt[v], nl = dep[v]-dep[u]+1;
      if (l < nl) return kv[in[v]-l];
      l -= nl; v = pa[u];
    }
    return -1;
  }
  int lca(int a, int b) {
    while (nxt[a] != nxt[b]) {
      if (in[a] < in[b]) swap(a,b);
      a = pa[nxt[a]];
    }
    if (in[a] < in[b]) swap(a,b);
    return b;
  }
  int len(int a, int b) { return dep[a]+dep[b]-dep[lca(a,b)]*2;}

  //* // SEG
  F get(int v) { return t.get(in[v],in[v]+1);}
  void add(int p, int v, G x) {
    int ip = ~p?in[p]:-1;
    while (~v) {
      int u = nxt[v];
      if (in[u] <= ip) {
        t.add(ip+1, in[v]+1, x);
        break;
      }
      t.add(in[u], in[v]+1, x);
      v = pa[u];
    }
  }
  void adds(int a, int b, G x) {
    int c = lca(a,b);
    add(c,a,x); add(pa[c],b,x);
  }
  F getr(int v) { return t.get(in[v],out[v]);}
  F getp(int v) {
    return t.get(0,in[v]) + t.get(out[v],n);
  }
  int get2(int v) {
    vi ds(2,INF);
    ds[0] = getp(v).d;
    for (int u : to[v]) ds.pb(getr(u).d);
    sort(rng(ds));
    return ds[1];
  }
  //*/
};
//

const int n1 = 3, n = n1*2;
struct T {
  int a, b, d, da, db;
  T(int a=0, int b=0, int d=0, int da=0, int db=0):a(a),b(b),d(d),da(da),db(db) {}
  bool operator<(const T& _) const { return a<_.a;}
  P get() {
    if (d == -1) return P(0,0);
    P res(a,b);
    bool isa = false;
    if (d%2) isa = (d/2%2==1);
    else if (da < n1) isa = (d/2%2==0);
    else isa = (d/2%2==1);
    if (isa) res.fi--; else res.se--;
    // cerr<<a<<" "<<b<<", "<<d<<", "<<da<<" "<<db<<": "<<res<<endl;
    return res;
  }
};
istream& operator>>(istream&i,T&a){return i>>a.a>>a.b>>a.d>>a.da>>a.db;}
ostream& operator<<(ostream&o,const T&a){return o<<a.a<<" "<<a.b<<" "<<a.d<<" "<<a.da<<" "<<a.db;}

struct Solver {
  void solve() {
    int m;
    scanf("%d",&m);
    vp es(m);
    cin>>es;
    es--;
    rep(i,m) es[i].se += n1;

    hl g(n);
    uf t(n);
    vi ist(m);
    rep(ei,m) {
      auto [a,b] = es[ei];
      if (t.unite(a,b)) g.add(a,b), ist[ei] = 1;
    }
    rep(i,n-1) if (t.unite(i,i+1)) g.add(i,i+1);
    g.init();

    vc<T> ts(n);
    rep(i,n) ts[i] = T(i<n1,i>=n1,0,i,i);

    P ans(0,0);

    vp del(m);
    {
      rep(ei,m) {
        auto [a,b] = es[ei];
        if (ist[ei]) continue;
        g.adds(a,b,ei);
      }
      rep(v,n) {
        int dt = g.get(v).d;
        mins(dt, g.get2(v));
        if (dt > m) continue;
        if (v<n1) del[dt].fi++; else del[dt].se++;
      }
    }
    // cerr<<del<<endl;

    t = uf(n);
    rep(ei,m) {
      auto [a,b] = es[ei];
      if (ist[ei]) {
        a = t[a]; b = t[b];
        T ta = ts[a], tb = ts[b];
        ans -= ta.get();
        ans -= tb.get();
        
        if (ta.d != -1) swap(ta,tb);
        T nt = ta;
        if (ta.d != -1) {
          nt.a += tb.a; nt.b += tb.b;
          if (maxs(nt.d, tb.d)) nt.da = tb.da, nt.db = tb.db;
          rep(ai,2) {
            rep(bi,2) {
              if (maxs(nt.d, g.len(ta.da,tb.da))) nt.da = ta.da, nt.db = tb.da;
              swap(tb.da,tb.db);
            }
            swap(ta.da,ta.db);
          }
        } else {
          if (tb.d != -1) {
            ans += P(tb.a, tb.b);
          }
        }

        t.unite(a,b);
        ans += nt.get();
        ts[t[a]] = nt;
      } else {
        a = t[a];
        T& ta = ts[a];
        if (ta.d != -1) {
          ans -= ta.get();
          ans += P(ta.a,ta.b);
          ta.d = -1;
        }
      }

      ans -= del[ei];
      printf("%d %d\n",ans.fi,ans.se);
    }
  }
};

int main() {
  // cin.tie(nullptr); ios::sync_with_stdio(false);
  int ts = 1;
  // scanf("%d",&ts);
  rep1(ti,ts) {
    Solver solver;
    solver.solve();
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3744kb

input:

4
1 1
1 2
2 1
2 2

output:

1 0
0 2
1 2
0 0

result:

ok 8 numbers

Test #2:

score: -100
Runtime Error

input:

250000
49324 49323
44443 44445
92513 92513
69591 69591
52085 52082
95024 95025
21004 21005
34373 34371
60771 60772
17131 17134
34885 34882
6011 6015
56103 56105
21055 21054
71592 71593
14894 14895
25774 25771
96225 96224
16444 16442
48432 48432
86954 86952
7202 7202
38661 38665
20063 20063
85383 853...

output:


result: