题解:CF2218G The 67th Iteration of "Counting is Fun"
lkjlkjlkj2012 · · 题解
思路
我们按
我们只考虑
如果它的邻居都是在
反之,如果它的邻居有一个是前一秒坐下,另一个是前一秒及以后坐下,那么限制这个人坐下的因素是邻居没有坐下。只要
否则,这个人的邻居在第
代码
:::warning[真的要查看代码吗]
// Problem: G. The 67th Iteration of "Counting is Fun"
// Contest: Codeforces - Codeforces Round 1090 (Div. 4)
// URL: https://codeforces.com/contest/2218/problem/G
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// Author: lkjlkjlkj2012
// Time: 2026-04-20 10:26:04
//
// Powered by CP Editor (https://cpeditor.org)
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 676767677;
int t, n, m, b[200005], now[200005];
vector<int> c[200005];
signed main()
{
ios::sync_with_stdio(0), cin.tie(0);
cin >> t;
while(t--)
{
cin >> n >> m;
for(int i = 1; i <= n; i++)
cin >> b[i];
for(int i = 1; i <= n; i++)
c[b[i]].push_back(i);
for(int i = 0; i < m; i++)
now[i] = c[i].size() + (i == 0 ? 0 : now[i - 1]);
int ans = 1;
b[0] = b[n + 1] = 1e8;
for(int i = 1; i < m; i++)
{
for(int x: c[i])
{
assert(b[x] == i);
if(b[x - 1] >= b[x] && b[x + 1] >= b[x])
{
ans = 0;
break;
}
if(b[x - 1] >= b[x] - 1 && b[x + 1] >= b[x] - 1)
(ans *= now[i - 1]) %= mod;
else
(ans *= now[i - 1] - (i > 1 ? now[i - 2] : 0)) %= mod;
}
}
cout << ans << "\n";
for(int i = 0; i < m; i++)
c[i].clear();
}
return 0;
}