Codevs2018 anti-virus software

Source: Internet
Author: User

2018 Anti-virus software

time limit: 1 s

space limit: 128000 KBtitle level: Diamonds DiamondView Run ResultsTitle Description Description

In fact, this "anti-virus Software" (anti-virus software), is the relevant department to deal with the h9n7 people influenza research and development.

There are only n cities in the monitoring area of the relevant department, numbered from 1 to N. Initially, none of these cities had any cases. As too many cases in one city are not good, the authorities need to be aware of the difference in the number of cases from X to Y (including x and y) in cities with the largest cases in the cities with the second most cases.

There will be a total of Q events, see "Input" for details.

Enter a description Input Description

The first behavior is two integer n,q, separated by a space.

The next Q line, each row represents an event. Line I+1 represents the I event, which has three integer ci,xi,yi, where CI is 1 or 2. If CI is 1, a new case of Yi has been found in City XI, and if CI is 2, the difference between the number of cases from Xi to Yi, the city with the largest case and the second most cases in the city, is indicated.

Output description Output Description

For each ci=2 event in the input, the output is one line, which is the result of the query.

Sample input Sample Input

4

2 1 4

1 2 3

2 2 4

1 3 2

2 1 3

1 2 2

2 1 4

Sample output Sample Output

0

3

1

3

Data range and Tips Data Size & Hint

"Sample description"

Initially, the number of cases in each city was {0,0,0,0}.

The maximum number of cases from 1 to 4 is 0, the second number of cases is 0, the difference is 0, and the output is 0.

City 2 found 3 new cases and the number of cases changed to {0,3,0,0}.

The maximum number of cases from 2 to 4 is 3, the second number of cases is 0, the difference is 3, and the output is 3.

City 3 found 2 new cases and the number of cases changed to {0,3,2,0}.

The maximum number of cases from 1 to 3 is 3, the second number of cases is 2, the difference is 1, and the output is 1.

City 2 found 2 new cases and the number of cases changed to {0,5,2,0}.

The maximum number of cases from 1 to 4 is 5, the second number of cases is 2, the difference is 3, and the output is 3.

"Data size and conventions"

For 40% of data, n,q≤1000.

For 100% of data, 2≤n,q≤100000, and for each ci=2, satisfies xi

Category labels Tags Click here to expand

The problem: First of all the people said that the serious spit groove-if there are two tie more cities, then should not be the first and second to take this value? I did it in a bad way, and then I added an equal sign so that the first second can take the same value, and then AC!?!? I am puzzled by the problem of the question. Sweat

Not difficult to make the line of the tree, point to modify the words of how to do, and then the interval is mainly a core operation--merge operation, the other did not

1 typevet=Record2 A1,a0:longint;3       End;4 var5 I,j,k,l,m,n:longint;6 A2:vet;7A:Array[0..500050] ofvet;8D:Array[0..500050] ofLongint;9C:Array[0..Ten] ofLongint;Ten procedureSwapvarx,y:longint); inline; One           varZ:longint; A           begin -z:=x;x:=y;y:=Z; -           End; the functionMax (x,y:longint): Longint;inline; -          begin -               ifX>y ThenMax:=xElsemax:=y; -          End; + functionmin (x,y:longint): Longint;inline; -          begin +               ifX<y ThenMin:=xElsemin:=y; A          End; at  - functionmerge (A2,a3:vet): Vet;inline; -           varI,j,k,l:longint;a4:vet; -           begin -c[1]:=a2.a0;c[2]:=a2.a1; -c[3]:=a3.a0;c[4]:=a3.a1; ina4.a0:=0; a4.a1:=0; -                 fori:=1  to 4  Do to                    begin +                         ifC[i]>=a4.a0 Then -                            begin thea4.a1:=a4.a0; *a4.a0:=C[i]; $                            EndPanax Notoginseng                         Else  -                             begin the                                 if(C[I]&GT;A4.A1) and(C[I]&LT;A4.A0) Thena4.a1:=C[i]; +                             End; A                    End; the exit (A4); +           End; - procedurebuilt (z,x,y:longint), inline; $           begin $                ifX=y Then -d[x]:=Z -                Else the                    begin -Built (z*2, X, (X+y)Div 2);WuyiBuilt (z*2+1, (X+y)Div 2+1, y); the                    End; -a[z].a0:=0; a[z].a1:=0; Wu           End; - proceduredoit (x,y:longint); About           begin $x:=D[x]; -a[x].a0:=a[x].a0+y;a[x].a1:=0; -                 whileX>1  Do -                      begin AA[xDiv 2]:=merge (a[x],a[x+1-2* (xMoD 2)]); +X:=xDiv 2; the                      End; -           End; $ functioncal (Z,x,y,l,r:longint): vet; the          varA3,a2:vet; the          begin the               ifL>r Then the                  begin -a2.a0:=0; ina2.a1:=0; the exit (A2); the                  End; About               if(x=l) and(Y=R) Thenexit (A[z]); theExit (Merge (Cal (z*2, X, (X+y)Div 2, L,min (R, (x+y)Div 2)), Cal (z*2+1, (X+y)Div 2+1, Y,max (L, (x+y)Div 2+1) , R )); the          End; the begin + READLN (n); -Built1,1, n); the       while  not(EOF) DoBayi          begin the readln (j,k,l); the                CaseJ of -                    1:d Oit (k,l); -                    2:begin theA2:=cal (1,1, n,k,l); theWriteln (a2.a0-a2.a1); the                    End; the               End; -          End; the Readln; the End.

Codevs2018 anti-virus software

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.