Secret Lilies and Roses

시간 제한2초메모리 제한2048 MB

요약
숨겨진 이진 문자열에서 특정 위치의 문자를 묻는 질의와 접두 백합 수 곱하기 접미 장미 수를 묻는 질의를 사용해 두 수가 같은 위치를 찾는다.
난이도

어려움10점 중 8점

유형
이분 탐색, 구현, 수학, 구간
정답자
아직 제출이 없습니다

문제

There are nn flowers arranged in a line from left to right, which are numbered from 11 to nn in that order. Each flower is either a lily or a rose. For an integer jj between 00 and nn, inclusive, let l_jl\_j denote the number of lilies among the leftmost jj flowers, and let r_jr\_j denote the number of roses among the rightmost n−jn − j flowers.

Initially, only the number of flowers nn is provided to you. The types of the flowers are hidden. You can obtain information on the flowers by making queries. In one query, you can perform one of the following.

Type query: Specify an integer ii between 11 and nn, inclusive. You will then receive the type of flower ii.

Multiply query: Specify an integer jj between 00 and nn, inclusive. You will then receive the value of l_j×r_jl\_j \times r\_j.

Your task is to find an integer kk between 00 and nn, inclusive, for which l_k=r_kl\_k = r\_k by making a limited number of queries. You can assume that at least one such integer exists for the arrangement of the flower types. Note that you do not need to identify the type of each flower.

예제1

  1. 예제 1

    입력
    2
    9
    
    lily
    
    rose
    
    6
    
    3
    
    3
    
    0
    
    rose
    
    
    예상 출력
    
    
    type 8
    
    type 1
    
    multi 6
    
    multi 3
    
    answer 5
    
    multi 3
    
    type 3
    
    answer 3