T1
当天最难的题目..............
足足三页的题目描述..........
我们可以考虑到对于每一个串来说,串内部满足条件的数字可以先消去,所以我们直接先将串内的数消去,这样可以得到一个新的串
然后我们从两端向中间一个一个枚举数字,只要相等就继续枚举下去,如果说数量达到了k的话就取模并且更新原来的序列
最后就是每个循环剩余长度*(m-1)+仅去掉同一循环的剩余数的个数。(不懂的话自己推一下就好了.....这个公式很简单的.......)
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define LL long long
LL n,m,tot,k,s[100005][2],cnt;
int main()
{
freopen("guass.in","r",stdin);
freopen("guass.out","w",stdout);
std::scanf("%I64d%I64d%I64d",&n,&m,&k);
for(int i=1;i<=n;i++)
{
LL x;
std::scanf("%I64d",&x);
if(!cnt||s[cnt][0]!=x)
{
s[++cnt][0]=x;
s[cnt][1]=1;
}
else s[cnt][1]++;
if(s[cnt][1]==k)s[cnt][1]=0,cnt--;
}
for(int i=1;i<=cnt;i++)
{
tot+=s[i][1];
}
int head=1;
int tail=cnt;
while(head<tail&&s[head][0]==s[tail][0])
{
if(!((s[head][1]+s[tail][1])%k))
{
head++;tail--;
}
else
{
s[head][1]=(s[head][1]+s[tail][1])%k;
s[tail][1]=0;
break;
}
}
LL ans=0;
if(head<tail)
{
for(int i=head;i<=tail;i++) ans+=s[i][1];
ans*=(m-1);
ans+=tot;
}
else if(head==tail)
{
if((s[head][1]*m)%k&