「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 ...
随机推荐
- SQL Server经典sql语句大全(转)
一.基础1.说明:创建数据库CREATE DATABASE database-name2.说明:删除数据库drop database dbname3.说明:备份sql server--- 创建 备份数 ...
- sofa
来源:http://fangpeng123456789.iteye.com/blog/2172745 sofa app: biz:业务实现层(业务类型) common: ...
- 项目中的process.bpmn的读-过程
1.这次项目中遇到了process.bpmn类的封装好的类.怎么读呢?不知道,一周过去了,总算明白点. 2.首先也是从Controller开始,走进service层,比如mybatis,调用的就不是m ...
- (转载)Docker的boot2docker.iso镜像使用
原文路径:https://blog.csdn.net/jiangjingxuan/article/details/54908272#commentsedit 在Docker首次启动时需要下载的一个bo ...
- 条件锁condition与Queue()
在学习之前你应该先了解锁和队列基础 import queue import time import random import threading import asyncio import logg ...
- Seekbar扩大点击区域
//扩大点击区域private void enlargeSeekBar() { mContentView.setOnTouchListener(new OnTouchListener() {//mCo ...
- 同步块:synchronized(同步监视器对象){同步运行代码片段}
package seday10; import seday03.Test2; /** * @author xingsir * 同步块:synchronized(同步监视器对象){需要同步运行的代码片段 ...
- 教你如何用python和pygame制作一个简单的贪食蛇游戏,可自定义
1.效果图 2.完整的代码 #第1步:导出模块 import pygame, sys, random from pygame.locals import * # 第2步:定义颜色变量,在pygame中 ...
- 微信小程序苹果手机调用camera原生组件拍照后不退出
最近做微信小程序时,用到小程序的原生组件camera时,踩到一个bug. 在给camera设置样式position:absolute;绝对定位后,IOS调用camera原生组件拍照后退不出来. 不使用 ...
- 一段代码实现Aplayer+网易云音乐接口
玩cnblogs的小伙伴可以将以下代码复制到页脚html当中哦 <!-- require APlayer --> <link rel="stylesheet" h ...