Sichuan B.HotPot

题目:

Sichuan hotpot is one of the most famous dishes around the world. People love its spicy taste. There are n tourists, numbered from 0 to (n−1), sitting around a hotpot.

There are k types of ingredients for the hotpot in total and the i-th tourist favors ingredient ai most. Initially, every tourist has a happiness value of 0 and the pot is empty.

The tourists will perform m moves one after another, where the i-th (numbered from 0 to (m − 1)) move is performed by tourist (i mod n).

When tourist t moves:

• If ingredient at exists in the pot, he will eat them all and gain 1 happiness value.

• Otherwise, he will put one unit of ingredient at into the pot. His happiness value remains unchanged. Your task is to calculate the happiness value for each tourist after m moves.

Input

There are multiple test cases. The first line of the input contains an integer T (1 ≤ T ≤ 103 ) indicating the number of test cases.

For each test case: The first line contains three integers n, k and m (1 ≤ n ≤ 105 , 1 ≤ k ≤ 105 , 1 ≤ m ≤ 109 ) indicating the number of tourists, the number of types of ingredients and the number of moves.

The second line contains n integers a0, a1, · · · , an−1 (1 ≤ ai ≤ k) where ai indicates the favorite ingredient of tourist i. It’s guaranteed that neither the sum of n nor the sum of k of all the test cases will exceed 2 × 105 .

Output

For each test case output n integers h0, h1, · · · , hn−1 in one line separated by a space, where hi indicates the happiness value of tourist i after m moves. Please, DO NOT output extra spaces at the end of each line, or your answer might be considered incorrect!

                     Example standard input                       standard output

4 0 2 1
3 2 6 2
1 1 2 2 2
1 1 5 0 5
1
2 2 10
1 2
2 2 10
1 1

要对移动步数进行讨论,分成<2n 和 2n+。

#include<bits/stdc++.h>
using namespace std;
typedef struct sm{
    int x;
    int y;
}mms;
const int N=1e5+10;
int cnt[N];
int n,k,m;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        mms ans[N];
        memset(cnt,0,sizeof(cnt));
        cin>>n>>k>>m;
        for(int i=0;i<n;i++)
        cin>>ans[i].x,ans[i].y=0;//x为每位游客最喜欢的部分 
        if(m>=2*n){
        for(int i=0;i<2*n;i++)
        {
            int a=i%n;//对i进行处理,但次数没变 
            if(cnt[ans[a].x]==0)cnt[ans[a].x]++;
            else
            {
                cnt[ans[a].x]--;
                ans[a].y++;
            }
        }
        for(int i=0;i<n;i++)
        ans[i].y* = (m/(2*n));
	}
        
        
        for(int i=0;i<m%(2*n);i++)
        {
             int a=i%n;
            if(cnt[ans[a].x]==0)cnt[ans[a].x]++;
            else
            {
                cnt[ans[a].x]--;
                ans[a].y++;
            }
        }
        for(int i=0;i<n;i++)
        {
            if(i)cout<<" ";
            cout<<ans[i].y;
        }
        cout<<endl;
    }
    return 0;
}

上一篇:France Alternative forms Fraunce


下一篇:ACM训练2021_7_16题解