Codeforences Educational Round10 C. Foe Pairs
来源:互联网 发布:fm 迭戈科斯塔数据 编辑:程序博客网 时间:2024/05/18 18:53
【题意】给了n个数的1个排列,给了m个特殊的二元组,你可以在这n个数里面选出两个数作为一对组合,现在要求选出的这两个数不能包含m对pair的任何一对,求满足这个条件的二元组的个数。
【AC代码】
#include <stdio.h>#include <string.h>#include <iostream>using namespace std;#define inf 0x3fffffff#define ll long longint 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;}
1 0
- Codeforences Educational Round10 C. Foe Pairs
- Educational Codeforces Round 10 C. Foe Pairs
- Educational Codeforces Round 10 C. Foe Pairs
- Educational Codeforces Round 10 C. Foe Pairs
- Educational Codeforces Round 10 C. Foe Pairs
- Educational Codeforces Round 10C Foe Pairs
- coderforce Educational Codeforces Round 10 C. Foe Pairs(贪心)
- C. Foe Pairs
- C. Foe Pairs
- 【Educational Codeforces Round 10C】【脑洞 SET】Foe Pairs 不含有敌对pair的区间数
- Educational Codeforces Round 10 C. Foe Pairs —— 后缀和
- 【Codeforces 652 C Foe Pairs 】
- cf#ecr10-C. Foe Pairs- two pointers
- Code Forces 652C Foe Pairs
- Codeforces 652C Foe Pairs 【dp】
- Codeforces 652C Foe Pairs 【dp】
- CodeForces 652C Foe Pairs(思维)
- Codeforences Educational Round 11
- Codeforces Round #336 (Div. 1) C. Marbles
- 35. Search Insert Position
- Java反射机制浅谈
- Python学习:异步IO:协程和asyncio
- vim配置收藏
- Codeforences Educational Round10 C. Foe Pairs
- android ViewPager滑动事件
- kokodudu的专栏之malloc函数的用法
- poj2985The k-th Largest Group
- 第一次写博客
- 弹出窗重新加载页面错误问题
- Java中Class类浅谈
- linux kernel的中断子系统之(八):softirq
- RecyclerView在ScrollView中使用wrap_content