Winter Vacation Training Topic Set 2B - Harbor

B - Harbor

topic background

NOIP2016 Popularization Group T3

topic description

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

Little K is very interested in these ships arriving at the harbor, and he recorded the situation of each ship arriving at the harbor according to time ;i ship arrived, he recorded the arrival timeti t_iti(unit: second), the number of passengers on board ki k_iki, and each passenger's nationality xi , 1 , xi , 2 , … , xi , k x_{i,1}, x_{i,2},\dots,x_{i,k}xi,1,xi,2,,xi,k

Little K has counted nnThe information of n ships, I hope you can help to calculate 24 24from the arrival time of each ship24 hours (24 2424 hours= 86400 = 86400=86400 seconds) how many different countries all passengers arriving by boat come from.

Formally, you need to compute nnn pieces of information. For outputiiFor i pieces of information, you need to countti − 86400 < tp ≤ ti t_i-86400<t_p \le t_iti86400<tptiship ppp , in allxp , j x_{p,j}xp,j, how many different numbers are there in total.

input format

Enter a positive integer nn in the first linen , means small K countsnnInformation about n ships.

Next nnn lines, each line describes the information of a ship: the first two integersti t_itisum ki k_ikiRespectively indicate the time when the ship arrives at the harbor and the number of passengers on board, then ki k_ikiIntegers xi , j x_{i,j}xi,jIndicates the nationality of the passengers on board.

Guaranteed input ti t_itiIt is incremental, and the unit is second; it means that the timing starts from the first time when K starts to go to work, and the ship is at the t t_itiSeconds to the harbor.

Guarantee that 1 ≤ n ≤ 1 0 5 1 \le n \le 10^51n105,$\sum{k_i} \le 3\times 10^5 $,1 ≤ xi , j ≤ 1 0 5 1\le x_{i,j} \le 10^51xi,j105 ,1 ≤ ti − 1 ≤ ti ≤ 1 0 9 1 \le t_{i-1}\le t_i \le 10^91ti1ti109

Among them ∑ ki \sum{k_i}kimeans all ki k_ikiof and.

output format

output nnline n , iiLine i outputs an integer representing theiiStats after i ship arrives.

Example #1

Sample Input #1

3
1 4 4 1 2 2
2 2 2 3
10 1 3

Sample output #1

3
4
4

Example #2

Sample Input #2

4
1 4 1 2 2 3
3 2 2 3
86401 2 3 4
86402 1 5

Sample output #2

3
3
3
4

hint

[Example Explanation 1]

first boat at 1 11 second to reach the harbor, nearest24 24The boat that arrived in 24 hours was the first boat and there were 4 44 passengers from countries4 , 1 , 2 , 2 4,1,2,24,1,2,2 of 3 out of33 different countries;

second boat at 2 22 seconds to reach the harbor, nearest24 24The boats arriving in 24 hours are the first boat and the second boat, a total of 4 + 2 = 6 4 + 2 = 64+2=6 passengers from countries4 , 1 , 2 , 2 , 2 , 3 4,1,2,2,2,34,1,2,2,2,3 out of4 44 different countries;

3rd boat at 10 1010 seconds to reach the harbor, nearest24 24The ships arriving in 24 hours are the first ship, the second ship and the third ship, a total of 4 + 2 + 1 = 7 4+2+1=74+2+1=7 passengers from countries4 , 1 , 2 , 2 , 2 , 3 , 3 4,1,2,2,2,3,34,1,2,2,2,3,3 out of4 44 different countries.

[Example Explanation 2]

first boat at 1 11 second to reach the harbor, nearest24 24The boat that arrived in 24 hours was the first boat and there were 4 44 passengers from countries1 , 2 , 2 , 3 1,2,2,31,2,2,3 of 3 from33 different countries.

second boat at 3 33 seconds to reach the harbor, nearest24 24The ships arriving in 24 hours are the first ship and the second ship, so there are 4 + 2 = 6 4+2=64+2=6 passengers from countries1 , 2 , 2 , 3 , 2 , 3 1,2,2,3,2,31,2,2,3,2,3 of 3 from33 different countries.

