首页 > 其他分享 >Educational Codeforces Round 123 D

Educational Codeforces Round 123 D

时间:2022-09-02 20:58:11浏览次数:37  
标签:Educational int mn1 mn2 Codeforces second 123 auto mpy

D. Cross Coloring

很容易想到的就是分成几个块 有几个就是k多少次幂
但是显然暴力的做法是n2的 我们考虑如何优化
我们考虑对每一行 这个x[i]能成立的条件是啥 那就是y[i]里有比他更小的即可
对于列也是如此
最后要注意的就是要特判0的情况

#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+20;
const int M = 998244353;
const int mod = 998244353;
#define int long long
#define endl '\n'
#define Endl '\n'
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;
#define _ 0
#define inf 0x3f3f3f3f3f3f3f3f
#define fast ios::sync_with_stdio(false);cin.tie(nullptr);
int qpow(int a,int k,int p){
    int res=1;
    while(k){
        if(k&1)res=res*a%p;
        k>>=1;
        a=a*a%p;
    }
    return res;
}
void solve() {
    int n,m,k,q;cin>>n>>m>>k>>q;
    map<int,int>mpx,mpy;
    for(int i=1;i<=q;i++){
        int x,y;cin>>x>>y;
        mpx[x]=i;
        mpy[y]=i;
    }
    set<int>s;
    int mn1=inf,mn2=inf;
    for(auto i:mpx)mn1=min(mn1,i.second);
    for(auto i:mpy)mn2=min(mn2,i.second);
    if(mpx.size()!=n)mn1=0;
    if(mpy.size()!=m)mn2=0;
    for(auto i:mpx){
        if(i.second>=mn2)s.insert(i.second);
    }
    for(auto i:mpy){
        if(i.second>=mn1)s.insert(i.second);
    }
    cout<<qpow(k,s.size(),mod)<<endl;
}
signed main(){
    fast
    int T;cin>>T;
    while(T--) {
        solve();
    }
    return ~~(0^_^0);
}

标签:Educational,int,mn1,mn2,Codeforces,second,123,auto,mpy
From: https://www.cnblogs.com/ycllz/p/16651186.html

相关文章

  • Educational Codeforces Round 123 E
    E.ExpandthePath我们画出一个合法的一般性的来研究比如RDRDR我们可以将其任意一个往下往右延长但是这个图形获得的面积是不规则的但是我们知道合法的序列肯定是......
  • Codeforces Round #814 (Div. 2)
    Preface关于军训……它死了第一次感觉到疫情的好处,就是不知道训了一半给不给学分,要不要补训一直打隔膜颓废也不是办法,因此来写写题(才不是因为路由器没到舍不得用流量更......
  • Educational Codeforces Round 134 (Rated for Div. 2) D Maximum AND
    MaximumAND贪心从高位开始,尽可能地让\(a\)中该位为\(0\)的和\(b\)中该位为\(1\)的配对在一起,换句话说,可以让\(a\)由小到大排序,\(b\)由大到小排序如果当......
  • codeforces极简题解
    CF1713F利用lucas定理,\(b_S\)表示下标\(T\)与\(S\)无交的\(a_T\)的异或,由于部分\(b_S\)未知,不能直接iFWT。回顾容斥:\([S=\emptyset]=\sum_{T\subseteqS}(-1)^|T|\),\([n=0......
  • Codeforces Round #773 E
    AnonymityIsImportant我们最开始会想到用三个状态表示其实并不用我们只需要用0表示这个人没病1表示不确定有病(这样我们就可以用set来做了)要是一个区间给了有病我们......
  • Educational Codeforces Round 134 (Rated for Div. 2)
    DMaxiumAnd贪心,优先满足高位,每次判断是否能够满足这一位答案为1,如果能则更新答案,这样显然是优的EPrefixFunction模仿求前缀函数的算法,先预处理求出\(|S|\)的前缀函......
  • Educational Codeforces Round 134 (Rated for Div. 2)
    EducationalCodeforcesRound134(RatedforDiv.2)目录EducationalCodeforcesRound134(RatedforDiv.2)D.MaximumANDE.PrefixFunctionQueriesD.Maximum......
  • Codeforces Round #606(B-D)
     Dashboard-CodeforcesRound#606(Div.2,basedonTechnocup2020EliminationRound4)-CodeforcesB.MakeThemOdd题意:一个数组,每次选择一个数,将数组中的......
  • 使用selenium自动化模块实现登录12306
    importtimefromselenium.webdriverimportChromefromselenium.webdriver.chrome.optionsimportOptionsfromselenium.webdriver.common.byimportByfromselenium.w......
  • Codeforces Round #817 (Div. 4) ABCDEFG
    https://codeforces.com/contest/1722/problem/A#include<bits/stdc++.h>usingnamespacestd;typedeflonglongLL;typedefpair<int,int>PII;constintN=200200,......