题目链接:点击打开题目
看懂官方题解就不难了,看出来这个题的结果和n、m各自的值是没有关系的,只用观察n*m-1和p的值就行了。
然后自己在纸上写几组,观察每个数对逆序数的贡献(前面没有选中的数的个数),就能发现是等差数列了。再多观察几组,发现每组都是等差数列,然后一组一组的算就行啦。
代码如下:
#include<queue>
#include<cmath>
#include<stack>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long LL;
#define INF 0x3f3f3f3f
#define CLR(a,b) memset(a,b,sizeof(a))
#define PI acos(-1.0)
int main()
{
int T;
int n,m,k;
LL l,num;
scanf ("%d",&T);
while (T--)
{
scanf ("%d%d%d",&n,&m,&k);
LL ant = 0;
n = n*m - 1;
while (n > k)
{
l = (n+k-1) / k; //项数
num = (k-1)*l*(l-1)/2;
n -= l;
ant += num;
}
if (ant&1)
puts("NO");
else
puts("YES");
}
return 0;
}