首页 > 其他分享 >CF685E Travelling Through the Snow Queen's Kingdom

CF685E Travelling Through the Snow Queen's Kingdom

时间:2023-11-24 17:37:17浏览次数:28  
标签:Kingdom int CF685E Queen tp edge fi include define

题意

给定一张图,走出当前边的时间为 \(i\)。

\(q\) 次询问,问 \(s\) 是否能在 \(l \to r\) 中走到 \(t\)。

Sol

考虑将边从大到小插入图中。

注意到当前边只能对起点造成贡献。

复杂度 \(O(n \times \max\{n, m\})\)

Code

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <array>
#include <bitset>
#define int long long
#define pii pair <int, int>
using namespace std;
#ifdef ONLINE_JUDGE

#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++)
char buf[1 << 23], *p1 = buf, *p2 = buf, ubuf[1 << 23], *u = ubuf;

#endif
int read() {
	int p = 0, flg = 1;
	char c = getchar();
	while (c < '0' || c > '9') {
		if (c == '-') flg = -1;
		c = getchar();
	}
	while (c >= '0' && c <= '9') {
		p = p * 10 + c - '0';
		c = getchar();
	}
	return p * flg;
}
void write(int x) {
	if (x < 0) {
		x = -x;
		putchar('-');
	}
	if (x > 9) {
		write(x / 10);
	}
	putchar(x % 10 + '0');
}
#define fi first
#define se second
const int N = 1005, M = 2e5 + 5;
array <pii, M> edge;

struct Node {
	int l, r, s, t;
	int id;
} isl[M];
array <array <int, N>, N> f;
bitset <M> ans;

signed main() {
	int n = read(), m = read(), q = read();
	for (int i = 1; i <= m; i++)
		edge[i].fi = read(), edge[i].se = read();
	for (int i = 1; i <= q; i++) {
		isl[i].l = read(), isl[i].r = read();
		isl[i].s = read(), isl[i].t = read();
		isl[i].id = i;
	}
	sort(isl + 1, isl + 1 + q, [](Node x, Node y) {return x.l > y.l;});
	array <int, N> tp;
	tp.fill(0x7f7f7f7f);
	f.fill(tp);
	int now = 1;
	for (int i = m; i; i--) {
		f[edge[i].fi][edge[i].se] = f[edge[i].se][edge[i].fi] = i;
		for (int j = 1; j <= n; j++) f[edge[i].fi][j] = f[edge[i].se][j] = min(f[edge[i].fi][j], f[edge[i].se][j]);
		while (now <= q && isl[now].l == i) {
			if (f[isl[now].s][isl[now].t] <= isl[now].r)
				ans[isl[now].id] = 1;
			now++;
		}
	}
	for (int i = 1; i <= q; i++)
		puts((ans[i] ? "Yes" : "No"));

	return 0;
}

标签:Kingdom,int,CF685E,Queen,tp,edge,fi,include,define
From: https://www.cnblogs.com/cxqghzj/p/17854244.html

相关文章

  • T399750 Cell kingdom(Hard) 题解
    LinkT399750Cellkingdom(Hard)Qustion第一天产生\(1\)个细胞,之后的每一天,一个细胞都会分裂成\(8\)个和自己一样的细胞,每个细胞在第三天都会自爆并且带走当天产生的\(6\)个细胞,求第\(x\)天有多少细胞Solution我们设\(F[i]\)表示第\(i\)天产生的新细胞个数那么可......
  • PSO Solve N-Queen Problem
    title:PSOSolveN-QueenProblemlayout:pagecategories:dataanalysisPSOSolve16-QueenProblemTheN-Queensproblemisaclassicprobleminthefieldofcomputerscienceandcombinatorialoptimization.ItinvolvesplacingNchessqueensonanN×Nche......
  • CF587E Duff as a Queen
    维护序列,支持:区间异或查询区间子集异或值种数(包含空集)\(n\le2\times10^5\),\(1\leq\le4\times10^4\),值域\([1,10^9]\),TL=7s.经典题。操作2相当于查询区间线性基大小。由于不能维护区间异或,作差分\(b_i=a_i\oplusa_{i-1}\)。可以得到\(a_i=\oplusb_1\oplu......
  • 【刷题笔记】52. N-Queens II
    题目Then-queenspuzzleistheproblemofplacingnqueensonann×nchessboardsuchthatnotwoqueensattackeachother.Givenanintegern,returnthenumberofdistinctsolutionstothen-queenspuzzle.Example:Input:4Output:2Explanation:Therea......
  • [LeetCode] 1222. Queens That Can Attack the King
    Ona 0-indexed 8x8 chessboard,therecanbemultipleblackqueensadonewhiteking.Youaregivena2Dintegerarray queens where queens[i]=[xQueeni,yQueeni] representsthepositionofthe ith blackqueenonthechessboard.Youarealsogivena......
  • 【刷题笔记】51. N-Queens
    题目Then-queenspuzzleistheproblemofplacingnqueensonann×nchessboardsuchthatnotwoqueensattackeachother.Givenaninteger n,returnalldistinctsolutionstothe n-queenspuzzle.Eachsolutioncontainsadistinctboardconfigurationoft......
  • Kingdom
    KingdomUVA题目描述平面有\(n\)个城市,初始时城市之间没有任何双向道路连接。你的任务是依次执行以下任务:roadAB:在城市\(A\)和城市\(B\)之间连接一条双向道路,保证这条道路不和其他道路在非端点处相交。lineC:询问一条\(y=C\)的水平线和多少个州相交,以及这些州一......
  • 【大联盟】20230714 T1 三分网络(tri) 题解 CF1666K 【Kingdom Partition】
    题目描述here。题解赛时得分:\(30/30\),想了很久网络流最后不会。感觉这题就纯纯对脑洞,因为把题目中的\(2\)改成\(3\)就做不了)))不过还是相当有意思的。考虑如下建模方式:首先,考虑最小割。对于每个点\(i\),我们用两个点\(x_{i}\),\(y_i\)来表示。\(x_i\)表示\(i\)号点是......
  • [LeetCode] 51. N-Queens
    The n-queens puzzleistheproblemofplacing n queensonan nxn chessboardsuchthatnotwoqueensattackeachother.Givenaninteger n,return alldistinctsolutionstothe n-queenspuzzle.Youmayreturntheanswerin anyorder.Eachsolution......
  • 52. N-Queens II刷题笔记
    回溯算法,参考该题解classSolution:deftotalNQueens(self,n:int)->int:diag1=set()diag2=set()usedCols=set()returnself.helper(n,diag1,diag2,usedCols,0)defhelper(self,n,diag1,diag2,usedCols,......