最开始猜了个结论错了,猜的是必须要有\(m+n-1\)个方格空着,这样才能保证任意一张牌能从起点到终点。

其实并不是,参考数字华容道,实际上是只要除了终点和起点,以及自身这个方格。我们只需要留出一个空格就可以使任意方格移动到任意位置。

我们只需要统计一下,一个数前面比他小的数有多少个,然后取个最大值,就是最大的要使这个牌按顺序到达终点,其它牌不能到达终点的情况,这时应该时满足\(m * n-4>=mx\)所有的就都可以满足。

#include <bits/stdc++.h>

#define int long long
#define rep(i, a, b) for(int i = (a); i <= (b); ++i)
#define fep(i, a, b) for(int i = (a); i >= (b); --i)
#define _for(i, a, b) for(int i=(a); i<(b); ++i)
#define pii pair<int, int>
#define pdd pair<double,double>
#define ll long long
#define db double
#define endl '\n'
#define fs first
#define sc second
#define pb push_back
#define vi vector<int> using namespace std;
const int maxn = 1e6 + 10; int a[maxn],tr[maxn],n,m,k; int lowbit(int x){
return x&-x;
} void add(int x, int d){
for(int i=x;i<=k;i+=lowbit(i)){
tr[i]+=d;
}
} int ask(int x){
int res=0;
for(int i=x;i;i-=lowbit(i)){
res+=tr[i];
}
return res;
} void solve() {
cin>>n>>m>>k;
rep(i,1,k){
tr[i]=0;
}
rep(i,1,k){
cin>>a[i];
}
int res=0;
rep(i,1,k){
res=max(res,ask(a[i]));
add(a[i],1);
}
if(n*m-4>=res){
cout<<"YA\n";
}else{
cout<<"TIDAK\n";
}
} signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
// freopen("C:\\Users\\24283\\CLionProjects\\untitled2\\1.in", "r", stdin);
int _;
cin >> _;
while (_--)
solve();
return 0;
}
``

21 Educational Codeforces Round 136 (Rated for Div. 2)Knowledge Cards(树状数组、set、+思维、数字华容道)的更多相关文章

  1. Educational Codeforces Round 80 (Rated for Div. 2)E(树状数组,模拟,思维)

    #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; ],mx[],a[],pos[],sum ...

  2. Educational Codeforces Round 63 (Rated for Div. 2) B. Game with Telephone Numbers 博弈思维+模拟+贪心思维

    题意:博弈题面  给出一个数字序列 (>=11)  有两个人任意删除数字 直到 数字只剩下11位 如果删除后的数字串开头是8那么就是第一个赢 否则就是第二个人赢 第一个人先手  数字序列一定是奇 ...

  3. Educational Codeforces Round 61 (Rated for Div. 2) G(线段树,单调栈)

    #include<bits/stdc++.h>using namespace std;int st[1000007];int top;int s[1000007],t[1000007];i ...

  4. Educational Codeforces Round 62 (Rated for Div. 2)E(染色DP,构造,思维,组合数学)

    #include<bits/stdc++.h>using namespace std;const long long mod=998244353;long long f[200007][2 ...

  5. Educational Codeforces Round 61 (Rated for Div. 2)D(二分,模拟,思维)

    #include<bits/stdc++.h>using namespace std;typedef long long ll;int n,k;ll a[200007],b[200007] ...

  6. Educational Codeforces Round 33 (Rated for Div. 2) B. Beautiful Divisors【进制思维/打表】

    B. Beautiful Divisors time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  7. Educational Codeforces Round 71 (Rated for Div. 2)-E. XOR Guessing-交互题

    Educational Codeforces Round 71 (Rated for Div. 2)-E. XOR Guessing-交互题 [Problem Description] ​ 总共两次询 ...

  8. Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...

  9. Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...

  10. Educational Codeforces Round 43 (Rated for Div. 2)

    Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...

随机推荐

  1. Vue双向数据绑定原理-下

    Vue双向数据绑定原理-下这一篇文章主要讲解Vue双向数据绑定的原理,主要是通过Object.defineProperty()来实现的,这里我们手写Vue双向数据绑定的原理. 首先我提出一个需求,我的 ...

  2. Intel 4工艺太难了!酷睿Ultra终于突破5GHz

    无论是14nm还是10nm,Intel这些年的新工艺都有一个通性:刚诞生的时候性能平平,高频率都上不去,只能用于笔记本移动端(分别对应5代酷睿.10代酷睿),后期才不断成熟,比如到了13代酷睿就达到史 ...

  3. 应用--WebApplication

    应用--Program中的WebApplication 在6.0,微软团队对于NetCore做了很大的改变,其中有一个改变就是推出了新的托管模型--最小托管模型,使用该模型可以创建最小的web应用.( ...

  4. spring cloud与加密库jasypt(ulisesbocchio)冲突问题定位

    背景 最近在项目上遇到个问题.项目就是普通的spring cloud,spring cloud在spring boot的基础上多了一些东西,比如支持bootstrap上下文(通过bootstrap.y ...

  5. Excel快速调整单元格行高和列宽

    之前使用的是鼠标双击的方法,但是只适用于少量调整时. 今天给同事编辑公众号文章,有一大篇表格在word中,直接从word中复制到公众号的话,格式会有一定程度的错位. 于是先粘贴到excel中处理,但到 ...

  6. [Ngbatis源码学习] Ngbatis 源码学习之资源加载器 DaoResourceLoader

    Ngbatis 源码学习之资源加载器 DaoResourceLoader DaoResourceLoader 是 Ngbatis 的资源文件加载器,扩展自 MapperResourceLoader.本 ...

  7. [Spring6.0源码解析]简述@Configuration注解

    @Configuration 标注在类上,启动 Spring 会自动扫描@Configuration注解的类,将其注册到IOC容器并实例化bean对象.如果在@Configuration注解的类中使用 ...

  8. 从零开始的react入门教程(四),了解常用的条件渲染、列表渲染与独一无二的key

    壹 ❀ 引 在从零开始的react入门教程(三),了解react事件与使用注意项一文中,我们了解了react中事件命名规则,绑定事件时对于this的处理,以及事件中可使用的e对象.那么这篇文章中我们来 ...

  9. .net core微服务之服务发现

    一:nacos https://nacos.io/docs/latest/what-is-nacos/ https://github.com/alibaba/nacos 二:consul https: ...

  10. CentOS在无网络环境下,用离线源yum安装软件

    先说大致步骤: 1.前提假设:当前无网络的目标服务器是A,我们需要先准备一台服务器B: 2.在B上面用yum先把软件安装完成. 3.然后用createrepo将B中的包拷贝出来,并传到A上(用U盘或者 ...