fudq's blog

By fudq, 13 years ago, In English

This contest is a little hard for me. Only A and C were solved finally though I spent more than one hour on the other problems. My rank is 213. Here is the summary:

Pro A: There are n elements in an array.If we can obtain an array where any two neighboring elements would be distinct in a finite time,print "YES" and print "NO" otherwise.

This problem is not hard.What we should do is just counting the amount of each elements and find the max amount k.If k-1 is bigger than n-k,then print "NO" and print "YES" otherwise.

Pro C: The first line tells us three integers n, m, k(1<=n,m,k<=10^5). The second line is an array(f) of n elements.

Next m lines contain operations with three integers li, ri, di(1<=li<=ri<=n,0<=di<=10^5) which means to increase all array elements with numbers li,li+1,...,ri by value di.

Next k lines contain queries with two integers x, y(1<=xi<=yi<=m) which means that one should apply operations with numbers xi,xi+1,..., yi to the array.

After understanding this problem,I thought of the segment tree firstly with the max data 10^5.But after I analysed carefully,I find another convenient solution.

First of all, we need to know how many times each operations need to apply by k queries.We need an array(p) with each element is 0 initially.Then come k queries and execute two commands:p[xi]++ and p[yi+1]--.After cycling from 1 to m with executing command:p[i]+=p[i-1],we can know the i-th operation needs to apply p[i] times.

Secondly,we multiply each operation's di by p[i].

Thirdly,we need to know how much each element needs to add by m operations.The following is similar to the first.As mentioned,we need an array(p) with each element is 0 initially.Then come m operations and execute two commands:p[li]+=di and p[ri+1]-=di.After cycling from 1 to n with executing command:p[i]+=p[i-1],we can know each element f[i] needs to add p[i].

Finally,after cycling from 1 to n with executing command:f[i]+=p[i],we can obtain the answers.

*Tips:as the data will be very big,we should use __int64 replace of int.

Full text and comments »

  • Vote: I like it
  • -9
  • Vote: I do not like it

By fudq, 13 years ago, In English

Totally speaking, this contest is very funny.I worked out the first four problems finally.Now is the summary:

Problem A: Input a number and output a string.So what string will be right? After looking the sample test,we can see the whole results which are the name of American Presidents and correspond to the order in American history. So we can draw a conclusion:just list the first forty American Presidents.And what you should pay attention to is just to output the last name.As a result,the results will be one word except for "Van Buren".

Problem B: Input two numbers and output a number with a QR code. This is a simple problem.You will see a two-dimensional matrix filled with 0 or 1 after scanning the QR code.It's not hard to see the two numbers (a1 and a2) meaning the row number and column number of the matrix.You just output the corresponding result.

Problem C: The description is several words.I still don't understand what it means after skimming twice. Finally,I see the description is a program which is written by LOLCODE. With the help of a magic website which is introducing LOLCODE,I understand this program finally. The address of the magic website

Problem D: This problem is similar to Problem C but the description is a picture in replace of text. It's not very hard to read this program.Here is a point:the icon of a snake or a arrow or a smile or a heart is standing for just a variable.

Full text and comments »

  • Vote: I like it
  • +1
  • Vote: I do not like it