10.9 Guz Simulation problem

Source: Internet
Author: User

Thanks @guz

The problem of Gu Z

A total of three questions, including

The first question help a total of 10 test points, the time limit is 1000ms, the space limit is 256MB.

The second problem is a total of 20 test points, the time limit is 1000ms2000ms, space limit 1MB16MB.

The third question cure a total of 20 test points, the time limit is 1000ms, the space limit is 256MB.

PS: Topic background has nothing to do with the topic itself, can skip

Help

Topic background

In the dream, the king stayed in a mysterious place. This is the insect kingdom! The King was so handsome as to see the king, and he gave him a cup of insects. The king took a mouthful, and suddenly there was a problem! " This wine is poisonous! " Suddenly, the king stayed in his dream and fell asleep again.

Title Description

The King of the dream is hungry! He wants to eat ants! We're going to save him! The King was found to have n ants in a line, each ant has a number \ (a_i\) He wants to eat them. But the ants are partly poisonous, and we can only help him to pick out the zmj ant to save him. After eating the zmj ant, the King can return to normal.

The number of zmj ants in a certain interval is
The number of ants that cannot be divisible by the interval gcd in this interval. number of ants not equal to interval gcd in this interval

Input/output format

Input format

The first line gives an integer n, which means there are n ants.

The second line gives n integers \ (a_i,a_2,\dots,a_n\)
The third line gives an integer \ (m\), which represents a \ (m\) query.

Next \ (m\) line, each line given \ (l,r\), ask \ ([l,r]\) the number of zmj ants.

PS: After the ants are found, the king will not eat them directly. That is, the number of ants in the original sequence is unchanged.

The output format is a total of M lines, and each line corresponds to a query.

Input/Output sample

Enter the sample #1:

51 3 2 4 241 52 53 54 5

The output sample #1:

4411

Data size

For random data of 30%,\ (1\le n\le5000,1\le m\le500,1\le a_i\le10^4\) ,

For random data of 100%, \ (1\le n\le10^5,1\le m\le2\times10^4,1\le a_i\le10^9\),

Exercises

This problem has several kinds of XJB algorithm, the room inside AC basically a person an algorithm, then I say my algorithm put.

Multiplication + tree-like array.

First, we can multiply the preprocessing gcd, so that f[i][j] the point I points to the right to jump \ (2^j\) all the number of GCD on the route. The f[i][j] method of finding is simple:

f[i][j]=gcd(f[i][j-1],f[i+(1<<(j-1))][j-1]

Then we can find the GCD of an interval in log time. So we find the gcd of all the intervals, then the tree-like array is modified by a single point, and the interval is queried. All the intervals are sorted by GCD, and all the numbers are ordered, and the numbers are sized to the tree array.

Escape

Topic background

Finally, the king was rescued out, he no longer want to see ZMJ ant, but then the queen of the ZMJ state: ZMJ appeared! The king was caught in the ZMJ state endured #@¥&!*~ torture, when the king was small your diseased estate, a servant of the Queen found the King small, he wanted to save the King Small Stay, but before saving the king to stay, he will take a Test king, and said if the king of the correct answer will help him escape. But the king was only a breath away, can you help him escape?

Title Description

The servant gave N a number, which n a positive integer of not more than N, of which a number appeared two times, and the remainder of the number appeared only once, and he wanted the king to stay for the number two times. Can you do that?

Input/output format

Input format

A total of two lines. The first behavior is an integer n, which is represented by a \ (n\) number. The second behavior is n digits, with a space interval between each of the two integers.

Output format

An integer that is the number that occurs two times.

Input/Output sample

Enter the sample #1:

32 3 3

The output sample #1:

3

Data size

For 5% of random data, n<=5000

For random data of 15%, n<=\ (10^5\)

For random data of 50%, n<=10\ (^6\)

For random data of 100% \ (2\le n\le10^7\),

Exercises

Space at first was 1mb,std hyperspace, and later Guz changed to 16MB, resulting in bitset can easily water over.

Let's figure out the Bitset space: 10 of 7 than 8Bytes, or 1.25MB (those that should be 1.1920928955078125MB attention should be 1.1920928955078125MiB instead of MB, this is the Windows pot,// The preliminary question CCF inexplicable back pot) not much to pull

Anyway, I think if the memory limit is able to go through but bitset, it is not easy to set, or even can not set. Let's talk about the solution.

Since the topic is a positive integer less than or equal to N, since there is a number that appears two times (set to x), then there is exactly another number that does not appear (set to Y). Set the input to a, then \ (x-y=\sum{a_i}-\sum{i}\), and \ (\displaystyle\frac x y=\frac{\sum{a_i}}{\sum{i}}\). Solve this equation set. STD is solution in the sense of modulo, but can also open double directly.

Cure

Topic background

From the ZMJ country escaped the King small stay met is driving gu Z, Wang small stay hurriedly on Gu Z's car. (Is it really good to be on someone else's car?)

