当前位置:网站首页>AT2336 [ARC069D] Flags
AT2336 [ARC069D] Flags
2022-07-22 16:43:00 【Have a cold moon in your heart】
AT2336 [ARC069D] Flags
Two points answer ,2-sat
determine , The line tree optimizes the edge construction .
On the line segment tree, the father connects to the son .
For each point x x x, The distance from him is no more than m i d mid mid The inverse of the point of , Express election x x x You can only choose not to be more than m i d mid mid The point of .
Finally run tarjan
Just decide .
Time complexity O ( n log 2 n ) \mathcal O(n\log ^2n) O(nlog2n).
#include<bits/stdc++.h>
using namespace std;
//#define int long long
typedef long long ll;
#define ha putchar(' ')
#define he putchar('\n')
inline int read() {
int x = 0, f = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-')
f = -1;
c = getchar();
}
while (c >= '0' && c <= '9')
x = x * 10 + c - '0', c = getchar();
return x * f;
}
inline void write(int x) {
if (x < 0) {
putchar('-');
x = -x;
}
if (x > 9)
write(x / 10);
putchar(x % 10 + '0');
}
const int _ = 8e4 + 10;
int n, cnt, idx, scc, low[_], dfn[_], id[_], Id[_];
stack<int> s;
vector<pair<int, int>> d;
vector<int> e[_];
void build(int o, int l, int r) {
id[o] = ++cnt;
if (o > 1) e[id[o >> 1]].emplace_back(cnt);
if (l == r) {
int v = d[l - 1].second;
e[id[o]].push_back(v <= n ? v + n : v - n);
return;
}
int mid = (l + r) >> 1;
build(o << 1, l, mid), build(o << 1 | 1, mid + 1, r);
}
void upd(int o, int l, int r, int L, int R, int x) {
if(L > R) return;
if (L <= l && r <= R) {
e[x].emplace_back(id[o]);
return;
}
int mid = (l + r) >> 1;
if (L <= mid) upd(o << 1, l, mid, L, R, x);
if (R > mid) upd(o << 1 | 1, mid + 1, r, L, R, x);
}
pair<int, int> get(int i, int m) {
pair<int, int> ret;
int l = 1, r = i, mid;
while (l <= r) {
mid = (l + r) >> 1;
if (d[i - 1].first - d[mid - 1].first >= m) l = mid + 1;
else r = mid - 1;
}
ret.first = r + 1, l = i, r = n << 1;
while (l <= r) {
mid = (l + r) >> 1;
if (d[mid - 1].first - d[i - 1].first < m) l = mid + 1;
else r = mid - 1;
}
ret.second = l - 1;
return ret;
}
void tarjan(int u) {
low[u] = dfn[u] = ++idx;
s.push(u);
for (int v : e[u])
if (!dfn[v]) {
tarjan(v);
low[u] = min(low[u], low[v]);
} else if (!Id[v]) low[u] = min(low[u], dfn[v]);
if (low[u] == dfn[u]) {
++scc;
while (1) {
int nw = s.top();
s.pop();
Id[nw] = scc;
if (nw == u) break;
}
}
}
bool check(int lim) {
scc = idx = 0;
memset(low, 0, sizeof low);
memset(dfn, 0, sizeof dfn);
memset(Id, 0, sizeof Id);
for (int i = 0; i < _; ++i) e[i].clear();
build(1, 1, cnt = n << 1);
for (int i = 1; i <= n << 1; ++i) {
int r = d[i - 1].second;
pair<int, int> p = get(i, lim);
upd(1, 1, n << 1, p.first, i - 1, r);
upd(1, 1, n << 1, i + 1, p.second, r);
}
for (int i = 1; i <= n << 1; ++i)
if (!dfn[i]) tarjan(i);
for (int i = 1; i <= n; ++i)
if (Id[i] == Id[i + n]) return 0;
return 1;
}
signed main() {
n = read();
for (int i = 1, x, y; i <= n; ++i) {
x = read(), y = read();
d.emplace_back(make_pair(x, i));
d.emplace_back(make_pair(y, i + n));
}
sort(d.begin(), d.end());
int l = 0, r = 1e9, mid;
while (l <= r) {
mid = (l + r) >> 1;
if (check(mid)) l = mid + 1;
else r = mid - 1;
}
write(l - 1), he;
return 0;
}
边栏推荐
- Chaque jour - jour 41 - 125. Vérifier la chaîne de palindromes
- ARC110E Shorten ABC
- Switch and router technology: OSPF route redistribution, OSPF NSSA area and OSPF virtual link
- This easy-to-use office network optimization tool is free
- ECCV 2022 | 修正FPN帶來的大目標性能損害:You Should Look at All Objects
- Process and thread interview questions
- On the continuous chain use of promise then
- 源启数字化:既有模式,还是开源创新?|砺夏行动
- Memory management interview questions
- Execute function semicolon immediately
猜你喜欢
大文件切片上传和断点续传
交換機與路由器技術:標准ACL、擴展ACL和命名ACL
The Prospectus has written "yuancosmos" 318 times! Feitian Yundong fights Hong Kong stocks again "yuancosmos first share"“
Command line code for server and local data transmission
【Leetcode周赛--哈希表数对】6164.数位和相等数对的最大和
Leetcode 234. palindrome linked list
源启数字化:既有模式,还是开源创新?|砺夏行动
【Leetcode数组--排序+辗转相除法最大公约数】6122.使数组可以被整除的最少删除次数
Fastjson code execution cve-2022-25845
UE4 进入指定区域实现触发加速功能
随机推荐
[unity] the UI follows the 3D object, and the world coordinates turn to UI coordinates
The competition of trillion market value public chain is white hot. Is there still a chance for the new public chain?
toString()及重写的作用与应用
Methods of checking the ranking of papers and periodicals
Sort -- insert sort and Hill sort in sort
Fundamentals of action theory
UE4 钥匙开门
QDataStream
The Prospectus has written "yuancosmos" 318 times! Feitian Yundong fights Hong Kong stocks again "yuancosmos first share"“
Li Kou daily question - day 41 -125. Verify the palindrome string
Switch and router technology: static NAT, dynamic NAT, pat and port mirroring
JVM memory model: runtime data area and thread
AcWing_11. 背包问题求方案数_dp
string的模拟实现
LeetCode 每日一题——814. 二叉树剪枝
CF464E The Classic Problem
Leetcode 234. palindrome linked list
Process and thread interview questions
高数_第2章多元函数微分学_隐函数的偏导数
Pixels and colors