QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#887343#8809. Telephone Planswsyear0 14ms114408kbC++202.5kb2025-02-07 16:37:122025-02-07 16:37:19

Judging History

This is the latest submission verdict.

  • [2025-02-07 16:37:19]
  • Judged
  • Verdict: 0
  • Time: 14ms
  • Memory: 114408kb
  • [2025-02-07 16:37:12]
  • Submitted

answer

#include <bits/stdc++.h>

#define rep(i, j, k) for (int i = (j); i <= (k); ++i)
#define per(i, j, k) for (int i = (j); i >= (k); --i)
#define SZ(v) int((v).size())
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
using ll = long long;
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;

template<class T> void chkmn(T &x, T y) { if (y < x) x = y; }
template<class T> void chkmx(T &x, T y) { if (y > x) x = y; }

using namespace std;

const int maxn = 1000010;

int n, m, ty, bel[maxn], fr[maxn], vis[maxn], tot;
ll pre[maxn], sum, lst;
set<int> e[maxn], S[maxn];
set<int>::iterator cur[maxn];
queue<int> qx, qy;

void flush(int x) {
  while (cur[x] != S[x].end() && vis[*cur[x]]) cur[x]++;
}

int main() {
  cin.tie(nullptr) -> ios::sync_with_stdio(false);
  cin >> ty >> n >> m;
  rep (i, 1, n) S[i].insert(i), bel[i] = i;
  tot = n;
  rep (i, 1, m) {
    int op;
    ll x, y;
    cin >> op >> x;
    if (op != 3) cin >> y;
    if (ty) x ^= lst, y ^= lst;
    pre[i] = pre[i - 1];
    if (op == 1) {
      e[x].insert(y), e[y].insert(x);
      sum += 1ll * SZ(S[bel[x]]) * SZ(S[bel[y]]);
      if (SZ(S[bel[x]]) < SZ(S[bel[y]])) swap(x, y);
      for (int o : S[bel[y]]) S[bel[x]].insert(o), bel[o] = bel[x];
    } else if (op == 2) {
      e[x].erase(y), e[y].erase(x);
      vector<int> vx, vy;
      fr[x] = -1, fr[y] = -1, qx.emplace(x), qy.emplace(y);
      while (!qx.empty() && !qy.empty()) {
        int u = qx.front();
        qx.pop(), vx.emplace_back(u), vis[u] = 1;
        cur[u] = e[u].begin(), flush(u), fr[u] != -1 ? flush(fr[u]) : void();
        if (cur[u] != e[u].end()) fr[*cur[u]] = u, qx.emplace(*(cur[u]++));
        if (fr[u] != -1 && cur[fr[u]] != e[fr[u]].end()) fr[*cur[fr[u]]] = fr[u], qx.emplace(*(cur[fr[u]]++));
        int v = qy.front();
        qy.pop(), vy.emplace_back(v), vis[v] = 1;
        cur[v] = e[v].begin(), flush(v), fr[v] != -1 ? flush(fr[v]) : void();
        if (cur[v] != e[v].end()) fr[*cur[v]] = v, qy.emplace(*(cur[v]++));
        if (fr[v] != -1 && cur[fr[v]] != e[fr[v]].end()) fr[*cur[fr[v]]] = fr[v], qy.emplace(*(cur[fr[v]]++));
      }
      if (!qx.empty()) swap(x, y), swap(vx, vy), swap(qx, qy);
      tot++;
      for (int o : vx) bel[o] = tot, S[bel[y]].erase(o), S[tot].insert(o);
      pre[i] += 1ll * SZ(S[bel[y]]) * SZ(S[tot]);
      for (int o : vx) vis[o] = 0;
      for (int o : vy) vis[o] = 0;
      while (!qy.empty()) qy.pop();
    } else {
      cout << (lst = sum - pre[max(0ll, i - x - 1)]) << '\n';
    }
  }
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 3
Accepted
time: 10ms
memory: 109664kb

input:

0
1 147
3 0
3 0
3 1
3 1
3 0
3 5
3 5
3 1
3 1
3 4
3 8
3 2
3 10
3 13
3 10
3 8
3 8
3 0
3 16
3 3
3 1
3 20
3 2
3 10
3 16
3 13
3 17
3 12
3 22
3 7
3 8
3 2
3 12
3 32
3 12
3 31
3 2
3 0
3 21
3 24
3 28
3 32
3 9
3 18
3 26
3 11
3 45
3 35
3 14
3 34
3 49
3 31
3 43
3 11
3 21
3 50
3 4
3 11
3 31
3 51
3 28
3 26
3 18
3 ...

output:

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

result:

ok 147 lines

Test #2:

score: 3
Accepted
time: 11ms
memory: 111988kb

input:

0
2 10
1 1 2
3 1
3 1
3 2
3 3
3 3
3 3
2 1 2
3 2
3 3

output:

1
1
1
1
1
1
1
1

result:

ok 8 lines

Test #3:

score: 0
Wrong Answer
time: 12ms
memory: 112364kb

input:

0
30 150
1 14 10
3 1
1 14 6
1 3 6
3 4
3 4
1 2 3
3 0
3 5
1 2 9
1 11 9
3 8
1 19 11
3 6
1 8 19
3 14
3 10
1 27 8
3 15
1 27 28
1 28 20
3 0
3 3
1 20 7
1 7 23
3 13
3 5
1 24 23
3 0
3 28
1 24 13
3 5
3 32
3 1
3 13
1 30 13
3 25
1 30 16
1 15 16
3 22
1 29 15
3 13
1 29 25
1 25 1
1 1 18
3 17
3 8
3 10
1 26 18
3 46
...

output:

1
6
6
10
10
21
28
36
36
45
66
66
91
91
105
105
120
120
120
120
136
171
190
253
253
253
276
276
300
300
300
325
351
351
351
351
406
406
435
435
435
435
435
406
435
435
435
300
435
435
435
435
435
153
435
190
435
435
435
136
406
120
120
136
120
435
435
276
435
66
435
435
435
91
435
435
28
435
55
55
43...

result:

wrong answer 51st lines differ - expected: '406', found: '435'

Subtask #2:

score: 0
Wrong Answer

Test #29:

score: 2
Accepted
time: 14ms
memory: 109704kb

input:

1
1 147
3 0
3 0
3 1
3 1
3 3
3 0
3 6
3 6
3 0
3 2
3 0
3 5
3 12
3 1
3 2
3 10
3 13
3 15
3 3
3 12
3 20
3 18
3 10
3 12
3 2
3 12
3 14
3 26
3 12
3 24
3 7
3 7
3 6
3 29
3 32
3 16
3 23
3 14
3 25
3 13
3 13
3 31
3 20
3 26
3 0
3 40
3 23
3 28
3 35
3 1
3 31
3 2
3 34
3 37
3 3
3 39
3 17
3 4
3 41
3 11
3 16
3 48
3 10
3...

output:

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

result:

ok 147 lines

Test #30:

score: 2
Accepted
time: 11ms
memory: 111612kb

input:

1
2 10
1 1 2
3 1
3 1
3 1
3 1
3 1
3 2
3 6
2 0 3
3 2

output:

1
1
1
1
1
1
1
1

result:

ok 8 lines

Test #31:

score: 0
Wrong Answer
time: 11ms
memory: 114408kb

input:

1
30 150
1 21 13
3 1
1 9 20
3 2
3 2
1 18 11
1 18 0
3 6
3 9
3 8
1 12 9
3 8
3 7
1 10 9
3 5
3 24
3 26
3 28
1 6 16
3 6
3 14
1 15 23
3 21
3 48
1 60 47
3 53
3 37
1 35 53
3 56
1 57 59
1 59 37
3 63
3 95
3 94
1 92 79
3 65
1 90 81
1 95 81
3 75
3 111
3 118
3 100
1 124 98
1 101 98
3 121
3 132
3 137
3 153
1 141 ...

output:

1
3
3
10
10
10
15
15
21
21
21
21
28
28
36
36
45
45
55
78
78
78
91
120
120
120
120
153
153
153
153
171
171
190
190
210
231
231
253
253
253
276
300
300
325
325
351
351
406
406
406
435
435
435
435
435
435
435
435
435
435
435
435
435
435
435
435
435
435
435
435
435
276
435
435
435
435
435
153
435
435
12...

result:

wrong answer 79th lines differ - expected: '136', found: '153'

Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 0
Skipped

Dependency #2:

0%

Subtask #5:

score: 0
Skipped

Dependency #3:

0%

Subtask #6:

score: 0
Skipped

Dependency #4:

0%

Subtask #7:

score: 0
Skipped

Dependency #6:

0%