传送门

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. 使用 Razor 表达式

    https://blog.csdn.net/github_37410569/article/details/54986136 https://blog.csdn.net/qq_21419015/art ...

  2. powerdesigner16.5改变数据模型字体大小

    1. 点击 2. 选择 3. 选择完点击确定后: 4. 点击设为默认:再点ok

  3. stm32f103中freertos的tasks基本使用案例及备忘

    基本实例   freetos的在stm32中使用踩了一些坑,事情做完了,就 做个备忘,希望能给后面的人一些借鉴. 先给出一个实际的例子吧. 启动代码 void task_create(void) { ...

  4. 浅谈对Jquery+JSON+WebService的使用小结

    https://www.jb51.net/article/36207.htm  更新时间:2013年04月28日 12:19:55   作者:    我要评论   本篇文章介绍了对Jquery+JSO ...

  5. string常用成员函数

    string常用成员函数 std::string::clear Clear string Erases the contents of the string, which becomes an emp ...

  6. next路由跳转监听

    next的路由跳转监听事件 { “routeChangeStart”, "beforeHisroryChange" "routeChangeComplete", ...

  7. 常见的一些mysql多表操作收集(备份)

    原帖地址:https://blog.csdn.net/qq_37248648/article/details/78468291 多表操作框架 SELECT A.ID, A.NUMBER, A.PRIC ...

  8. LOJ#6713. 「EC Final 2019」狄利克雷 k 次根 加强版

    题目描述 定义两个函数 \(f, g: \{1, 2, \dots, n\} \rightarrow \mathbb Z\) 的狄利克雷卷积 \(f * g\) 为: \[ (f * g)(n) = ...

  9. jmeter实现IP欺骗

    用jmeter模拟多个IP同时向一个目标发送请求 1.IP地址参数化 在csv文件中编辑参数化IP地址列表,参数化的IP需在同一个局域网,子网掩码相同(比如和客户端本机同一网段),如下 将csv列表中 ...

  10. java.util.Properties类,保存时保留注释及格式不变

    原文地址:http://blog.csdn.net/benbenxiongyuan/article/details/53006097 参考地址:http://www.iteye.com/topic/1 ...