Problem Statement

For an integer sequence $X=(X_1,X_2,\dots,X_n)$, let $X[L,R]$ denote the integer sequence $(X_L,X_{L+1},\dots,X_{R})$.

You are given integers $N$ and $M$, and $M$ quadruples of integers $(A_i,B_i,C_i,D_i)$.

Determine if there is an integer sequence $X$ of length $N$ that satisfies the following condition for every $i=1,2,\dots,M$:

  • $X[A_i,B_i]$ is lexicographically smaller than $X[C_i,D_i]$.
What is lexicographical order on sequences?

A sequence $S = (S_1,S_2,\ldots,S_{|S|})$ is lexicographically smaller than $T = (T_1,T_2,\ldots,T_{|T|})$ when 1. or 2. below holds.
Here, $|S|$ and $|T|$ denotes the lengths of $S$ and $T$, respectively.

  1. $|S| \lt |T|$ and $(S_1,S_2,\ldots,S_{|S|}) = (T_1,T_2,\ldots,T_{|S|})$.
  2. There is an integer $1 \leq i \leq \min\lbrace |S|, |T| \rbrace$ that satisfy both of the following:
    • $(S_1,S_2,\ldots,S_{i-1}) = (T_1,T_2,\ldots,T_{i-1})$.
    • $S_i$ is smaller than $T_i$ (as a number).

Constraints

  • $2 \leq N \leq 2000$
  • $1 \leq M \leq 2000$
  • $1 \leq A_i \leq B_i \leq N$
  • $1 \leq C_i \leq D_i \leq N$
  • All input values are integers.

首先一定满足 \(X_{A_i}\le X_{C_i}\),从 \(A_i\) 向 \(C_i\) 连边。

跑一次 tarjan 后,此时如果出现了大于 1 的强连通分量,那么这个分量里所有的数都是一样的,用一个并查集并起来。

如果这个强连通分量里的边有 \(i\),那么说明 \(X_{A_{i+1}}\le X_{C_{i+1}}\)

以此类推,知道某一次没有大于 1 的强连通分量,就结束了。

发现每次至少合并两个点,最多跑 \(N\) 次 tarjan。同时每次图中至多有 \(M\) 条边,所以复杂度是 \(O(NM)\) 的。

#include<bits/stdc++.h>
using namespace std;
const int N=2005;
int n,m,k,tp,st[N],hd[N],fl,e_num,tme,p[N],id[N],dfn[N],low[N],idx,a[N],b[N],c[N],d[N],fa[N];
struct edge{
int v,nxt;
}e[N];
void add_edge(int u,int v)
{
e[++e_num]=(edge){v,hd[u]};
hd[u]=e_num;
}
int find(int x)
{
if(fa[x]==x)
return x;
return fa[x]=find(fa[x]);
}
void tarjan(int x)
{
dfn[x]=low[x]=++tme;
st[++tp]=x;
for(int i=hd[x];i;i=e[i].nxt)
{
if(!dfn[e[i].v])
tarjan(e[i].v),low[x]=min(low[x],low[e[i].v]);
else if(!id[e[i].v])
low[x]=min(low[x],dfn[e[i].v]);
}
if(low[x]==dfn[x])
{
++idx;
if(st[tp]^x)
{
fl=1;
while(st[tp]^x)
id[st[tp]]=idx,fa[find(st[tp--])]=find(x);
}
id[st[tp--]]=idx;
}
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
fa[i]=i;
for(int i=1;i<=m;i++)
{
scanf("%d%d%d%d",a+i,b+i,c+i,d+i);
add_edge(a[i],c[i]);
}
while(1)
{
fl=tme=idx=0;
memset(dfn,0,sizeof(dfn));
memset(id,0,sizeof(id));
for(int i=1;i<=n;i++)
if(!dfn[i])
tarjan(i);
if(!fl)
break;
memset(hd,e_num=0,sizeof(hd));
for(int i=1;i<=m;i++)
{
while(a[i]+p[i]<=b[i]&&c[i]+p[i]<=d[i]&&find(a[i]+p[i])==find(c[i]+p[i]))
++p[i];
if(a[i]+p[i]>b[i])
{
if(d[i]-c[i]<=b[i]-a[i])
return puts("No"),0;
}
else if(c[i]+p[i]>d[i])
return puts("No"),0;
else
add_edge(find(a[i]+p[i]),find(c[i]+p[i]));
}
}
puts("Yes");
}

