Logo
(追記) (追記ここまで)

28222번 - Sequence 서브태스크다국어언어 제한함수 구현

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1.5 초 1024 MB50161431.818%

문제

In the enchanting realm of APIO, there lived a young and brilliant student named Alice. Alice had an insatiable curiosity for solving intriguing problems that challenged her mathematical prowess. One day, she stumbled upon a mystical series of numbers with a length of $N$ (that is $A[0],ドル $A[1],ドル $\cdots,ドル $A[N - 1]$), and she couldn't resist the allure of exploring its secrets.

Here, she wants to share with you some of her discoveries. But before that, for your convenience, we need to define some things:

  • Define $W(l, r,x)$ as $\displaystyle\sum_{i=l}^{r}{\mathrm{I}[A[i] = x]},ドル i.e., the number of occurrences of $x$ in $A[l] \cdots A[r]$.
  • Define the set of medians of a non-empty integer sequence $B[0]$ $B[1]$ $\cdots$ $B[k - 1]$ as $S(\{B[0], B[1], \cdots ,B[k - 1]\}),ドル and in the following Alice will show you how to calculate the set of medians step-by-step:
    • First, sort the elements $B[0], B[1], \cdots ,B[k - 1]$ in ascending order to obtain the sequence $C[0], C[1], \cdots ,C[k - 1]$.
    • Then, $S(\{B[0], B[1], \cdots ,B[k - 1]\}) = \{C[\lfloor \frac{k-1}{2} \rfloor ], C[\lceil \frac{k-1}{2} \rceil ] \}$.
    • To enhance your understanding of the calculation of S,ドル let's consider a few examples:
      • $S(\{6, 3, 5, 4, 6, 2, 3\}) = \{4\}$.
      • $S(\{4, 2, 3, 1\}) = \{2, 3\}$.
      • $S(\{5, 4, 2, 4\}) = \{4\}$.

Alice is eager to find the maximum value of $\displaystyle\max_{x \in S(l,r)}{W(l, r,x)},ドル where 0ドル ≤ l ≤ r ≤ N - 1,ドル as it poses a challenging task. The term $S(l, r)$ represents the set of medians derived from $A[l] \cdots A[r]$ (as previously mentioned as $S(A[l], \cdots ,A[r])$). Although Alice has already obtained the answer, she seeks assistance in verifying it and kindly requests your help in programming the calculation.

구현

You should implement the following procedure:

int sequence(int N, std::vector<int> A);
  • $N$: the length of sequence $A$.
  • $A$: array of length $N,ドル describing the sequence $A$.
  • This procedure should return an integer representing the maximum value among all possible pairs $(l, r)$.
  • This procedure is called exactly once.

입력

출력

제한

  • 1ドル ≤ N ≤ 5 \times 10^5$
  • 1ドル ≤ A[i] ≤ N$

예제 1

Consider the following call:

sequence(7, {1, 2, 3, 1, 2, 1, 3});

This procedure should return 3ドル$.

In this case, $S(0, 5) = \{1, 2\},ドル $W(0, 5, 1) = 3,ドル $W(0, 5, 2) = 2$. So the value of $(0, 5)$ is 3ドル$.

It is easy to verify that $(0, 5)$ has the greatest value among all possible pairs.

예제 2

Consider the following call:

sequence(9, {1, 1, 2, 3, 4, 3, 2, 1, 1});

This procedure should return 2.

예제 3

Consider the following call:

sequence(14, {2, 6, 2, 5, 3, 4, 2, 1, 4, 3, 5, 6, 3, 2});

This procedure should return 3ドル$.

서브태스크

번호배점제한
111

$N ≤ 100$.

217

$N ≤ 2 \times 10^3$.

37

There exists an $x$ that satisfy $∀0 ≤ i < x, A[i] ≤ A[i + 1]$ and $∀x < i < N, A[i] ≤ A[i - 1]$.

412

$A[i] ≤ 3$.

513

$W(0, N - 1,A[i]) ≤ 2$ (for each $i$ such that 0ドル ≤ i ≤ N - 1$)

622

$N ≤ 8 × 10^4$.

718

No additional constraints.

힌트

샘플 그레이더

The sample grader reads input in the following format:

  • Line 1ドル$: $N$
  • Line 2ドル$: $A[0]$ $A[1]$ $\cdots$ $A[N - 1]$.

The sample grader prints your output in the following format:

  • Line 1ドル$: the return value of sequence.

출처

Olympiad > Asia-Pacific Informatics Olympiad > APIO 2023 B번

제출할 수 있는 언어

C++17, C++20, C++17 (Clang), C++20 (Clang)

채점 및 기타 정보

  • 예제는 채점하지 않는다.
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /