Codeforences Educational Round10 C. Foe Pairs
【题意】给了n个数的1个排列,给了m个特殊的二元组,你可以在这n个数里面选出两个数作为一对组合,现在要求选出的这两个数不能包含m对pair的任何一对,求满足这个条件的二元组的个数。
【AC代码】
#include <stdio.h>
#include <string.h>
#include <iostream>
using namespace std;
#define inf 0x3fffffff
#define ll long long
int p[300005],b[300005];
int main()
{int n,m;scanf("%d%d",&n,&m);int x,y,x1,y1;for(int i=1; i<=n; i++){scanf("%d",&x);p[x]=i;}for(int i=1; i<=n; i++)b[i]=inf;for(int i=1; i<=m; i++){scanf("%d %d",&x,&y);x1=p[x],y1=p[y];if(x1>y1)swap(x1,y1);b[x1] = min(b[x1],y1);}for(int i=n-1; i>=1; i--){b[i] = min(b[i],b[i+1]);}ll ans=0;for(int i=1; i<=n; i++){if(b[i]==inf)ans += (n-i+1);else ans+=b[i]-i;}printf("%I64d\n",ans);return 0;
}
Codeforences Educational Round10 C. Foe Pairs相关推荐
- Educational Codeforces Round 10 C. Foe Pairs —— 后缀和
题目链接:http://codeforces.com/problemset/problem/652/C C. Foe Pairs time limit per test 1 second memory ...
- Educational Codeforces Round 10 C. Foe Pairs
C. Foe Pairs time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- Educational Codeforces Round 10 C. Foe Pairs 水题
C. Foe Pairs 题目连接: http://www.codeforces.com/contest/652/problem/C Description You are given a permu ...
- coderforce Educational Codeforces Round 10 C. Foe Pairs(贪心)
C. Foe Pairs time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- 【Educational Codeforces Round 10C】【脑洞 SET】Foe Pairs 不含有敌对pair的区间数
C. Foe Pairs time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- codeforces_652C. Foe Pairs
C. Foe Pairs time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- 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 652 C Foe Pairs 】
C. Foe Pairs time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- Codeforces 652C Foe Pairs 【dp】
C. Foe Pairs time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
最新文章
- python3 zipfile模块 zip压缩解压
- java广度优先遍历
- 在欲而无欲,居尘不染尘
- 每日英语:Apple Unveils New iPads
- iOS中常见的6种传值方式,UIPageViewController
- java 终态类,javaoo,继承,抽象类,终态类,访问修饰符!
- 使用 ‘In Place’ 直接从MySQL 5.0升级至5.7
- linux单块网卡绑定多个ip及网卡聚合绑定多个ip方法
- MAC 终端打开sublime3
- 谷粒商城:跨域问题解决
- ACDSee10 正版授权 许可证
- JAVA对接圆通API
- 前端面试需要准备什么?
- 关于我的论文以及毕业设计的一些总结吧——基于物联网技术的智能实验室管理系统设计与实现
- 分析称惠普赶走前任CEO赫德堪比苹果赶走乔布斯
- The artifact org.apache.commons:commons-io:jar:1.3.2 has been relocated to commons-io:commons-io:jar
- 更改设置并对计算机自定义,电脑别乱玩 禁用Win8.1自定义设置项
- 分析在线直播答题应用基础架构
- obj文件转gltf文件
- 【技巧】我是如何 搜索 到想要的信息的