codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

1523B.md (3889B)


      1 Source: https://codeforces.com/problemset/problem/1523/B
      2 
      3 B. Lord of the Values
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 ![](https://espresso.codeforces.com/16b5b964dd8e62e0574290a998664c6e18c34884.png) 
     22 
     23 While trading on his favorite exchange trader William realized that he found a vulnerability. Using this vulnerability he could change the values of certain internal variables to his advantage. To play around he decided to change the values of all internal variables from $a_1, a_2, \ldots, a_n$ to $-a_1, -a_2, \ldots, -a_n$. For some unknown reason, the number of service variables is always an even number.
     24 
     25 William understands that with his every action he attracts more and more attention from the exchange's security team, so the number of his actions must not exceed $5\,000$ and after every operation no variable can have an absolute value greater than $10^{18}$. William can perform actions of two types for two chosen variables with indices $i$ and $j$, where $i \lt j$:
     26 
     27 1. Perform assignment $a_i = a_i + a_j$
     28 2. Perform assignment $a_j = a_j - a_i$
     29 
     30 William wants you to develop a strategy that will get all the internal variables to the desired values.
     31 
     32 Input
     33 
     34 Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 20$). Description of the test cases follows.
     35 
     36 The first line of each test case contains a single even integer $n$ ($2 \le n \le 10^3$), which is the number of internal variables.
     37 
     38 The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \le a_i \le 10^9)$, which are initial values of internal variables.
     39 
     40 Output
     41 
     42 For each test case print the answer in the following format:
     43 
     44 The first line of output must contain the total number of actions $k$, which the strategy will perform. Note that you do not have to minimize $k$. The inequality $k \le 5\,000$ must be satisfied.
     45 
     46 Each of the next $k$ lines must contain actions formatted as "type i j", where "type" is equal to "1" if the strategy needs to perform an assignment of the first type and "2" if the strategy needs to perform an assignment of the second type. Note that $i \lt j$ should hold.
     47 
     48 We can show that an answer always exists.
     49 
     50 Example
     51 
     52 Input
     53 
     54 ```
     55 2
     56 4
     57 1 1 1 1
     58 4
     59 4 3 1 2
     60 ```
     61 
     62 Output
     63 
     64 ```
     65 8
     66 2 1 2
     67 2 1 2
     68 2 1 3
     69 2 1 3
     70 2 1 4
     71 2 1 4
     72 1 1 2
     73 1 1 2
     74 8
     75 2 1 4
     76 1 2 4
     77 1 2 4
     78 1 2 4
     79 1 3 4
     80 1 1 2
     81 1 1 2
     82 1 1 4
     83 ```
     84 
     85 Note
     86 
     87 For the first sample test case one possible sequence of operations is as follows:
     88 
     89 1. "2 1 2". Values of variables after performing the operation: [1, 0, 1, 1]
     90 2. "2 1 2". Values of variables after performing the operation: [1, -1, 1, 1]
     91 3. "2 1 3". Values of variables after performing the operation: [1, -1, 0, 1]
     92 4. "2 1 3". Values of variables after performing the operation: [1, -1, -1, 1]
     93 5. "2 1 4". Values of variables after performing the operation: [1, -1, -1, 0]
     94 6. "2 1 4". Values of variables after performing the operation: [1, -1, -1, -1]
     95 7. "1 1 2". Values of variables after performing the operation: [0, -1, -1, -1]
     96 8. "1 1 2". Values of variables after performing the operation: [-1, -1, -1, -1]
     97 
     98 For the second sample test case one possible sequence of operations is as follows:
     99 
    100 1. "2 1 4". Values of variables after performing the operation: [4, 3, 1, -2]
    101 2. "1 2 4". Values of variables after performing the operation: [4, 1, 1, -2]
    102 3. "1 2 4". Values of variables after performing the operation: [4, -1, 1, -2]
    103 4. "1 2 4". Values of variables after performing the operation: [4, -3, 1, -2]
    104 5. "1 3 4". Values of variables after performing the operation: [4, -3, -1, -2]
    105 6. "1 1 2". Values of variables after performing the operation: [1, -3, -1, -2]
    106 7. "1 1 2". Values of variables after performing the operation: [-2, -3, -1, -2]
    107 8. "1 1 4". Values of variables after performing the operation: [-4, -3, -1, -2]