Educational Codeforces Round 66 差G
Educational Codeforces Round 66
F
题意:长度为 n 的序列,求有多少个区间 \([l,r]\) ,使得其构成了一个 1~r-l+1 的排列。 \(n \le 3*10^5, a_i \le n\)
key:随机权值
合法区间中肯定包含 1 ,并且最大值就是长度。先考虑最大值在 1 的右边的情况,可以枚举每个 1 的右边,记录最大值 x ,此时需要检查 \([r-x+1,r]\) 这个区间是否是一个排列。最大值在 1 左边的情况同理。
考虑 hash :给 1~n 的每个数字一个 64 位的随机权值,定义为 \(h_i\) ,这样一个长度为 k 的排列的 hash 必须是 \(h_1 \ xor \ h_2 \dots \ xor \ h_k\) ,这样就可以 O(1) check 了,所以复杂度是 O(n)。
Educational Codeforces Round 66 差G的更多相关文章
- Educational Codeforces Round 68 差G
Educational Codeforces Round 68 E 题意:有 n 个线段,每个都是平行 x 或者 y 轴,只有互相垂直的两线段才会相交.问形成了多少个矩形. \(n \le 5000, ...
- Educational Codeforces Round 66 (Rated for Div. 2) B. Catch Overflow!
链接:https://codeforces.com/contest/1175/problem/B 题意: You are given a function ff written in some bas ...
- Educational Codeforces Round 66 (Rated for Div. 2) A. From Hero to Zero
链接:https://codeforces.com/contest/1175/problem/A 题意: You are given an integer nn and an integer kk. ...
- Educational Codeforces Round 66 (Rated for Div. 2) A
A. From Hero to Zero 题目链接:http://codeforces.com/contest/1175/problem/A 题目 ou are given an integer n ...
- Educational Codeforces Round 66 (Rated for Div. 2)
A.直接模拟. #include<cstdio> #include<cstring> #include<iostream> #include<algorith ...
- Educational Codeforces Round 39 (Rated for Div. 2) G
Educational Codeforces Round 39 (Rated for Div. 2) G 题意: 给一个序列\(a_i(1 <= a_i <= 10^{9}),2 < ...
- Educational Codeforces Round 63部分题解
Educational Codeforces Round 63 A 题目大意就不写了. 挺简单的,若果字符本来就单调不降,那么就不需要修改 否则找到第一次下降的位置和前面的换就好了. #include ...
- Educational Codeforces Round 81 + Gym 102267
UPD:变色了!!!历史最高1618~ Educational Codeforces Round 81 (Rated for Div. 2) The 2019 University of Jordan ...
- Educational Codeforces Round 20
Educational Codeforces Round 20 A. Maximal Binary Matrix 直接从上到下从左到右填,注意只剩一个要填的位置的情况 view code //#pr ...
随机推荐
- 四个因素决定Essay写作段落长度
段落是一篇Essay的基石,写好Essay应从写好段落开始.那么Essay写作中一个段落多长为好?英语和修辞学教授理查德·诺德奎斯特著文介绍了一些专家的观点.从以下的译文可以看到,段落长度虽然没有固定 ...
- 爱奇艺用券付费VIP电影+python爬虫程序+可视化界面+下载本地
申明:本博客中的工具及源码仅供个人学习使用,请勿用作商业等其他任何违法用途!否则后果自负 直接步入正题吧! 工具开发环境:windows10,python3.6 工具界面设计:基于python 自带的 ...
- DevOps专题|Packer使用教程
什么是Packer 简单介绍一下自己 Packer 是一个轻量命令行工具, 能在几乎所有主流的操作系统上运行. 在给定一份配置文件的情况下, Packer 能为多种系统架构创建云主机镜像.同时 Pac ...
- PAT Advanced 1151 LCA in a Binary Tree (30) [树的遍历,LCA算法]
题目 The lowest common ancestor (LCA) of two nodes U and V in a tree is the deepest node that has both ...
- python查找数组中出现次数最多的元素
方法1-np.argmax(np.bincount()) 看一个例子 array = [0,1,2,2,3,4,4,4,5,6] print(np.bincount(array)) print(np. ...
- 并发与高并发(十三)J.U.C之AQS
前言 什么是AQS,是AbstractQueuedSynchronizer类的简称.J.U.C大大提高了并发的性能,而AQS又是J.U.S的核心. 主体概要 J.U.C之AQS介绍 J.U.C之AQS ...
- 施魔法(DP)
链接:https://ac.nowcoder.com/acm/contest/3003/H来源:牛客网 题目描述 牛可乐有 n 个元素( 编号 1..n ),第 i 个元素的能量值为 ai. 牛可乐 ...
- idea新建文件模板 (以xml文件为例)
https://blog.csdn.net/li1325169021/article/details/93158207 偷个懒
- ZJNU 2340/2341/2343 - 罗小黑的“礼物”Ⅰ/Ⅱ/Ⅲ
把一位数.两位数.三位数……这些所在的范围分开判断 可得1~9这些数范围在[1,9]内 10~99内共有90个数,每个数占两位,所以共有180位在,范围在[10,189]内 同理,100~999内共有 ...
- 向mysql数据库中插入数据时显示“Duplicate entry '1′ for key ‘PRIMARY' ”错误
错误情况如题,出现这个错误的原因十分简单: 很明显,这是主键的问题. 在一张数据表中是不能同时出现多个相同主键的数据的 这就是错误的原因,解决的方法: 1.可以将这张表设置成无主键(mysql支持,其 ...