【题意】给了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相关推荐

  1. Educational Codeforces Round 10 C. Foe Pairs —— 后缀和

    题目链接:http://codeforces.com/problemset/problem/652/C C. Foe Pairs time limit per test 1 second memory ...

  2. 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 ...

  3. Educational Codeforces Round 10 C. Foe Pairs 水题

    C. Foe Pairs 题目连接: http://www.codeforces.com/contest/652/problem/C Description You are given a permu ...

  4. 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 ...

  5. 【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 ...

  6. codeforces_652C. Foe Pairs

    C. Foe Pairs time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  7. Code Forces 652C Foe Pairs

    C. Foe Pairs time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  8. 【Codeforces 652 C Foe Pairs 】

    C. Foe Pairs time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  9. Codeforces 652C Foe Pairs 【dp】

    C. Foe Pairs time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

最新文章

  1. python3 zipfile模块 zip压缩解压
  2. java广度优先遍历
  3. 在欲而无欲,居尘不染尘
  4. 每日英语:Apple Unveils New iPads
  5. iOS中常见的6种传值方式,UIPageViewController
  6. java 终态类,javaoo,继承,抽象类,终态类,访问修饰符!
  7. 使用 ‘In Place’ 直接从MySQL 5.0升级至5.7
  8. linux单块网卡绑定多个ip及网卡聚合绑定多个ip方法
  9. MAC 终端打开sublime3
  10. 谷粒商城:跨域问题解决
  11. ACDSee10 正版授权 许可证
  12. JAVA对接圆通API
  13. 前端面试需要准备什么?
  14. 关于我的论文以及毕业设计的一些总结吧——基于物联网技术的智能实验室管理系统设计与实现
  15. 分析称惠普赶走前任CEO赫德堪比苹果赶走乔布斯
  16. The artifact org.apache.commons:commons-io:jar:1.3.2 has been relocated to commons-io:commons-io:jar
  17. 更改设置并对计算机自定义,电脑别乱玩 禁用Win8.1自定义设置项
  18. 分析在线直播答题应用基础架构
  19. obj文件转gltf文件
  20. 【技巧】我是如何 搜索 到想要的信息的

热门文章

  1. 微信网页获取用户授权-----LoveEmperor-王子様
  2. 微信公众号调用视频列表(自定义菜单)
  3. python用户登陆程序 要求用户名和密码_python开发基础作业01:模拟登陆系统
  4. phpstorm配置phpunit,进行php单元测试
  5. 关于state刷新界面的思考
  6. 西门子smart-PLC的数据块
  7. Kubernetes基础:创建资源的方式
  8. 如何快速设计业务架构?
  9. JavaScript实现走马灯效果[无缝连接、循环滚动]
  10. Pytorch优化器全总结(三)牛顿法、BFGS、L-BFGS 含代码