아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Video Reviews - 2

시간 제한4초메모리 제한512 MB

요약
블로거를 정해진 순서로 처리할 때, 관심이 없어도 이미 올라온 리뷰가 a_i개 이상이면 리뷰를 남긴다. m개 이상의 리뷰를 얻기 위해 설득해야 하는 최소 인원을 구한다. 배열은 LCG로 생성되며 길이는 최대 5e7이다.
난이도

보통10점 중 7점

유형
그리디, 이분 탐색, 정렬, 구현
정답자
아직 제출이 없습니다

문제

Easy problem, just binary search the answer. Oh wait...

You

The studio "Lodka Gaming" is engaged in advertising of their new game ".C.O.N.T.E.S.T: Unexpected Behaviour". The studio's marketer is planning to communicate with nn videobloggers one by one (in the predetermined order, starting from the 1-st and ending with the nn-th), offering them to record a video review on the game. All people are different and videobloggers are as well, therefore the ii-th videoblogger will record a review in two cases: either he is interested in this game, or there are already at least a_ia\_i video reviews on this game.

The studio wants to have at least mm video reviews in the Internet. The game designer of "Lodka Gaming" understands these video reviews possibly would not appear by themselves, so he wants to convince some video bloggers that they are actually interested in this game. Which minimal number of videobloggers are needed to be convinced?

입력

The first line contains two integers nn and mm (1≤n≤5⋅107,1≤m≤n1 \le n \le 5 \cdot 10^7, 1 \le m \le n) --- the number of videobloggers and the required number of video reviews.

As nn can be too large, the a_ia\_i values will be generated by linear congruential random number generators.

The second line contains two integers a_1a\_1 and kk (0≤a_i≤5⋅107,0≤k≤1050 \le a\_i \le 5 \cdot 10^7, 0 \le k \le 10^5).

Each of the following kk lines contains 4 integers c_jc\_j, x_jx\_j, y_jy\_j and z_jz\_j (1≤c_j<5⋅107,1≤z_j≤5⋅107,1≤x_j<z_j,0≤y_j<z_j1 \le c\_j < 5 \cdot 10^7, 1 \le z\_j \le 5 \cdot 10^7, 1 \le x\_j < z\_j, 0 \le y\_j < z\_j). z_jz\_j are prime numbers. All a_ia\_i, except the first one, will be generated using these numbers. The first c_1c\_1 of them will be generated using the formula a_i=(x_1⋅a_i−1+y_1)mod  z_1a\_i = (x\_1 \cdot a\_{i-1} + y\_1) \mod z\_1, the next c_2c\_2 --- using the formula a_i=(x_2⋅a_i−1+y_2)mod  z_2a\_i = (x\_2 \cdot a\_{i-1} + y\_2) \mod z\_2, and so on. It is guaranteed that the sum of all c_jc\_j is n−1n-1.

출력

Output a single integer --- the minimal number of videobloggers who have to be convinced to record a video review on the game in order to achieve at least mm total video reviews in the Internet.

힌트

In the first sample, a=\[2,1,3,3,4,2,3]a = \[2, 1, 3, 3, 4, 2, 3].

In the second sample, a=\[2,1,3,3,4,3,2]a = \[2, 1, 3, 3, 4, 3, 2].

예제2

  1. 예제 1

    입력
    7 4
    2 6
    1 1 49999990 49999991
    1 1 2 49999991
    1 1 0 49999991
    1 1 1 49999991
    1 1 49999989 49999991
    1 1 1 49999991
    
    예상 출력
    1
    
  2. 예제 2

    입력
    7 4
    2 5
    1 1 96 97
    1 1 2 97
    1 1 0 97
    1 1 1 97
    2 1 96 97
    
    예상 출력
    2