QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#20590#2214. Link Cut DigraphjobAKIOIAC ✓532ms92384kbC++113.8kb2022-02-16 19:01:482022-05-03 10:40:45

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-03 10:40:45]
  • 评测
  • 测评结果:AC
  • 用时:532ms
  • 内存:92384kb
  • [2022-02-16 19:01:48]
  • 提交

answer

// 德丽莎你好可爱德丽莎你好可爱德丽莎你好可爱德丽莎你好可爱德丽莎你好可爱
// 德丽莎的可爱在于德丽莎很可爱,德丽莎为什么很可爱呢,这是因为德丽莎很可爱!
#include <bits/stdc++.h>
#define int long long
using namespace std;
namespace IO {
  int len = 0;
  char ibuf[(1 << 20) + 1], *iS, *iT, out[(1 << 25) + 1];
  #define gh()   (iS == iT ? iT = (iS = ibuf) + fread(ibuf, 1, (1 << 20) + 1, stdin), (iS == iT ? EOF : *iS++) : *iS++)
  inline int read() {
    char ch = gh();
    int x = 0;
    char t = 0;
    while (ch < '0' || ch > '9') t |= ch == '-', ch = gh();
    while (ch >= '0' && ch <= '9') x = x * 10 + (ch ^ 48), ch = gh();
    return t ? -x : x;
  }
  inline void putc(char ch) { out[len++] = ch; }
  template <class T> inline void write(T x) {
    if (x < 0) putc('-'), x = -x;
    if (x > 9) write(x / 10);
    out[len++] = x % 10 + 48;
  }
  string getstr(void) {
    string s = ""; 
    char c = gh();
    while (c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == EOF) c = gh();
    while (!(c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == EOF))s.push_back(c), c = gh();
    return s;
  }
  void putstr(string str, int begin = 0, int end = -1) {
    if (end == -1) end = str.size();
    for (int i = begin; i < end; i++) putc(str[i]);
    return;
  }
  inline void flush() {
    fwrite(out, 1, len, stdout);
    len = 0;
  }
} // namespace IO by Macesuted
using IO::flush;
using IO::getstr;
using IO::putc;
using IO::putstr;
using IO::read;
using IO::write;
const int N = 1e6;
int n, m, x[N], y[N], fa[N], rk[N];
int dfn[N], low[N], tot, col[N], ans[N];
int getfa(int x) {
  if(fa[x] != x) fa[x] = getfa(fa[x]);
  return fa[x];
}
int cnt, st[N], tp, in[N], scc[N], sc;
vector <int> tmp, a[N];
void tarjan(int u) {
  dfn[u] = low[u] = ++cnt;
  st[++tp] = u;  in[u] = 1;
  for(int i = 0; i < a[u].size(); i++) {
    int to = a[u][i];
    if(!dfn[to]) {
      tarjan(to);
      low[u] = min(low[u], low[to]);
    }  else if(in[to]) {
      low[u] = min(low[u], dfn[to]);
    }
  }
  if(dfn[u] == low[u]) {
    int tmp = st[tp--], now = tmp;
    in[tmp] = 0;
    scc[tmp] = now;
    while(tmp != u) {
      tmp = st[tp--];
      in[tmp] = 0;
      scc[tmp] = now;
    }
  }
}
void work(int l,int r, vector <int> e) {
  int mid = (l + r) >> 1;  tot++;
  vector <int> now;
  for(int i = 0; i < e.size(); i++) {
    int id = e[i];
    if(id <= mid) {
      int A = getfa(x[id]), B = getfa(y[id]);
      if(col[A] != tot) {
        col[A] = tot;
        a[A].clear();
        dfn[A] = low[A] = 0;
        now.push_back(A);
      }
      if(col[B] != tot) {
        col[B] = tot;
        a[B].clear();
        dfn[B] = low[B] = 0;
        now.push_back(B); 
      }
      a[A].push_back(B);
    }
  }
  for(int i = 0; i < now.size(); i++) if(!dfn[now[i]]) tarjan(now[i]);
  if(l == r) {
    int q1 = 0;
    for(int i = 0; i < now.size(); i++) {
      int tmp = now[i];
      if( getfa(tmp) != getfa(scc[tmp]) ) {
        q1 += rk[getfa(scc[tmp])] * rk[getfa(tmp)];
        rk[getfa(scc[tmp])] += rk[getfa(tmp)];
        fa[getfa(tmp)] = getfa(scc[tmp]);
      }
    }
    ans[l] = ans[l - 1] + q1;
  }  else {
    vector <int> el, er;
    for(int i = 0; i < e.size(); i++) {
      int tx = getfa(x[e[i]]), ty = getfa(y[e[i]]);
      if(col[tx] == tot && col[ty] == tot && scc[tx] == scc[ty]) {
        el.push_back(e[i]);
      }  else er.push_back(e[i]);
    }
    work(l, mid, el);  work(mid + 1, r, er);
  }
}
signed main () {
  n = read(), m = read();
  for(int i = 1; i <= n + m; i++) rk[i] = 1, fa[i] = i;
  for(int i = 1; i <= m; i++) x[i] = read(), y[i] = read();
  for(int i = 1; i <= m; i++) tmp.push_back(i);
  work(1, m, tmp);
  for(int i = 1; i <= m; i++) cout << ans[i] << "\n";
  return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 468ms
memory: 83916kb

Test #2:

score: 0
Accepted
time: 524ms
memory: 82732kb

Test #3:

score: 0
Accepted
time: 499ms
memory: 85228kb

Test #4:

score: 0
Accepted
time: 432ms
memory: 89996kb

Test #5:

score: 0
Accepted
time: 497ms
memory: 84396kb

Test #6:

score: 0
Accepted
time: 506ms
memory: 84064kb

Test #7:

score: 0
Accepted
time: 529ms
memory: 82360kb

Test #8:

score: 0
Accepted
time: 532ms
memory: 82464kb

Test #9:

score: 0
Accepted
time: 451ms
memory: 91372kb

Test #10:

score: 0
Accepted
time: 511ms
memory: 83464kb

Test #11:

score: 0
Accepted
time: 497ms
memory: 84772kb

Test #12:

score: 0
Accepted
time: 495ms
memory: 82912kb

Test #13:

score: 0
Accepted
time: 368ms
memory: 92384kb

Test #14:

score: 0
Accepted
time: 365ms
memory: 91816kb

Test #15:

score: 0
Accepted
time: 200ms
memory: 68640kb

Test #16:

score: 0
Accepted
time: 414ms
memory: 72564kb

Test #17:

score: 0
Accepted
time: 434ms
memory: 72324kb

Test #18:

score: 0
Accepted
time: 453ms
memory: 72080kb

Test #19:

score: 0
Accepted
time: 524ms
memory: 83136kb

Test #20:

score: 0
Accepted
time: 459ms
memory: 86580kb

Test #21:

score: 0
Accepted
time: 394ms
memory: 86636kb

Test #22:

score: 0
Accepted
time: 444ms
memory: 86708kb

Test #23:

score: 0
Accepted
time: 425ms
memory: 86896kb

Test #24:

score: 0
Accepted
time: 431ms
memory: 86228kb

Test #25:

score: 0
Accepted
time: 425ms
memory: 85924kb

Test #26:

score: 0
Accepted
time: 436ms
memory: 85836kb

Test #27:

score: 0
Accepted
time: 447ms
memory: 84632kb