Under construction

Still being built. Things may change

Drainage

Interview

Time limit1sMemory limit1024 MB

Summary
Merge cities into groups with each project query, then count the cities in groups whose total rainfall exceeds their total drainage capacity.
Level

Medium4 of 10

Topics
Union-find, Array, Implementation
Solved
No attempts yet

Problem

The ChAOS country has NN cities, numbered 11 through NN. Each city has a drainage ditch that prevents flooding. The drainage ditch of city ii can prevent flooding only when the rainfall is at most AiA_i.

To prepare for heavy rain in a single city, the country decides to build a project that pools the drainage capacity of two cities. For example, after building the project on cities 11 and 22, if the sum of the rainfall of cities 11 and 22 is at most A1+A2A_1 + A_2, both cities 1 and 2 are protected from flooding. Otherwise, both cities flood. If the project is then built on cities 22 and 33 as well, and the sum of the rainfall of cities 11, 22, and 33 is at most A1+A2+A3A_1 + A_2 + A_3, all three cities are protected. Otherwise, all three cities flood.

Heavy rain is now falling across the country. The current rainfall of city ii is BiB_i. Write a program that processes two kinds of queries.

  • 11 xx yy: Build the project on city xx and city yy.
  • 22: Print the number of cities that flood in the current state.

There is at least one query of type 22.

Input

The first line contains the number of cities NN (3≤N≤1000003 \le N \le 100000) and the number of queries MM (1≤M≤1000001 \le M \le 100000).

The second line contains NN integers A1,A2,…,ANA_1, A_2, \ldots, A_N (0≤Ai≤10000 \le A_i \le 1000).

The third line contains NN integers B1,B2,…,BNB_1, B_2, \ldots, B_N (0≤Bi≤10000 \le B_i \le 1000).

From the fourth line through line M+3M + 3, each line contains one query in the form 11 xx yy or 22 (1≤x,y≤N1 \le x, y \le N).

Output

For each query of type 22, print the answer on its own line.

Examples2

  1. Example 1

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

    Input
    5 6
    1 1 1 1 1
    5 0 0 0 0
    1 1 2
    1 2 4
    2
    1 3 5
    1 3 4
    2
    
    Expected output
    3
    0