CodeForces 652C Foe Pairs
只要计算每个位置最多能到哪个位置,累加即可,DP从后往前预处理一下每个位置到达的最远位置。
有坑点:输入的时候如果同一个点出发的,需要保存最小值。
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std; const int maxn=*+; int n,m;
int a[maxn],b[maxn];
int p[maxn]; int dp[maxn]; int main()
{
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
p[a[i]]=i;
} for(int i=;i<=n;i++) b[i]=0x7FFFFFFF; for(int i=;i<=m;i++)
{
int li,ri;scanf("%d%d",&li,&ri);
int fx=p[li];
int fy=p[ri];
if(fx>fy) swap(fx,fy);
b[fx]=min(b[fx],fy);
} dp[n]=b[n];
for(int i=n-;i>=;i--)
{
if(b[i]==0x7FFFFFFF) dp[i]=min(dp[i+],b[i]);
else dp[i]=min(dp[i+],b[i]-);
} long long ans=; for(int i=;i<=n;i++)
{
if(dp[i]==0x7FFFFFFF) ans=ans+(long long)(n-i+);
else ans=ans+(long long)(dp[i]-i+);
}
printf("%lld\n",ans); return ;
}
CodeForces 652C Foe Pairs的更多相关文章
- codeforces 652C Foe Pairs 水题
题意:给你若干个数对,给你一个序列,保证数对中的数都在序列中 对于这个序列,询问有多少个区间,不包含这些数对 分析:然后把这些数对转化成区间,然后对于这些区间排序,然后扫一遍,记录最靠右的左端点就好 ...
- Code Forces 652C Foe Pairs
C. Foe Pairs time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- codeforces 652C C. Foe Pairs(尺取法+线段树查询一个区间覆盖线段)
题目链接: C. Foe Pairs time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- Educational Codeforces Round 10 C. Foe Pairs 水题
C. Foe Pairs 题目连接: http://www.codeforces.com/contest/652/problem/C Description You are given a permu ...
- Codeforces 159D Palindrome pairs
http://codeforces.com/problemset/problem/159/D 题目大意: 给出一个字符串,求取这个字符串中互相不覆盖的两个回文子串的对数. 思路:num[i]代表左端点 ...
- codeforces#572Div2 E---Count Pairs【数学】【同余】
题目:http://codeforces.com/contest/1189/problem/E 题意:给定$n$个互不相同数,一个$k$和一个质数$p$.问这$n$个数中有多少对数$(a_i+a_j) ...
- CodeForces - 1189E Count Pairs(平方差)
Count Pairs You are given a prime number pp, nn integers a1,a2,…,ana1,a2,…,an, and an integer kk. Fi ...
- Codeforces 1188B - Count Pairs(思维题)
Codeforces 题面传送门 & 洛谷题面传送门 虽说是一个 D1B,但还是想了我足足 20min,所以还是写篇题解罢( 首先注意到这个式子里涉及两个参数,如果我们选择固定一个并动态维护另 ...
- 【CF652C】Foe Pairs(线性扫描)
题意:给你1-n的一个排列和m组数对,问有多少区间不包含任意一个数对. (1 ≤ n, m ≤ 3·105) 思路:数据范围过大,不能用容斥原理 f[i]表示以位置i上的数为左端点,右端点最小到哪里 ...
随机推荐
- CodeForces 566B Replicating Processes
#include <bits/stdc++.h> #define N 3010 #define LL long long #define unsigned U using namespac ...
- UUID 浅析
在2013年3月21日苹果已经通知开发者,从2013年5月1日起,访问UIDID的应用将不再能通过审核,替代的方案是开发者应该使用“在iOS 6中介绍的Vendor或Advertising标示符”. ...
- 对比React Native、dcloud、LuaView三个框架技术(内部)
转载自:http://www.jianshu.com/p/ee1cdb33db8d主要对比React Native和5+SDK(就是dcloud的SDK)两个: 开发语言:三个都是用其他语言来统一开发 ...
- [转]startActivityForResult的用法和demo
有时候我们需要把A activity提交数据给B activity处理,然后把结果返回给A 这种方式在很多种情况需要用到,比如我应用的程序需要有拍照上传的功能. 一种解决方案是 我的应用程序 〉调 ...
- U盘安装Centos后拔除U盘无法启动问题解决方法
今天安装CentOS后发现把引导文件安装在U盘上了,所以不插U盘就无法进入CentOS系统,在网上找到这种方法成功摆脱U盘启动,避免重新用U盘做引导盘安装系统,简单省事,所以发个帖,留着以后备用. 1 ...
- AI 人工智能 探索 (一)
碰撞检测 //逗留碰撞 void OnTriggerStay (Collider other) { if (other.transform.name == name) { //检测距离 //根据距离 ...
- java socket网络编程(多线程技术)
Client.java import java.io.*; import java.net.*; import java.util.*; public class Client { public st ...
- 链接libtorrent库时出现的问题
在QtCreator中使用libtorrent库的时候, 项目配置中 libs项配置如下: LIBS += -liconv -ltorrent-rasterbar -lboost_system -lb ...
- 一个简单的基于HTTP协议的屏幕共享应用
HTTP协议可以能是应用层协议里使用最广泛并且用途最多样的一个了.我们一般使用HTTP协议来浏览网页,但是HTTP协议还用来做很多其它用途.对开发人员来讲很常见的一种就是用HTTP协议作为各种版本控制 ...
- RAS、AES、DES加密
---------------------------------------------------------------------------------------------------- ...