#P7602. [THUPC 2021] 视频倍增期

[THUPC 2021] 视频倍增期

Description

To better measure video quality, Kuaishou’s product manager proposed the concept of a video “doubling period”. The doubling period is a time metric measured in seconds. It means the time it takes for a video’s cumulative views to increase from only half of the current value to the current total views. Low-quality videos often start strong but fade quickly: right after release, people click out of curiosity or because the title is attractive, but after some time the reputation drops sharply, so the doubling period is long. High-quality videos often start slow but grow later: after watching, people share and recommend it on their own, gradually building reputation and traffic, so the doubling period is shorter.

Xiaozhang is a backend administrator at Kuaishou. There are nn videos monitored by Xiaozhang, numbered from 11 to nn. Xiaozhang has mm seconds of work time in a week. Each second, there is one request from the frontend to be processed. Requests are of two types:

  • Update request: during this second, all videos with indices in the interval [l,r][l, r] gain xx views, and the backend data needs to be updated.
  • Query request: the frontend wants to know the doubling period of video ii. Suppose the current cumulative views of this video in this week is xx, and this query is sent at second jj. Let jj' be the second when the cumulative views of this video in this week first reaches x/2\lceil x / 2 \rceil (with j0j' \ge 0). Then the doubling period is defined as jjj - j'.

Faced with such frequent updates and queries, Xiaozhang finds it difficult and hopes for your help.

Input Format

The first line contains two positive integers nn and mm, with 1n,m1051 \le n, m \le {10}^5.

The next mm lines describe the requests. Line jj represents the request at second jj (1jm1 \le j \le m), and is in one of the following formats:

  • 0 l r x0 \ l \ r \ x: this is an update request. At second jj, videos with indices in [l,r][l, r] (1lrn1 \le l \le r \le n) each gain xx views. It is guaranteed that 1x1081 \le x \le {10}^8.
  • 1 i1 \ i: this is a query request. Query the doubling period of video ii (1in1 \le i \le n) at second jj.

Output Format

For each query request, output one line in order, giving the requested doubling period.

5 5
0 2 3 3
1 4
0 2 4 3
1 4
1 3

2
1
4

Hint

Sample Explanation

  • At second 22, the cumulative views of video 44 is 00. It reached the cumulative views 0/2=0\lceil 0 / 2 \rceil = 0 at second 00, so its doubling period at this time is 22 seconds.
  • At second 44, the cumulative views of video 44 is 33. It reached the cumulative views 3/2=2\lceil 3 / 2 \rceil = 2 at second 33, so its doubling period at this time is 11 second.
  • At second 55, the cumulative views of video 33 is 66. It reached the cumulative views 6/2=3\lceil 6 / 2 \rceil = 3 at second 11, so its doubling period at this time is 44 seconds.

Source

From the 2021 Tsinghua University Programming Contest and Collegiate Invitational (THUPC2021).

Resources such as editorial(s) can be found at https://github.com/yylidiw/thupc_0/tree/master.

Translated by ChatGPT 5