21 Educational Codeforces Round 136 (Rated for Div. 2)Knowledge Cards(树状数组、set、+思维、数字华容道)

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

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

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

cpp 复制代码
#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;
}
``
相关推荐
Timmylyx051822 天前
CF 新年赛 Goodbye 2025 题解
算法·codeforces·比赛日记
Timmylyx051822 天前
2025年最后一搏—— Educational Codeforces Round 186 (Rated for Div. 2) 题解
算法·codeforces·比赛日记
ddmdd1 个月前
codeforces Round 1070(Div. 2)
codeforces
defaulter3 个月前
Codeforces Round 1049 (Div. 2)C. Ultimate Value
算法·codeforces
图灵信徒5 个月前
ICPC Central Russia Regional Contest, 2024
c++·python·codeforces·算法竞赛
超闻逸事6 个月前
题解:CF2129C Interactive RBS
c++·算法·codeforces
ReineRabbit6 个月前
重生之 CF2126G2. Big Wins! (hard version)
线段树·codeforces·中位数
Savior`L6 个月前
Educational Codeforces Round 181 (Rated for Div. 2)
数据结构·c++·算法·codeforces
TL自动机6 个月前
Educational Codeforces Round 180 (Rated for Div. 2) C. Coloring Game
codeforces
Closet1237 个月前
Codeforces 2025/6/11 日志
c++·算法·codeforces