The third boat is at 86401 8640186401 seconds to reach the harbor, the nearest24 24The ships arriving in 24 hours are the second ship and the third ship, a total of 2 + 2 = 4 2+2=42+2=4 passengers from countries2 , 3 , 3 , 4 2,3,3,42,3,3,4 of3 out of 33 different countries.

The fourth boat is at 86402 8640286402 seconds to reach the harbor, the nearest24 24The ships arriving in 24 hours are the second ship, the third ship and the fourth ship, a total of 2 + 2 + 1 = 5 2+2+1=52+2+1=5 passengers from countries2, 3, 3, 4, 5 2,3,3,4,52,3,3,4,5 of 4 out of44 different countries.

【data range】

  • For 10% 10\%10% 的测试点, n = 1 , ∑ k i ≤ 10 , 1 ≤ x i , j ≤ 10 , 1 ≤ t i ≤ 10 n=1,\sum k_i \leq 10,1 \leq x_{i,j} \leq 10, 1 \leq t_i \leq 10 n=1,ki10,1xi,j10,1ti10
  • For 20 % 20\%20% 的测试点, 1 ≤ n ≤ 10 , ∑ k i ≤ 100 , 1 ≤ x i , j ≤ 100 , 1 ≤ t i ≤ 32767 1 \leq n \leq 10, \sum k_i \leq 100,1 \leq x_{i,j} \leq 100,1 \leq t_i \leq 32767 1n10,ki100,1xi,j100,1ti32767
  • For 40 % 40\%40% 的测试点, 1 ≤ n ≤ 100 , ∑ k i ≤ 100 , 1 ≤ x i , j ≤ 100 , 1 ≤ t i ≤ 86400 1 \leq n \leq 100, \sum k_i \leq 100,1 \leq x_{i,j} \leq 100,1 \leq t_i \leq 86400 1n100,ki100,1xi,j100,1ti86400
  • For 70 % 70\%70% 的测试点, 1 ≤ n ≤ 1000 , ∑ k i ≤ 3000 , 1 ≤ x i , j ≤ 1000 , 1 ≤ t i ≤ 1 0 9 1 \leq n \leq 1000, \sum k_i \leq 3000,1 \leq x_{i,j} \leq 1000,1 \leq t_i \leq 10^9 1n1000,ki3000,1xi,j1000,1ti109
  • For 100 % 100\%100% 的测试点, 1 ≤ n ≤ 1 0 5 , ∑ k i ≤ 3 × 1 0 5 , 1 ≤ x i , j ≤ 1 0 5 , 1 ≤ t i ≤ 1 0 9 1 \leq n \leq 10^5,\sum k_i \leq 3\times 10^5, 1 \leq x_{i,j} \leq 10^5,1\leq t_i \leq 10^9 1n105,ki3×105,1xi,j105,1ti109

answer

You can use an array plus a queue. The array is used to record the corresponding number of people in each city, and the queue is used to record the sequence. These data are not always valid. As long as the time and current of the ship that first came in exceed 86400, we will It can be discarded, which means that it can be dequeued. The title says that the input time is incremental, so it can be dequeued directly.

Every time we input, we judge, if the current array corresponds to 0, it means that there is no such city, we add one to the city, and then put it in the queue, after inputting, we start to judge, if the head of the queue exceeds 24 hours , Then discard, subtract one from the corresponding city array, and then check whether the array is 0 now, if it is 0, it means that the city is gone, we subtract one from cnt, and then go out of the team.

#include<bits/stdc++.h>
using namespace std;

struct node{
    
    
	int t;
	int c;
};

int a[3000001],N,n,k,t,cnt;

int main(){
    
    
	queue<node> q;
	cin >> N;
	for(int i=0;i<N;i++){
    
    
		cin >> t >> n;
		for(int i=0;i<n;i++){
    
    
			cin >> k;
			q.push({
    
    t,k});
			if(a[k]==0) cnt++;
			a[k]++;
		}
		while(!q.empty()&&t-q.front().t>=86400){
    
    
			a[q.front().c]--;
			if(a[q.front().c]==0) cnt--;
			q.pop();
		}
		cout << cnt << endl;
	}
	return 0;
}

Guess you like

Origin blog.csdn.net/L6666688888/article/details/128417388