0%

ABC-386-D - Diagonal Separation 

思路讲解

如果红色块被涂黑了,所有被红线围住的块全部也要涂黑,所以说中间不能有一个白色的块

image

形式化的来说,B(x,y),那么不能有白块 ≤ x && ≤ y。

AC代码

AC

https://atcoder.jp/contests/abc386/submissions/62215130

https://www.luogu.com.cn/record/200864278

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define ROF(i, a, b) for (int i = a; i >= b; --i)
#define SZ(x) ((int)x.size())
#define all(x,size) x.begin()+1,x.begin()+size+1
#define all1(x) x.begin(),x.end()

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef array<ll,3> arr;
typedef double DB;
const ll MAXN=static_cast<ll>(2e5)+10,MAXval=static_cast<ll>(1e18)+3;

int N,T;
//ll coly[MAXN];

int main()
{
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
cin>>N>>T;
vector<pll> wNode;
// 我们要记录的是黑色最远出现位置和白色最近出现位置
map<ll,ll> bHigh;
FOR(i, 1, T){
ll x,y;char c;
cin>>x>>y>>c;
if(c=='B'){
bHigh[x]=bHigh.find(x)==bHigh.end()?y:max(y,bHigh[x]);
}else{
wNode.push_back({x,y});
}
}
if(bHigh.empty()){ // 没有黑色块自然没那么多烦人事了
cout<<"Yes\n";
return 0;
}
ll maxHigh=0;
for(map<ll,ll>::reverse_iterator it=bHigh.rbegin();it!=bHigh.rend();++it){
it->second=max(it->second,maxHigh);
maxHigh=it->second;
}
FOR(i, 0, SZ(wNode)-1){
ll x=wNode[i].first,y=wNode[i].second;
map<ll,ll>::iterator it=bHigh.lower_bound(x);
if(it!=bHigh.end()){ // 确保lower_bound会搜到正确的东西
ll yB=it->second;
if(yB>=y){
cout<<"No\n";
return 0;
}
}
}
cout<<"Yes\n";
return 0;
}
/*
AC
https://atcoder.jp/contests/abc386/submissions/62215130
*/

心路历程(WA,TLE,MLE……)

如果出现样例结果评测机与本地结果不一致,大概率是空的情况处理有问题

还是要多防御性编程,不要相信lower_bound一定正确,避免其返回end()的情况