QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#124371#2645. Collapselmeowdn0 24ms17268kbC++143.7kb2023-07-14 17:20:572023-07-14 17:20:58

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-14 17:20:58]
  • 评测
  • 测评结果:0
  • 用时:24ms
  • 内存:17268kb
  • [2023-07-14 17:20:57]
  • 提交

answer

#include "collapse.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;
int n,m,k,q,ans[N],b;
map<pii,pii>ed;
vi d[N],f[N]; vp g[N];

struct DSU {
  int id[N],cnt; vi p;
  void init() {cnt=0; rep(i,1,n) id[i]=i;}
  void init(vi p) {cnt=p.size(); for(int x:p) id[x]=x;}
  int find(int i) {return i==id[i]?i:id[i]=find(id[i]);}
  void merge(int x,int y) {
    x=find(x), y=find(y);
    if(x!=y) cnt--, id[x]=y;
  }
  int qry() {return cnt;}
} A,B;

struct edge {int u,v,l,r;} e[N];

vi simulateCollapse(int _n,vi t,vi x,vi y,vi w,vi p) {
  n=_n, k=t.size(), q=w.size(), b=sqrt(k);
  rep(i,1,k) {
    int op=t[i-1], u=x[i-1]+1, v=y[i-1]+1;
    if(u<v) swap(u,v);
    if(op==0) {
      ++m; ed[pii(u,v)]=pii(m,i);
    } else {  
      auto [id,l]=ed[pii(u,v)]; ed.erase(pii(u,v));
      e[id]=(edge){u,v,l,i-1};
    }
  }
  for(auto [p,q]:ed) {
    int u=p.fi, v=p.se, id=q.fi, l=q.se;
    e[id]=(edge){u,v,l,k};
  }
  for(int l=1,r=b;l<=k;l=r+1) {
    r=min(k,l+b-1); vector<edge> E;
    rep(i,1,n) g[i].clear(), d[i].clear(), f[i].clear();
    rep(i,1,m) {
      if(e[i].l>r||e[i].r<l) continue;
      else if(e[i].l>l||e[i].r<r) E.eb(e[i]);
      else d[e[i].u].eb(e[i].v), f[e[i].v].eb(e[i].u);
    }
    rep(i,1,q) {
      int t=w[i-1]+1, x=p[i-1]+1;
      if(l<=t&&t<=r) g[x].eb(t,i);
    }
    A.init(); B.init(); vi tp;
    rep(i,1,n) {
      A.cnt++; for(int j:d[i]) A.merge(i,j);
      for(auto [t,id]:g[i]) {
        static int vst[N]; tp.clear();
        int res=A.qry();
        for(auto x:E) if(x.l<=t&&t<=x.r&&x.u<=i) {
          int u=A.find(x.u), v=A.find(x.v);
          if(!vst[u]) tp.eb(u), vst[u]=1;
          if(!vst[v]) tp.eb(v), vst[v]=1;
        }
        B.init(tp); res-=tp.size();
        for(auto x:E) if(x.l<=t&&t<=x.r&&x.u<=i) {
          int u=A.find(x.u), v=A.find(x.v);
          B.merge(u,v);
        }
        res+=B.qry(); ans[id]+=res;
      }
    }
    rep(i,1,n) g[i].clear();
    rep(i,1,q) {
      int t=w[i-1]+1, x=p[i-1]+1;
      if(l<=t&&t<=r) g[x+1].eb(t,i);
    }
    A.init(); B.init();
    per(i,n,1) {
      A.cnt++; for(int j:f[i]) A.merge(i,j);
      for(auto [t,id]:g[i]) {
        static int vst[N]; tp.clear();
        int res=A.qry();
        for(auto x:E) if(x.l<=t&&t<=x.r&&x.v>=i) {
          int u=A.find(x.u), v=A.find(x.v);
          if(!vst[u]) tp.eb(u), vst[u]=1;
          if(!vst[v]) tp.eb(v), vst[v]=1;
        }
        B.init(tp); res-=tp.size();
        for(auto x:E) if(x.l<=t&&t<=x.r&&x.v>=i) {
          int u=A.find(x.u), v=A.find(x.v);
          B.merge(u,v);
        }
        res+=B.qry(); ans[id]+=res;
      }
    }
  }
  vi res; rep(i,1,q) res.eb(ans[i]); return res;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 5
Accepted
time: 9ms
memory: 12104kb

input:

2 5000 5000
0 0 1
1 0 1
0 0 1
1 1 0
0 1 0
1 1 0
0 1 0
1 0 1
0 1 0
1 0 1
0 0 1
1 0 1
0 1 0
1 1 0
0 1 0
1 1 0
0 0 1
1 0 1
0 1 0
1 0 1
0 1 0
1 0 1
0 0 1
1 0 1
0 1 0
1 1 0
0 0 1
1 1 0
0 1 0
1 1 0
0 1 0
1 1 0
0 1 0
1 0 1
0 1 0
1 0 1
0 0 1
1 0 1
0 0 1
1 0 1
0 0 1
1 0 1
0 1 0
1 1 0
0 1 0
1 0 1
0 0 1
1 1 0
...

output:

2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
...

result:

ok 5000 lines

Test #2:

score: -5
Wrong Answer
time: 2ms
memory: 12264kb

input:

5 7 5000
0 1 3
1 3 1
0 1 2
0 0 2
0 1 0
1 0 1
0 4 1
6 2
1 3
6 2
5 3
4 0
1 0
4 3
4 2
2 0
6 0
5 1
5 1
1 2
1 1
5 2
0 1
4 3
6 2
3 2
5 1
3 2
5 0
2 1
4 1
6 0
2 0
5 3
4 0
3 2
0 2
1 3
2 1
5 3
1 2
4 2
3 1
1 0
2 2
1 0
2 1
4 1
2 2
3 2
6 1
1 2
2 3
2 1
5 0
2 2
5 3
4 0
3 1
3 1
6 0
2 1
4 3
4 1
0 3
4 0
6 1
5 2
0 0
4...

output:

3
5
3
3
4
5
3
3
4
3
5
5
5
5
3
5
3
3
3
5
4
4
5
4
3
4
3
4
4
5
5
5
3
5
3
5
5
4
5
5
5
4
4
5
5
4
5
4
4
3
4
5
5
3
5
3
5
4
4
5
3
4
5
3
5
5
4
5
4
3
5
5
3
3
5
4
3
3
5
3
4
4
4
5
3
4
5
5
5
4
5
4
4
5
5
5
5
3
4
3
3
5
5
3
4
4
3
5
5
5
4
4
3
5
4
5
5
5
4
3
5
5
3
5
3
3
5
3
4
3
5
5
5
5
5
3
5
3
5
4
3
5
3
5
4
4
4
5
3
5
...

result:

wrong answer 21st lines differ - expected: '3', found: '4'

Subtask #2:

score: 0
Wrong Answer

Test #13:

score: 30
Accepted
time: 10ms
memory: 15380kb

input:

2 1 100000
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 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...

output:

2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
...

result:

ok 100000 lines

Test #14:

score: -30
Wrong Answer
time: 24ms
memory: 14676kb

input:

5 10 100000
0 3 2
1 2 3
0 2 1
0 2 3
0 0 3
1 3 2
1 1 2
0 2 4
0 0 2
0 4 0
2 2
0 2
7 2
1 2
8 2
0 2
0 2
6 2
0 2
2 2
2 2
7 2
5 2
8 2
0 2
9 2
2 2
7 2
6 2
0 2
8 2
1 2
3 2
2 2
9 2
9 2
1 2
9 2
6 2
1 2
3 2
1 2
3 2
3 2
5 2
8 2
3 2
0 2
7 2
7 2
8 2
9 2
1 2
1 2
0 2
1 2
1 2
0 2
7 2
9 2
2 2
5 2
6 2
2 2
9 2
9 2
0 2
...

output:

4
5
5
5
4
5
5
5
5
5
5
5
4
5
5
4
5
5
5
5
5
5
4
5
4
4
5
4
5
5
4
5
4
4
4
5
4
5
5
5
5
4
5
5
5
5
5
5
5
4
5
4
5
5
4
4
5
5
5
5
5
5
4
5
5
4
5
5
5
4
4
5
4
4
5
5
5
5
5
4
5
5
5
4
4
4
5
5
4
5
5
5
4
5
4
4
5
5
4
5
5
4
4
4
5
5
5
4
5
5
5
4
4
5
5
4
4
5
5
4
5
4
4
5
5
5
5
4
4
4
5
5
4
5
5
5
4
5
4
5
5
5
5
4
5
4
5
5
5
5
...

result:

wrong answer 10th lines differ - expected: '4', found: '5'

Subtask #3:

score: 0
Wrong Answer

Test #28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
5
2
2
4
2
5
2
4
4
4
3
4
2
2
3
4
2
4
3
5
4
3
4
5
4
5
4
5
5
4
3
4
4
5
2
3
4
4
4
4
5
2
5
5
5
2
4
2
5
2
5
5
4
3
2
4
4
4
2
4
5
4
5
4
4
2
3
4
3
3
2
4
2
3
3
2
4
4
4
5
3
3
4
5
4
4
5
4
3
3
5
3
5
5
3
2
5
4
5
5
4
3
4
5
3
5
5
2
4
3
2
4
2
3
4
3
5
5
4
5
2
3
3
3
4
2
2
5
5
4
...

result:

wrong answer 20th lines differ - expected: '2', found: '3'

Subtask #4:

score: 0
Skipped

Dependency #1:

0%