「HNOI/AHOI2018」游戏
传送门
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」游戏的更多相关文章
- 「HNOI/AHOI2018」道路
传送门 Luogu 解题思路 考虑树形 \(\text{DP}\) 设状态 \(dp[u][i][j]\) 表示从首都走到点 \(u\) ,经过 \(i\) 条公路,\(j\) 条铁路的最小不方便值. ...
- AC日记——#2057. 「TJOI / HEOI2016」游戏 LOJ
#2057. 「TJOI / HEOI2016」游戏 思路: 最大流: 代码: #include <cstdio> #include <cstring> #include &l ...
- LOJ#3054. 「HNOI 2019」鱼
LOJ#3054. 「HNOI 2019」鱼 https://loj.ac/problem/3054 题意 平面上有n个点,问能组成几个六个点的鱼.(n<=1000) 分析 鱼题,劲啊. 容易想 ...
- loj #2508. 「AHOI / HNOI2018」游戏
#2508. 「AHOI / HNOI2018」游戏 题目描述 一次小 G 和小 H 在玩寻宝游戏,有 nnn 个房间排成一列,编号为 1,2,…,n,相邻房间之间都有 111 道门.其中一部分门上有 ...
- [Bzoj5285][洛谷P4424][HNOI/AHOI2018]寻宝游戏(bitset)
P4424 [HNOI/AHOI2018]寻宝游戏 某大学每年都会有一次Mystery Hunt的活动,玩家需要根据设置的线索解谜,找到宝藏的位置,前一年获胜的队伍可以获得这一年出题的机会. 作为新生 ...
- Solution -「HNOI 2007」「洛谷 P3185」分裂游戏
\(\mathcal{Description}\) Link. 给定 \(n\) 堆石子,数量为 \(\{a_n\}\),双人博弈,每轮操作选定 \(i<j\le k\),使 \(a_i ...
- 「HNOI 2019」白兔之舞
一道清真的数论题 LOJ #3058 Luogu P5293 题解 考虑$ n=1$的时候怎么做 设$ s$为转移的方案数 设答案多项式为$\sum\limits_{i=0}^L (sx)^i\bin ...
- 洛谷P4424 [HNOI/AHOI2018]寻宝游戏(思维题)
题意 题目链接 Sol 神仙题Orz Orz zbq爆搜70.. 考虑"与"和"或"的性质 \(0 \& 0 = 0, 1 \& 0 = 0\) ...
- 【LOJ】#2508. 「AHOI / HNOI2018」游戏
题解 把没有门的点缩成一个点 如果\(i->i + 1\)的钥匙大于\(i\),那么\(i\)不可以到\(i + 1\),连一条\(i\)到\(i + 1\)的边 如果\(i->i + 1 ...
随机推荐
- Oracle 11g安装 —— Oracle Database 11g Release2 for Windows(x64)
文章来自:https://blog.csdn.net/IT_xiao_guang_guang/article/details/104422421 下面是我的Oracle 11g安装过程,希望可以帮到正 ...
- Mac升级后如何查看自己的网络端口
OS X 10.9 下面 网络实用工具 从实用工具目录里消失了,可能这个程序用的人太少就取消了吧.但是对于做互联网的人还是有点用的. 参考http://www.mamicode.com/info-de ...
- MySQL加号+ 的作用
案例:查询员工名和员工姓,连接成一个字段,并显示为: 姓名 SELECT last_name+first_name AS 姓名 FROM employees;没有报错但姓名一下全是0 Java中的 + ...
- 在虚拟机中使用Git
自己如何从安装虚拟机到使用git进行项目代码版本管理的部分教程因为是自学所以没有好的教程只能自己进行百度,网上的教程太多了但都是只是一个模块没有从头到尾详细的教程,我们如果有个详细的教程本来只需花很少 ...
- STL初探
关于STL的一些东西 感言: 学C++不学STL函数库的人可能都是... 有点问题 头文件<algorithm>的一些东西 sort,快排: 这是个初学者必需掌握的东西,及其好用,因为方( ...
- clippingNode 裁剪
let stencil = new cc.Sprite(fileName); let clippingNode = new cc.ClippingNode();this.addChild(clippi ...
- C++-POJ1018-Communication System
贪心算法:先排序,再枚举最小带宽(B),每次更新当前最小花费(P)和以及答案(ans) #include <cstdio> #include <algorithm> using ...
- 解决“(1146, "Table 'mydb.django_session' doesn't exist")”报错的方法
执行 ./manage.py makemigrations sessions ./manage.py migrate sessions
- 微信小程序 (全局配置和页面配置)
全局配置 app.json 文件用来对微信小程序进行全局配置. 一.配置页面路径 二.window 配置全局默认的窗口 navigationBarTextStyle:导航栏的标题颜色 navigati ...
- Tex 论文写作 jpg eps图像
pdflatex只能支持pdf.jpg.jpeg.png共4中格式的图片.所以在插入eps图像是会没法显示,使用latex编译不存在这个问题,但是,我还不会用,编译完后从哪里看不知道. 这个里面说的详 ...