传送门

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. Python_面向对象进阶

    isinstance和issubclass isinstance(obj,cls)检查是否obj是否是类 cls 的对象 class Foo(object): pass obj = Foo() isi ...

  2. MySQL起别名

    好处: 便于理解 连接查询的时候,如果要查询的字段有重名的情况,使用别名可以区分开来 注意: 如果别名中有特殊符号 # 空格 ... ,需要用 "双引号" 把别名引起来单引号也行, ...

  3. 1069 The Black Hole of Numbers (20分)

    1069 The Black Hole of Numbers (20分) 1. 题目 2. 思路 把输入的数字作为字符串,调用排序算法,求最大最小 3. 注意点 输入的数字的范围是(0, 104), ...

  4. wamp修改MySQL密码

    wamp默认密码为空 用户名为root: 左击wamp绿色小图标,打开phpMyAdmin ->执行 ->账号 ->找到用户名为root的修改权限&&点击修改权限 - ...

  5. 网络常识---tracert

    当打不开一个网页,可以是用如下命令查看请求的数据走到哪里了 在命令行中输入“tracert ”并在后面加入一个IP地址,可以查询从本机到该IP地址所在的电脑要经过的路由器及其IP地址

  6. js实现汉字转拼音

    汉字转拼音,每个字首字母大写:pinyin.getFullChars(name); 提取首字母并大写:pinyin.getCamelChars(name); /* --- description: P ...

  7. 什么情况下用vue.use方法

    链接:https://blog.csdn.net/lxiang222/article/details/103376150 简而言之

  8. Linux下调试caffe

    参考博客:https://blog.csdn.net/xiaoyezi_1834/article/details/50724875 使用Anjuta 我使用的是ubuntu18.04,安装命令: su ...

  9. rabbitmq - 简单认识

    1. 概述 与 rabbitmq 做交互 amqp 最著名的实现 与 jms 最明显的区别 消息 不是去找 queue 而是去找 exchange 2. rabbitmq 基本组件 sender 发送 ...

  10. SniperOj-compare_flag-Writeup

    SniperOj-compare_flag-Writeup 题干如上,只给了一个nc命令,那么连接到服务器如下 有如下的python代码 #!/usr/bin/env python from time ...