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;
}
``
相关推荐
所以遗憾是什么呢?20 天前
【题解】Codeforces Round 1097 (Div. 2, Based on Zhili Cup 2026) (致理杯) ABCDEF
数据结构·算法·acm·codeforces·icpc·ccpc·xcpc
wenhaoran112 个月前
CF1800F Dasha and Nightmares
c++·算法·字符串·codeforces·位运算
超闻逸事4 个月前
题解:CF2196D Double Bracket Sequence
codeforces
Timmylyx05184 个月前
Codeforces Round 1075 (Div. 2) 题解
算法·codeforces·比赛日记
Timmylyx05185 个月前
CF 新年赛 Goodbye 2025 题解
算法·codeforces·比赛日记
Timmylyx05185 个月前
2025年最后一搏—— Educational Codeforces Round 186 (Rated for Div. 2) 题解
算法·codeforces·比赛日记
ddmdd6 个月前
codeforces Round 1070(Div. 2)
codeforces
defaulter7 个月前
Codeforces Round 1049 (Div. 2)C. Ultimate Value
算法·codeforces
图灵信徒9 个月前
ICPC Central Russia Regional Contest, 2024
c++·python·codeforces·算法竞赛
超闻逸事10 个月前
题解:CF2129C Interactive RBS
c++·算法·codeforces