[ARC165D] Substring Comparison的更多相关文章

  1. Finding the Longest Palindromic Substring in Linear Time

    Finding the Longest Palindromic Substring in Linear Time Finding the Longest Palindromic Substring i ...

  2. Java and C# Comparison

    原文:http://www.harding.edu/fmccown/java_csharp_comparison.html Java Program Structure C# package hell ...

  3. LeetCode[3] Longest Substring Without Repeating Characters

    题目描述 Given a string, find the length of the longest substring without repeating characters. For exam ...

  4. 最长回文子串-LeetCode 5 Longest Palindromic Substring

    题目描述 Given a string S, find the longest palindromic substring in S. You may assume that the maximum ...

  5. POJ3693 Maximum repetition substring [后缀数组 ST表]

    Maximum repetition substring Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9458   Acc ...

  6. [LeetCode] Longest Substring with At Least K Repeating Characters 至少有K个重复字符的最长子字符串

    Find the length of the longest substring T of a given string (consists of lowercase letters only) su ...

  7. substring的用法

    public String substring(int beginIndex, int endIndex) 返回一个新字符串,它是此字符串的一个子字符串.该子字符串从指定的 beginIndex 处开 ...

  8. jQuery之常用且重要方法梳理(target,arguments,slice,substring,data,trigger,Attr)-(一)

    1.jquery  data(name) data() 方法向被选元素附加数据,或者从被选元素获取数据. $("#btn1").click(function(){ $(" ...

  9. leetcode--5. Longest Palindromic Substring

    题目来自 https://leetcode.com/problems/longest-palindromic-substring/ 题目:Given a string S, find the long ...

  10. C#和Java中的Substring()

    吐槽-使用清理软件整理电脑要注意,不要清理的"太狠",不然你会受伤的! C#中的Substring() 示例 实现代码 using System;using System.Coll ...

随机推荐

  1. pycharm+anaconda的关联

    Pycharm+anaconda的关联 关联好处:Pycharm和anaconda关联后,pycharm可以直接调用anaconda中已安装好的模块,而anaconda里安装和卸载模块都比较方便. 关 ...

  2. 使用 docker 打包构建部署 Vue 项目,一劳永逸解决node-sass安装问题

    文章源于 Jenkins 构建 Vue 项目失败,然后就把 node_modules 删了重新构建发现 node-sass 安装不上了,折腾一天终于可以稳定构建了. 犹记得从学 node 的第一天,就 ...

  3. AI绘图开源工具Stable Diffusion WebUI前端API对接

    背景 本文主要介绍 AI 绘图开源工具 Stable Diffusion WebUI 的 API 开启和基本调用方法,通过本文的阅读,你将了解到 stable-diffusion-webui 的基本介 ...

  4. C++笔记(自用)

    <Effective C++> 条款11 在operator=中处理"自我赋值" 自我赋值 证同测试: if(this==&rhs)return*this; 影 ...

  5. Redis系列22:Redis 的Pub/Sub能力

    Redis系列1:深刻理解高性能Redis的本质 Redis系列2:数据持久化提高可用性 Redis系列3:高可用之主从架构 Redis系列4:高可用之Sentinel(哨兵模式) Redis系列5: ...

  6. Solution Set -「CF 1490」

    「CF 1490A」Dense Array Link. 显然不满足的 adjacent elements 之间一直加 \(\min\times2,\min\times4,\cdots,\min\tim ...

  7. SpringBoot WebSocket STOMP

    SpringBoot WebSocket STOMP 关键词:Springboot, WebSocket, STOMP, broadcast, sendToUser, MessageMapping, ...

  8. JAVA实现单链表修改和删除数据节点

    JAVA实现单链表修改和删除数据节点 一.修改单链表中的一个节点 ①实现思路 因为带头节点的链表中头节点的next域不能发生改变(始终指向单链表的头节点),否则将找不到该链表.所以我们需要先找一个辅助 ...

  9. ChatGPT API FAQ

    ChatGPT API FAQ General questions about the ChatGPT API Written by Johanna C.. Updated over a week a ...

  10. [GKCTF 2020]cve版签到

    通过题目的提示可知,这是一个CVE(cve-2020-7066)的复现 点击进之后也无回显 看了这个cve之后,知道这个cve就是这个get_headers()会截断URL中空字符后的内容 就根据cv ...