This page is still under construction.

Parts of this page are still being built. What you see may change.

Friends

Time limit2sMemory limit1024 MB

Summary
Friends occupy squares on a line; a jump moves one friend to an empty square, and after each move a query asks for the sum over all friends of the length of their contiguous block.
Level

Medium7 of 10

Topics
Intervals, Implementation, Sorting, Math
Solved
No attempts yet

Problem

NN friends are playing a game. The game is played on a row of LL squares, numbered from 00 to L−1L - 1, where squares ii and i+1i+1 are adjacent to each other. At most one friend stands on each square at any given time. In each step of the game, one friend jumps from its current square to a new (non-occupied) square.

At any moment of the game, the score of a friend is the length of the longest contiguous segment of friends it is part of. This means that if a friend stands on some position xx, and there are friends on positions a,a+1,...,x−1,x,x+1,...,b−1,ba, a + 1, ..., x - 1, x, x + 1, ..., b - 1, b, the score of the friend is b−a+1b - a + 1.

The total score of the game is the sum of scores for all friends. At various times during the game, the friends wonder what their current total score is.

Input

The judge reads input in the following format:

  • line 11: N L Q
  • line 22: P[0] P[1] .. P[N - 1]
  • lines 33 to 3+Q−13 + Q - 1: each line represents either a jump or a score question. If the line is 0 A B, a jump from AA to BB is to be made, and if the line is 1 a scoring question is to be made.

Output

For each scoring question, the judge writes a line with the return value of score().

Constraints

  • 1≤N≤100 0001 \le N \le 100\,000
  • 1≤L≤1091 \le L \le 10^9
  • S+J≤200 000S + J \le 200\,000

Examples1

  1. Example 1

    Input
    3 7 5
    1 3 4
    1
    0 4 2
    1
    0 3 0
    1
    
    Expected output
    5
    9
    9