RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
USACO0502

Farm Updates

Platinum II 플래티넘 II
난이도
2s
시간 제한
256MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

Farmer John operates a collection of \(N\) farms (\(1\le N\le 10^5\)), conveniently
numbered \(1\ldots N\). Initially, there are no roads connecting these farms to
each-other, and each farm is actively producing milk.

Due to the dynamic nature of the economy, Farmer John needs to make changes to
his farms according to a series of \(Q\) update operations
(\(0\le Q\le 2\cdot 10^5\)). Update operations come in three possible forms:

  • (D x) Deactivate an active farm \(x\), so it no longer produces milk.
  • (A x y) Add a road between two active farms \(x\) and \(y\).
  • (R e) Remove the \(e\)th road that was previously added (\(e = 1\) is the first road that was added).

A farm \(x\) that is actively producing milk, or that can reach another active
farm via a series of roads, is called a "relevant" farm. For each farm \(x\),
please calculate the maximum \(i\) (\(0\le i\le Q\)) such that \(x\) is relevant
after the \(i\)-th update.

Problem credits: Benjamin Qi

제약

SCORING

  • Tests 2 through 5 satisfy \(N\le 10^3\), \(Q\le 2\cdot 10^3\)
  • Test cases 6 through 20 satisfy no additional constraints.

Problem credits: Benjamin Qi

입력 형식

The first line of input contains \(N\) and \(Q\). The next \(Q\) lines each contain an update of one of the following forms:

D x
A x y
R e

It is guaranteed that for updates of type R, \(e\) is at most the number of roads
that have been added so far, and no two updates of type R have the same value of
\(e\).

출력 형식

Please output \(N\) lines, each containing an integer in the range \(0\ldots Q\).

예제 1
입력
5 9
A 1 2
A 2 3
D 1
D 3
A 2 4
D 2
R 2
R 1
R 3
출력
7
8
6
9
9
설명

In this example, roads are removed in the order \((2,3), (1,2), (2,4)\).

  • Farm \(1\) is relevant just before \((1,2)\) is removed.
  • Farm \(2\) is relevant just before \((2,4)\) is removed.
  • Farm \(3\) is relevant just before \((2,3)\) is removed.
  • Farms \(4\) and \(5\) are still active after all queries. Therefore they both stay relevant, and the output for both should be \(Q\).
문제 정보

riseoj 작성

출처 올림피아드 > USACO > 2021-2022 > January > Gold

태그

평가 및 의견

Farm Updates

개요
출제자 난이도 Platinum II 플래티넘 II 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Farm Updates

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8