Seaport (queue) (array analog list)

Source: Internet
Author: User

Harbour Topic Description:

Small k is a seaport customs officer, and many ships arrive at the harbor every day, and there are usually many passengers from different countries on board.

The small k was very interested in the ships that had arrived at the harbor, and he recorded the circumstances of each vessel arriving at the seaport in time; for the ship arriving on the first, he recorded the time of the ship's arrival Ti (unit: seconds), the number of passengers on board the Star Ki, and the nationality of each passenger x (i,1), X (i,2 k);.

Small k statistics on the N ship information, I hope you help calculate the arrival time of each ship up to 24 hours (24 hours = 86,400 seconds) All passengers arriving from the number of different countries.

Formally speaking, you need to calculate n information. For the output of article I information, you need to statistically meet ti-86400 < TP <= TI's ship p, in all X (P,J), how many different numbers are in total.

Input format:

The first line enters a positive integer n, indicating that the information of n ships is counted by the small K.

Next n lines, each line describes a ship's information: The first two integers ti and ki respectively indicate the time the ship arrived at the seaport and the number of passengers on board, and then ki an integer x (i,j) indicates the country of the passenger on board 7.

Ensure that the input ti is incremented, the unit is the second, indicating that the first time from the beginning of the work of K, this ship in ti seconds to reach the seaport.

Guarantee.

Which represents all the Ki's and.

Output format:

Output n lines, line I outputs an integer representing the statistics of the arrival of the first ship.

Sample input:
Example 1:31 4 4 1 2 22 2 2 310 1 3 Example 2:41 4 1 2 2 33 2 2 386401 2 3 486402 1 5
Sample output:
Sample 1:344 Example 2:3,334
Tips:

"Sample Interpretation 1"

The first ship arrived at the seaport in 1 seconds, and the last 24-hour boat arrived was the first ship, with a total of 4 passengers, from the national 4,1,2,2, from 3 different countries;

The second ship arrived at the seaport in 2 seconds, the last 24 hours of the ship was the first ship and the second ship, a total of 4 + 2 = 6 passengers, respectively from the national 4,1,2,2,2,3, a total of 4 different countries;

The third ship arrived at the seaport in 10 seconds, the last 24 hours of the ship was the first ship, the second ship and the third ship, a total of 4 + 2+1=7 passengers, respectively, from the national 4,1,2,2,2,3,3, a total of 4 different countries.

"Sample Interpretation 2"

The first ship arrived at the seaport in 1 seconds, and the last 24-hour ship was the first, with a total of 4 passengers, from the national 1,2,2,3, from 3 different countries.

The second ship arrived at the seaport in 3 seconds, the last 24 hours of the ship was the first ship and the second ship, a total of 4+2=6 passengers, respectively, from the national 1,2,2,3,2,3, a total of 3 different countries.

The third ship arrived at the seaport in 86,401 seconds, the last 24 hours of the ship was the second ship and the third ship, a total of 2+2=4 passengers, respectively, from the national 2,3,3,4, a total of 3 different countries.

The ship arrived at the seaport in 86,402 seconds, and the last 24 hours were the second ship, the third ship and the fourth ship, a total of 2+2+1=5 passengers, from the national 2,3,3,4,5, from 4 different countries.

"Data Range"

Time limit: 1000ms
Space limit: 512MB

Source: NOIP2016 Universal T3

#include <cstdio>#include<stdio.h>#include<iostream>#include<algorithm>#include<queue>#include<vector>using namespacestd;structnode{intT,z;} Data,p;vector<node>Q;inta[300010][2],n,k=1, b[100000],sum;intAsize (inta[100000]){    intans;  for(intI=1; i<=100000; i++)if(A[i]) ans++; returnans;}intMain () {q.push_back (P); CIN>>N;  for(intI=1; i<=n;i++){        intTi,ki; scanf ("%d%d",&ti,&ki); DATA.T=ti;data.z=K;        Q.push_back (data);  for(intj=1; j<=ki;j++) {scanf ("%d", &a[k][1]); a[k][2]=++K; } a[k-1][2]=0; }    intIi=1;  for(intI=1; i<=n;i++) {p=Q[i]; intzz=p.z;  while(1) {b[a[zz][1]]++; if(b[a[zz][1]]==1) sum++; ZZ=a[zz][2]; if(zz==0) Break; }         while(1){            if(q[ii].t<=q[i].t-86400) {ZZ=q[ii].z;  while(1) {b[a[zz][1]]--; if(b[a[zz][1]]==0) sum--; ZZ=a[zz][2]; if(zz==0) Break; } II++; }            Else  Break; } printf ("%d\n", sum); }}

Seaport (queue) (array analog list)

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.