electicode
HomeCoursesResourcesProblemsNational OlympiadContestsLeaderboard
...

Boring Data Structure

Time Limit: 1000msMemory Limit: 256MB
View EditorialView Submissions

Problem Description

Firdavs started studying data structures, in particular those that allow performing operations on segments and answering queries about the value of an element at a given position. To make it more interesting for Firdavs, Khaled complicated the task by adding a query to swap two elements at different positions. Firdavs was able to solve this problem --- can you?

You are given numbers NNN, QQQ, and an array AAA of size NNN. Write a program that processes QQQ operations of the following types:

  • 1  i1\; i1i --- output the value of the element at position iii;
  • 2  i  j2\; i\; j2ij --- swap the values of the elements at positions iii and jjj;
  • 3  l  r  x3\; l\; r\; x3l --- increase by all elements in the segment from to inclusive.

Input

In the first line, there are two integers NNN and QQQ (2≤N,Q≤3⋅105)(2 \le N, Q \le 3 \cdot 10^5)(2≤N,Q≤3⋅105).

In the second line, the elements of the array are written A1,  A2,  …,  ANA_1,\; A_2,\; \ldots,\; A_NA1​,A2​,…,AN​ (1≤Ai≤.

In the next QQQ lines, the operations are given in the following format:

  • 1  i1\; i1i (1≤i≤N)(1 \le i \le N)(1≤i≤N) --- query for the value of the element at position iii;
  • 2  i  j2\; i\; j2ij (1≤i,j≤N,  i --- swap the values of the elements at positions and ;

Output

For each query of type 111, output the value of the element at position iii on a separate line.

Scoring System

GroupAdditional constraintsPointsRequired subtasks
0Tests from examples0—
1Only operations of type 1,  21,\; 21,27—
2Only operations of type 1,  31,\; 31,329—

Examples

Example 1
Input
2 5
26 26
3 1 2 1999
3 1 1 1
2 1 2
1 1
1 2
Output
2025
2026

© 2026 Electicode. All rights reserved.

r
x
xxx
lll
rrr
106)(1 \le A_i \le 10^6)
(1≤Ai​≤106)
≠j)(1 \le i, j \le N,\; i \ne j)
(1≤i,j≤N,i=j)
iii
jjj
  • 3  l  r  x3\; l\; r\; x3lrx (1≤l≤r≤N,  1≤x≤106)(1 \le l \le r \le N,\; 1 \le x \le 10^6)(1≤l≤r≤N,1≤x≤106) --- increase by xxx all elements in the segment from lll to rrr.
  • 3N,Q≤2000N, Q \le 2000N,Q≤2000170
    4No additional constraints470, 1, 2, 3