题目连接:
http://codeforces.com/gym/100861/attachments
题解:
比较水的题目,基本看的懂题意就能打。
这里需要一下离散化。
代码:
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define met(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
const int maxn = 7e4+10;
struct node1
{
int cnt;
int logo;
}num1[maxn];
struct node2
{
int price;
int day;
}num2[maxn];
int change1[maxn],len1;
int change2[maxn],len2;
int ans[maxn];
int cmp1(node1 a,node1 b)
{
return a.cnt>b.cnt;
}
int cmp2(node2 a,node2 b)
{
return a.price>b.price;
}
int id(int num)
{
return lower_bound(change2,change2+len2,num)-change2+1;
}
void init()
{
for(int i=0;i<maxn;i++)
{
num1[i].cnt=0;
num1[i].logo=-1;
}
for(int i=0;i<maxn;i++)
num2[i].price=num2[i].day=0;
met(change1,0),met(change2,0);
len1=0,len2=0;
met(ans,0);
}
int main()
{
init();
int F,A,B,C;
scanf("%d%d%d%d",&F,&A,&B,&C);
int n,m;
scanf("%d%d",&n,&m);
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
{
int x;
scanf("%d",&x);
change1[len1++]=x;
change2[len2++]=x;
}
sort(change2,change2+len2);
len2=unique(change2,change2+len2)-change2;
int len3=0;
for(int i=0;i<len1;i++)
{
if(num1[id(change1[i])].logo==-1)
{
len3++;
num1[(id(change1[i]))].logo=change1[i];
}
num1[(id(change1[i]))].cnt++;
}
sort(num1+1,num1+maxn,cmp1);
num2[1].price=F;
num2[1].day=1;
for(int i=2;i<=len3;i++)
{
num2[i].price=((A*num2[i-1].price+B)%C)+1;
num2[i].day=i;
}
sort(num2+1,num2+len3+1,cmp2);
for(int i=1;i<=len3;i++)
ans[num2[i].day]=num1[i].logo;
printf("%d\n",len3);
for(int i=1;i<=len3;i++)
{
if(i==1)
printf("%d",ans[i]);
else
printf(" %d",ans[i]);
}
printf("\n");
}