CodeForces 689 D Friends and Subsequences
题解:
如果左端点来说, 那么对于a[i]来说是向上的一条折线, b[i]来说是向下的一条折线, 那么如果这2个折线求交点个数的话, 我们可以二分去求第一个 a[i] == b[i] 的地方, 求最后一个a[i] == b[i]的地方。
代码:
- #include<bits/stdc++.h>
- using namespace std;
- #define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
- #define LL long long
- #define ULL unsigned LL
- #define fi first
- #define se second
- #define pb push_back
- #define lson l,m,rt<<1
- #define rson m+1,r,rt<<1|1
- #define lch(x) tr[x].son[0]
- #define rch(x) tr[x].son[1]
- #define max3(a,b,c) max(a,max(b,c))
- #define min3(a,b,c) min(a,min(b,c))
- typedef pair<int,int> pll;
- const int inf = 0x3f3f3f3f;
- const int _inf = 0xc0c0c0c0;
- const LL INF = 0x3f3f3f3f3f3f3f3f;
- const LL _INF = 0xc0c0c0c0c0c0c0c0;
- const LL mod = (int)1e9+;
- const int N = 2e5 + ;
- int a[N], b[N];
- int Log[N];
- int Max[N][];
- int Min[N][];
- void init(int n) {
- for(int i = -(Log[]=-); i < N; i++)
- Log[i] = Log[i - ] + ((i & (i - )) == );
- for(int i = ; i <= n; ++i) Max[i][] = a[i], Min[i][] = b[i];
- for(int j = ; j <= Log[n]; j++)
- for(int i = ; i+(<<j)- <= n; i++)
- Max[i][j] = max(Max[i][j-], Max[i+(<<(j-))][j-]),
- Min[i][j] = min(Min[i][j-], Min[i+(<<(j-))][j-]);
- }
- int QMin(int l, int r) {
- int k = Log[r - l + ];
- return min(Min[l][k], Min[r-(<<k)+][k]);
- }
- int QMax(int l, int r){
- int k = Log[r - l + ];
- return max(Max[l][k], Max[r-(<<k)+][k]);
- }
- int main(){
- int n;
- scanf("%d", &n);
- for(int i = ; i <= n; ++i) scanf("%d", &a[i]);
- for(int i = ; i <= n; ++i) scanf("%d", &b[i]);
- init(n);
- LL ans = ;
- for(int i = ; i <= n; ++i){
- int l = i, r = n;
- while(l <= r){
- int m = l+r >> ;
- if(QMin(i, m) > QMax(i, m)) l = m + ;
- else r = m - ;
- }
- if(QMin(i, l) != QMax(i, l)) continue;
- int tl = l;
- l = i, r = n;
- while(l <= r){
- int m = l+r >> ;
- if(QMin(i, m) >= QMax(i, m)) l = m + ;
- else r = m - ;
- }
- ans += l - tl;
- }
- cout << ans << endl;
- return ;
- }
CodeForces 689 D Friends and Subsequences的更多相关文章
- codeforces 689 Mike and Shortcuts(最短路)
codeforces 689 Mike and Shortcuts(最短路) 原题 任意两点的距离是序号差,那么相邻点之间建边即可,同时加上题目提供的边 跑一遍dijkstra可得1点到每个点的最短路 ...
- Codeforces Testing Round #12 C. Subsequences 树状数组维护DP
C. Subsequences Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/probl ...
- Codeforces Testing Round #12 C. Subsequences 树状数组
C. Subsequences For the given sequence with n different elements find the number of increasing s ...
- codeforces 689D D. Friends and Subsequences(RMQ+二分)
题目链接: D. Friends and Subsequences time limit per test 2 seconds memory limit per test 512 megabytes ...
- 【codeforces 314C】Sereja and Subsequences
[题目链接]:http://codeforces.com/problemset/problem/314/C [题意] 让你从n个元素的数组中选出所有的不同的非递减子数列; 然后计算比这个子数列小的和它 ...
- codeforces 689 E. Mike and Geometry Problem 组合数学 优先队列
给定一个函数: f([l,r]) = r - l + 1; f(空集) = 0; 即f函数表示闭区间[l,r]的整点的个数 现在给出n个闭区间,和一个数k 从n个区间里面拿出k个区间,然后对这k个区间 ...
- codeforces 361 D - Friends and Subsequences
原题: Description Mike and !Mike are old childhood rivals, they are opposite in everything they do, ex ...
- 【22.48%】【codeforces 689D】Friends and Subsequences
time limit per test2 seconds memory limit per test512 megabytes inputstandard input outputstandard o ...
- Codeforces Round #361 (Div. 2) D. Friends and Subsequences 二分
D. Friends and Subsequences 题目连接: http://www.codeforces.com/contest/689/problem/D Description Mike a ...
随机推荐
- nginx 301跳转https后post请求失效问题解决
app本地请求是http端口,后来升级https强制301跳转,设置如下 server { listen 80; server name www.XXX.com; rewrite ^/(.*)$ ht ...
- 制造资源计划(Manufacturing Resource Planning,Mrp II)
制造资源计划(Manufacturing Resource Planning,Mrp II) 概括: 以物料需求计划(MRP)为核心的企业生产管理计划系统,MRP II 是以工业工 ...
- 灰度级分层(一些基本的灰度变换函数)基本原理及Python实现
1. 基本原理 灰度级分层通常用于突出感兴趣的特定灰度范围内的亮度.灰度级分层有两大基本方法. 将感兴趣的灰度范围内的值显示为一个值(比如0),而其他范围的值为另外一个值(255). 将感兴趣的灰度范 ...
- SpringBoot-Admin的使用
[**前情提要**]Spring Boot Actuator 提供了对单个 Spring Boot 应用的监控,信息包含应用状态.内存.线程.堆栈等,比较全面的监控了 Spring Boot 应用的整 ...
- 【Kubernetes 系列五】在 AWS 中使用 Kubernetes:EKS
目录 1. 概述 2. 版本 3. 预备 3.1. 操作环境 3.2. 角色权限 3.2.1. CloudFormation 完全权限 3.2.2. EKS 读写权限 3.2.3. EC2 相关权限 ...
- Java并发之内存模型(JMM)浅析
背景 学习Java并发编程,JMM是绕不过的槛.在Java规范里面指出了JMM是一个比较开拓性的尝试,是一种试图定义一个一致的.跨平台的内存模型.JMM的最初目的,就是为了能够支多线程程序设计的,每个 ...
- Mybatis框架(9)---Mybatis自定义插件生成雪花ID做为表主键项目
Mybatis自定义插件生成雪花ID做为主键项目 先附上项目项目GitHub地址 spring-boot-mybatis-interceptor 有关Mybatis雪花ID主键插件前面写了两篇博客作为 ...
- @Validated和@Valid区别
注解地方 @Validated:可以用在类型.方法和方法参数上.但是不能用在成员属性(字段)上 @Valid:可以用在方法.构造函数.方法参数和成员属性(字段)上 两者是否能用于成员属性(字段)上直接 ...
- Android进阶之绘制-自定义View完全掌握(一)
Android的UI设计可以说是决定一个app质量的关键因素,因为人们在使用app的时候,最先映入眼帘的就是app的界面了,一个美观.充实的界面能够给用户带来非常好的体验,会在用户心中留下好的印象. ...
- 存储型XSS的发现经历和一点绕过思路
再次骚扰 某SRC提现额度竟然最低是两千,而已经有750的我不甘心呐,这不得把这2000拿出来嘛. 之后我就疯狂的挖这个站,偶然发现了一个之前没挖出来的点,还有个存储型XSS! 刚开始来到这个之前挖过 ...