传送门

Luogu

解题思路

这是一道 \(O(n^2)\) 暴力加上 \(\text{random_shuffle}\) 优化 什么鬼 就可以 \(\text{AC}\) 的题。

但还是要讲一下 \(O(n)\) 的正解。

算了我不讲了咕咕咕,可以去这里

细节注意事项

  • 有点难想,但是并不难写

参考代码

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#define rg register
using namespace std;
template < typename T > inline void read(T& s) {
s = 0; int f = 0; char c = getchar();
while (!isdigit(c)) f |= (c == '-'), c = getchar();
while (isdigit(c)) s = s * 10 + (c ^ 48), c = getchar();
s = f ? -s : s;
} const int _ = 1000010; int n, m, q, key[_];
int L[_], R[_], co[_], col = 1, dgr[_];
int tot, head[_], nxt[_], ver[_];
inline void Add_edge(int u, int v)
{ nxt[++tot] = head[u], head[u] = tot, ver[tot] = v; } inline void expand(int x) {
while (1) {
int flag = 0;
while (L[x] > 1 && L[x] <= key[L[x] - 1] && key[L[x] - 1] <= R[x])
flag = 1, L[x] = L[co[L[x] - 1]];
while (R[x] < n && L[x] <= key[R[x]] && key[R[x]] <= R[x])
flag = 1, R[x] = R[co[R[x] + 1]];
if (!flag) return;
}
} inline void toposort() {
static queue < int > Q;
for (rg int i = 1; i <= col; ++i)
if (!dgr[i]) Q.push(i);
while (!Q.empty()) {
int u = Q.front(); Q.pop();
expand(u);
for (rg int i = head[u]; i; i = nxt[i])
if (!--dgr[ver[i]]) Q.push(ver[i]);
}
} int main() {
#ifndef ONLINE_JUDGE
freopen("in.in", "r", stdin);
#endif
read(n), read(m), read(q);
for (rg int x, y, i = 1; i <= m; ++i)
read(x), read(y), key[x] = y;
for (rg int i = 1; i <= n; ++i) {
if (key[i - 1] != 0) ++col;
co[i] = col, R[col] = i;
if (!L[col]) L[col] = i;
}
for (rg int i = 1; i <= n; ++i) {
if (key[i] == 0) continue;
if (co[i] < co[key[i]])
Add_edge(co[i], co[i] + 1), ++dgr[co[i] + 1];
else
Add_edge(co[i] + 1, co[i]), ++dgr[co[i]];
}
toposort();
for (rg int s, t, i = 1; i <= q; ++i)
read(s), read(t), puts(L[co[s]] <= t && t <= R[co[s]] ? "YES" : "NO");
return 0;
}

完结撒花 \(qwq\)