The great selfless kindness of the face of Gu Z to see the king of the appearance of the dying, it is heartache, decided to take him to the seaside 沝 (Zi) about (Xuan) mountain to find the mountain female Bud Tong Snow to thousand years ice 宩 to help. But before they went up the hill, they had a problem. Want to find the mountain female Bud Tong Snow, must know her home temperature .

Title Description

沝 (Zi) about (Xuan) mountain is always blowing the wind. The wind blows from place to place 1, place 2 until place N, altogether n+1 a place. Live in the place N. The elevation of the location at 0 is 0. The temperature of the wind changes with elevation. Location 0 at the seaside, the temperature is 0 degrees; for any location, the temperature difference of the wind from location I to location i+1 depends only on the elevation difference between the two places. Specifically:

If \ (a_i=a_{i+1}\), the temperature of the wind does not change;

If the \ (a_i<a_{i+1}\) wind climbs 1 meters, the temperature will fall s degrees;

If the \ (a_i>a_{i+1}\) winds climb 1 meters, the temperature will increase T-degree;

The crustal movement of the 沝 (Zi) about (Xuan) mountains is very strong. They got the data of the Q-day to the crustal movement. On the J-day 1<=j<=q, the elevation of the location \ (l_j,l_{j+1},..., r_j (1\le l_j\le r_j\le N) \) increased \ (x_j\).

Note \ (x_j\) may be a negative number.

Their task is to calculate the temperature of the bud Tong Snow residence after daily crustal movement.

Input/output format

Input format

The first line has four integers \ (n,q,s,t\), separated by a space. In the next n+1 line, line I (\ (1\le i\le n+1\)) has an integer \ (a_{i-1}\). In the next Q line, line J \ ((1\le j\le Q) \) has three integers \ (l_j,r_j,x_j\), separated by a space. The meanings of all the numbers entered are described in the topic

Output format

Total \ (q\) line, section \ (j\) line \ ((1\le j\le Q) \) has an integer that represents the temperature of the bud Tong Snow residence after the first \ (j\) diurnal crustal movement.

Input sample

2 2 5 506-11 1 41 2 8

Output sample

5-35

Data size

For 30% of data n,q<=2000,

For another 20% of the data s=t, for 100% of the data

\ (1\le n\le2\times10^5,1\le s,t\le10^6\)

\ (a_0=0,| A_i|\le10^6 (1\le i\le N) \)

Exercises

It is said that the problem is bare differential!!?!?!? No tree-like array!?!??!

Well, it's like it's really not.

However, I used

Long Long is not open.

Array out of bounds

Cheated 5 points.

Mdzz

In fact, the tree-like array is just one more log, and the constant thief must be able to be a small mother AC.

箰 Shiang used Mountain ...

The difference is each modification to modify the two endpoints out of the relative value of temperature, while directly maintaining the answer ...

Too lazy to say

10.9 Guz Simulation problem

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.