#P15583. [KTSC 2026] 通信网络 2 / Communication Network 2

    ID: 17420 远端评测题 6000ms 1024MiB 尝试: 0 已通过: 0 显示难度NOI/NOI+/CTS 上传者: 标签>交互题2026KTSC(韩国)

[KTSC 2026] 通信网络 2 / Communication Network 2

Background

Note: You can get more sample tests in the attachments.

Problem Description

There is an undirected graph with NN vertices, numbered 0∼N−10 \sim N-1. There are no self-loops in this graph. Initially, the graph has no edges.

You are given TT edge sets E0,…,ET−1E_0,\ldots,E_{T-1}. For u=0,1,⋯ ,T−1u=0,1,\cdots,T-1, at time u+0.5u+0.5, take the XOR (symmetric difference) of EuE_u and the current edge set of the graph. In other words, let the current edge set be EE, and for every e∈Eue\in E_u:

  • If ee is in EE, delete ee from EE.
  • Otherwise, add ee to EE.

For a non-negative integer tt and two vertices a,ba,b, we say that a,ba,b are connected at time t\boldsymbol{t} if and only if at time tt there exists a path connecting aa and bb. In particular, if a=ba=b, then by definition this statement is always true for any tt.

Furthermore, for integers 0≤l≤r≤T0\le l\le r\le T and two vertices a,ba,b, we say that a,ba,b are connected during the time interval [l,r]\boldsymbol{[l,r]} if and only if a,ba,b are connected at every time t=l,l+1,…,rt=l,l+1,\ldots,r.

There are QQ queries. Each query gives x,l,rx,l,r. Return the number of vertices yy such that x,yx,y are connected during the time interval [l,r][l,r] (0≤x≤N−10\le x\le N-1, 0≤l≤r≤T0\le l\le r\le T, 0≤y≤N−10\le y\le N-1).

Implementation Details

This is a functional interactive problem. You do not need to, and should not, implement the main function.

You should implement the following function:

vector<int> count_computers(int N, int T, int Q, vector<vector<array<int, 2>>> E, vector<array<int, 3>> F)
  • EE: an array storing the edge sets. The size of EE is TT. Each E[i]E[i] is a non-empty edge array representing the set EiE_i. Each edge is given as an array of size 22, with elements [a,b][a,b] in order, representing an edge connecting vertices aa and bb.
  • FF: an array storing the queries. The size of FF is QQ. For any 0≤i≤Q−10\le i\le Q-1, F[i]F[i] represents the ii-th query. Each query is given as an array of size 33, with elements [x,l,r][x,l,r] in order, where xx is a vertex and [l,r][l,r] is a time interval.
  • Return an array RR of size QQ. For any 0≤j≤Q−10\le j\le Q-1, R[j]R[j] is the answer to the jj-th query.
  • This function is called exactly once.

Your source code must not call any input/output functions.

Input Format

The input format of the sample grader program is as follows. ∣Ei∣|E_i| denotes the size of the set EiE_i, and S=∑0≤i≤T−1∣Ei∣S = \sum_{0 \le i \le T-1} |E_i|.

  • Line 11: NN TT QQ.
  • For all 0≤i≤T−10 \le i \le T-1:
    • Line 2+∑0≤j<i(1+∣Ej∣)2 + \sum_{0 \le j < i} (1 + |E_j|): ∣Ei∣|E_i|.
    • Line 2+∑0≤j<i(1+∣Ej∣)+k2 + \sum_{0 \le j < i} (1 + |E_j|) + k (0≤k<∣Ei∣−10 \le k < |E_i| - 1): a ba \ b (the two endpoints of the kk-th edge in EiE_i).
  • Line 2+S+T+i2 + S + T + i (0≤i≤Q−10 \le i \le Q - 1): x l rx \ l \ r (each element of F[i]F[i]).

Output Format

The sample grader program outputs the answers in the following format:

  • Line 1+i1 + i (0≤i≤Q−10 \le i \le Q - 1): R[i]R[i].
4 5 7
2
0 1
1 2
2
2 3
1 3
2
0 1
0 3
4
0 1
1 2
0 3
2 3
1
1 3
1 1 1
2 2 2
3 3 3
0 0 5
2 1 3
1 1 4
3 2 3

3
4
4
1
3
2
4

Hint

Constraints

  • 2≤N≤100 0002\le N\le 100\, 000.
  • 1≤T≤100 0001\le T\le 100\, 000.
  • 1≤Q≤250 0001\le Q\le 250\, 000.
  • EiE_i is an edge set, and all edges inside it are pairwise distinct.
  • Let S=∑0≤i<T−1∣Ei∣S=\sum_{0\le i\lt T-1} |E_i|, then S≤100 000S\le 100\, 000.
  • For every edge [a,b][a,b] given in the input, 0≤a<b≤N−10\le a\lt b\le N-1.
  • For every query given in the input, 0≤x≤N−1,0≤l≤r≤T0\le x\le N-1,0\le l\le r\le T.

Subtasks

ID Score Limit
11 55 N,S,Q≤100N,S,Q\le 100
22 1212 N,S,Q≤5 000N,S,Q\le 5\, 000
33 1919 For all queries, l=rl=r
44 2323 For all edges [a,b][a,b] given in EE, ∣a−b∣=1\vert a-b\vert =1
55 4141 No additional constraints

Sample

Consider the following call.

count_computers(4, 5, 7, [[[0, 1], [1, 2]], [[2, 3], [1, 3]], [[0, 1], [0, 3]], [[0, 1], [1, 2], [0, 3], [2, 3]], [[1, 3]], [[1, 1], [2, 2], [3, 3], [0, 0], [0, 5]], [[2, 1, 3], [1, 1, 4], [3, 2, 3]]])

There are 44 vertices in the graph.

At each time, the graph is as follows:

  • At time 00: 00 edges.
  • At time 11: 22 edges: (0,1),(1,2)(0, 1), (1, 2).
  • At time 22: 44 edges: (0,1),(1,2),(2,3),(1,3)(0, 1), (1, 2), (2, 3), (1, 3).
  • At time 33: 44 edges: (1,2),(2,3),(1,3),(0,3)(1, 2), (2, 3), (1, 3), (0, 3).
  • At time 44: 22 edges: (0,1),(1,3)(0, 1), (1, 3).
  • At time 55: 11 edge: (0,1)(0, 1).

A total of 77 queries are given:

  • Query 00: At time 11, vertex 11 is connected to the set {0,1,2}\{0, 1, 2\}.
  • Query 11: At time 22, vertex 22 is connected to the set {0,1,2,3}\{0, 1, 2, 3\}.
  • Query 22: At time 33, vertex 33 is connected to the set {0,1,2,3}\{0, 1, 2, 3\}.
  • Query 33: Since there are no edges at time 00, from time 00 to 55, vertex 00 is only connected to vertex 00.
  • Query 44: From time 11 to 33, vertex 22 is connected to the set {0,1,2}\{0, 1, 2\}.
  • Query 55: From time 11 to 44, vertex 11 is connected to the set {0,1}\{0, 1\}.
  • Query 66: From time 22 to 33, vertex 33 is connected to the set {0,1,2,3}\{0, 1, 2, 3\}.

Therefore, the function should return [3,4,4,1,3,2,4][3, 4, 4, 1, 3, 2, 4].

You can get more sample tests in the attachments.

Translated by ChatGPT 5