「HNOI/AHOI2018」游戏的更多相关文章

  1. 「HNOI/AHOI2018」道路

    传送门 Luogu 解题思路 考虑树形 \(\text{DP}\) 设状态 \(dp[u][i][j]\) 表示从首都走到点 \(u\) ,经过 \(i\) 条公路,\(j\) 条铁路的最小不方便值. ...

  2. AC日记——#2057. 「TJOI / HEOI2016」游戏 LOJ

    #2057. 「TJOI / HEOI2016」游戏 思路: 最大流: 代码: #include <cstdio> #include <cstring> #include &l ...

  3. LOJ#3054. 「HNOI 2019」鱼

    LOJ#3054. 「HNOI 2019」鱼 https://loj.ac/problem/3054 题意 平面上有n个点,问能组成几个六个点的鱼.(n<=1000) 分析 鱼题,劲啊. 容易想 ...

  4. loj #2508. 「AHOI / HNOI2018」游戏

    #2508. 「AHOI / HNOI2018」游戏 题目描述 一次小 G 和小 H 在玩寻宝游戏,有 nnn 个房间排成一列,编号为 1,2,…,n,相邻房间之间都有 111 道门.其中一部分门上有 ...

  5. [Bzoj5285][洛谷P4424][HNOI/AHOI2018]寻宝游戏(bitset)

    P4424 [HNOI/AHOI2018]寻宝游戏 某大学每年都会有一次Mystery Hunt的活动,玩家需要根据设置的线索解谜,找到宝藏的位置,前一年获胜的队伍可以获得这一年出题的机会. 作为新生 ...

  6. Solution -「HNOI 2007」「洛谷 P3185」分裂游戏

    \(\mathcal{Description}\)   Link.   给定 \(n\) 堆石子,数量为 \(\{a_n\}\),双人博弈,每轮操作选定 \(i<j\le k\),使 \(a_i ...

  7. 「HNOI 2019」白兔之舞

    一道清真的数论题 LOJ #3058 Luogu P5293 题解 考虑$ n=1$的时候怎么做 设$ s$为转移的方案数 设答案多项式为$\sum\limits_{i=0}^L (sx)^i\bin ...

  8. 洛谷P4424 [HNOI/AHOI2018]寻宝游戏(思维题)

    题意 题目链接 Sol 神仙题Orz Orz zbq爆搜70.. 考虑"与"和"或"的性质 \(0 \& 0 = 0, 1 \& 0 = 0\) ...

  9. 【LOJ】#2508. 「AHOI / HNOI2018」游戏

    题解 把没有门的点缩成一个点 如果\(i->i + 1\)的钥匙大于\(i\),那么\(i\)不可以到\(i + 1\),连一条\(i\)到\(i + 1\)的边 如果\(i->i + 1 ...

随机推荐

  1. Resharper快捷键使用

    1:   Alt+F7将你光标所在位置的变量的所有使用以列表的方式显示出来,显示结果的窗体可以像其他窗体那样停靠. 它的优点包括: 可以从所有使用中挑选只显示read usage或者write usa ...

  2. Django中间件,CSRF(跨站请求伪造),缓存,信号,BootStrap(模板)-响应式(栅格)+模板

    Django中间件,CSRF(跨站请求伪造),缓存,信号,BootStrap(模板)-响应式(栅格)+模板 1.中间件(重要): 在Django的setting中有个MIDDLEWARE列表,里面的东 ...

  3. HTML的背景

    HTML HTML(超文本标记语言),超文本包括:文字.图片.音频.视频.动画等. W3C(万维网联盟)标准包括: 结构化标准语言(HTML.XML) 1.1. HTML(超文本标记语言):用来显示数 ...

  4. STM32F103之DMA学习记录

    /================翻译STM32F103开发手册DMA章节===========================/ 13 DMA(Direct memory access) 13.1 ...

  5. 马路 树链剖分/线段树/最近公共祖先(LCA)

    题目 [问题描述] 小迟生活的城市是⼀棵树(树指的是⼀个含有 \(n\) 个节点以及 \(n-1\) 条边的⽆向连通图),节点编号从 \(1\) 到 \(n\),每条边拥有⼀个权值 \(value\) ...

  6. Go_sqlx和占位符

    sqlx使用 第三方库sqlx能够简化操作,提高开发效率. 安装 go get github.com/jmoiron/sqlx package main import ( "fmt" ...

  7. EAC3 Transient Pre-Noise Processing

    Transient pre-noise processing用于减少pre-noise的长度,pre-noise产生于low bitrate 编码存在transient matiral的场景. 当使用 ...

  8. 【Python】变量命名习惯

    仅供参考,个人习惯

  9. 【做题笔记】UVA11988破损的键盘

    本题可以在洛谷评测,但需要绑定账号 首先解释一下:Home键的作用是把光标移动,End键的作用是返回上次按Home键的地方 考虑朴素做法:输入为[时下一次插入在数组最前端,然后元素整体向后:同时令 l ...

  10. 前台后台$.psot交互

    前台 {include file='public/header' /} <body class="login-bg"> <div class="logi ...