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

It's Mooin' Time III

Bronze II 브론즈 II
난이도
2s
시간 제한
256MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

Elsie is trying to describe her favorite USACO contest to Bessie, but Bessie is
having trouble understanding why Elsie likes it so much. Elsie says "And It's
mooin' time! Who wants a mooin'? Please, I just want to do USACO".

Bessie still doesn't understand, so she transcribes Elsie's description in a
string of length \(N\) (\(3 \leq N \leq 10^5\)) containing lowercase alphabetic
characters \(s_1s_2 \ldots s_N\). Elsie considers a string \(t\) containing three
characters a moo if \(t_2 = t_3\) and \(t_2 \neq t_1\).

A triplet \((i, j, k)\) is valid if \(i < j < k\) and string \(s_i\ s_j\ s_k\) forms a
moo. For the triplet, FJ performs the following to calculate its value:

  • FJ bends string \(s\) 90-degrees at index \(j\)
  • The value of the triplet is twice the area of \(\Delta ijk\).

In other words, the value of the triplet is \((j-i)(k-j)\).

Bessie asks you \(Q\) (\(1 \leq Q \leq 3 \cdot 10^4\)) queries. In each query, she
gives you two integers \(l\) and \(r\) (\(1 \leq l \leq r \leq N\), \(r-l+1 \ge 3\)) and
ask you for the maximum value among valid triplets \((i, j, k)\) such that
\(l \leq i\) and \(k \leq r\). If no valid triplet exists, output \(-1\).

Note that the large size of integers involved in this problem may require the
use of 64-bit integer data types (e.g., a "long long" in C/C++).

Problem credits: Chongtian Ma

제약

SCORING

  • Inputs 2-3: \(N,Q\le 50\)
  • Inputs 4-6: \(Q=1\) and the singular query satisfies \(l=1\) and \(r=N\)
  • Inputs 7-11: No additional constraints

Problem credits: Chongtian Ma

입력 형식

The first line contains two integers \(N\) and \(Q\).

The following line contains \(s_1 s_2, \ldots s_N\).

The following \(Q\) lines contain two integers \(l\) and \(r\), denoting each query.

출력 형식

Output the answer for each query on a new line.

예제 1
입력
12 5
abcabbacabac
1 12
2 7
4 8
2 5
3 10
출력
28
6
1
-1
12
설명

For the first query, (\(i,j,k\)) must satisfy \(1 \le i < j < k \le 12\). It can be
shown that the maximum area of \(\Delta ijk\) for some valid (\(i,j,k\)) is achieved
when \(i=1\), \(j=8\), and \(k=12\). Note that \(s_1\ s_8\ s_{12}\) is the string "acc"
which is a moo according to the definitions above. \(\Delta ijk\) will have legs
of lengths \(7\) and \(4\) so two times the area of it will be \(28\).

For the third query, (\(i,j,k\)) must satisfy \(4 \le i < j < k \le 8\). It can be
shown that the maximum area of \(\Delta ijk\) for some valid (\(i,j,k\)) is achieved
when \(i=4\), \(j=5\), and \(k=6\).

For the fourth query, there exists no (\(i,j,k\)) satisfying
\(2 \le i < j < k \le 5\) in which \(s_i\ s_j\ s_k\) is a moo so the output to that
query is \(-1\).

문제 정보

riseoj 작성

출처 올림피아드 > USACO > 2024-2025 > US Open > Bronze

태그

평가 및 의견

It's Mooin' Time III

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

Log in to rate problems.

개별 의견

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

풀이 제출

It's Mooin' Time III

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