Under construction

Still being built. Things may change

Progression

Time limit1sMemory limit1024 MB

Summary
Given N mission difficulties with range updates that add or assign arithmetic progressions, find the longest arithmetic run inside a query range.
Level

Hard8 of 10

Topics
Segment tree, Array, Implementation
Solved
No attempts yet

Problem

Damian is making a video game with NN missions. The initial difficulty of mission ii is DiD_i. The game can be played both forwards and backwards. Damian performs two kinds of operations. A patch operation is given as 11, LL, RR, SS, CC, and it increases the difficulty of every mission ii with L≤i≤RL \le i \le R by S+(i−L)×CS + (i - L) \times C. A rewrite operation is given as 22, LL, RR, SS, CC, and it sets the difficulty of every mission ii with L≤i≤RL \le i \le R to S+(i−L)×CS + (i - L) \times C.

Playable segments and queries

Missions aa through bb (where 1≤a≤b≤N1 \le a \le b \le N) form a playable segment if there is an integer kk such that Di+1−Di=kD_{i+1} - D_i = k for every a≤i<ba \le i < b. The value kk may be zero or negative. A single mission is a playable segment of length 11. An evaluate query is given as 33, LL, RR. For that query, find the length of the longest playable segment inside missions LL through RR, using the difficulties at that moment.

Examples5

  1. Example 1

    Input
    10 6
    1 2 3 4 1 2 3 4 5 5
    3 1 10
    1 1 4 -1 -1
    3 1 10
    3 9 10
    2 5 10 -2 -2
    3 1 10
    
    Expected output
    5
    6
    2
    7
    
  2. Example 2

    Input
    10 5
    1 2 3 4 1 2 3 4 5 5
    3 1 10
    1 1 10 1 2
    3 1 10
    2 1 10 3 4
    3 1 10
    
    Expected output
    5
    5
    10
    
  3. Example 3

    Input
    10 5
    1 2 3 4 1 2 3 4 5 5
    3 1 4
    3 4 5
    3 2 4
    3 5 9
    3 10 10
    
    Expected output
    4
    2
    3
    5
    1
    
  4. Example 4

    Input
    10 5
    1 2 3 4 1 2 3 4 5 5
    2 10 10 6 1
    3 5 10
    1 5 5 4 1
    3 1 5
    3 1 6
    
    Expected output
    6
    5
    5
    
  5. Example 5

    Input
    10 5
    1 2 3 4 1 2 3 4 5 5
    1 1 4 -1 -1
    3 1 5
    3 4 5
    1 5 10 -1 -1
    3 1 10
    
    Expected output
    4
    2
    9