Codeforces Round #532 (Div. 2) B. Build a Contest(映射) 1300

Arkady coordinates rounds on some not really famous competitive programming platform. Each round features n problems of distinct difficulty, the difficulties are numbered from 1 to n.

To hold a round Arkady needs n new (not used previously) problems, one for each difficulty. As for now, Arkady creates all the problems himself, but unfortunately, he can’t just create a problem of a desired difficulty. Instead, when he creates a problem, he evaluates its difficulty from 1 to n and puts it into the problems pool.

At each moment when Arkady can choose a set of n new problems of distinct difficulties from the pool, he holds a round with these problems and removes them from the pool. Arkady always creates one problem at a time, so if he can hold a round after creating a problem, he immediately does it.

You are given a sequence of problems’ difficulties in the order Arkady created them. For each problem, determine whether Arkady held the round right after creating this problem, or not. Initially the problems pool is empty.

Input
The first line contains two integers n and m (1≤n,m≤105) — the number of difficulty levels and the number of problems Arkady created.

The second line contains m integers a1,a2,…,am (1≤ai≤n) — the problems’ difficulties in the order Arkady created them.

Output
Print a line containing m digits. The i-th digit should be 1 if Arkady held the round after creation of the i-th problem, and 0 otherwise.

Examples
input
3 11
2 3 1 2 2 2 3 2 2 3 1
output
00100000001
input
4 8
4 1 3 3 2 3 3 3
output
00001000
方法一 map<int,int> 此难度等级对应问题个数

#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
using namespace std;

#define PI acos(-1.0)
typedef long long ll;
typedef long double ld;
const int INF32M=0x3f3f3f3f;
const ll INF64M=0x3f3f3f3f3f3f3f3f;


int main()
{
	ios::sync_with_stdio(false);
	int n,m,t;		//难度等级1-n m出题个数 
	cin>>n>>m;
	map<int,int> mp;	//此难度等级对应的问题个数 难度等级n 1-1e5 m=1e5个问题同一难度 对应问题个数为1e5 
	for(int i=1;i<=m;i++)
	{
		cin>>t;
		mp[t]++;
		if(mp.size()==n)
		{	
			printf("1");
			for(int j=1;j<=n;j++)
			{
				mp[j]--;
				if(mp[j]==0)		//此难度等级对应问题个数没有了 
					mp.erase(j);		//此难度等级对应位置移除掉
				 
			}
		}
		else
			printf("0");		//未等到其余难度等级第一次出现 
	}
	return 0;
}

方法二 num数组计数

#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
using namespace std;

#define PI acos(-1.0)
typedef long long ll;
typedef long double ld;
const int INF32M=0x3f3f3f3f;
const ll INF64M=0x3f3f3f3f3f3f3f3f;

int a[100005];	//存值为难度等级n最大为1e5 m个问题1e5 
int num[100005];	//难度等级n 1-1e5 对应问题个数 m=1e5个数同一难度等级
//此难度等级对应问题个数为1e5 
int main()
{
	ios::sync_with_stdio(false);
	int n,m,cnt=0;
	cin>>n>>m;
	for(int i=1;i<=m;i++)
		cin>>a[i];
	for(int i=1;i<=m;i++)
	{
		num[a[i]]++;
		if(num[a[i]]==1)
			cnt++;		//难度等级种类++
		if(cnt==n)
		{
			printf("1");
			for(int j=1;j<=n;j++)
			{
				num[j]--;
				if(num[j]==0)		//此难度等级对应问题个数减为0 
					cnt--;		//难度等级总种类-- 
			}	
		} 
		else		//1-n难度问题不全 不能举办一轮比赛 
			printf("0");	
	}
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值