Demo entry 6763344

mid

   

Submitted by 反对法 on Oct 22, 2018 at 03:17
Language: C++. Code size: 558 Bytes.

#include<bits/stdc++.h>
#define llt long long 
using namespace std;

const int N=3e5+777;
int pos[N];// pos[i] 表示:值i的位置
int maxn[N];// i位置的左侧最近敌人的位置
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	int x,y;
	for(int i=1;i<=n;++i){
		scanf("%d",&x);
		pos[x]=i;
	}
	while(m--){
		int u,v;
		scanf("%d%d",&u,&v);
		u=pos[u];
		v=pos[v];
		if(u>v) swap(u,v);
		maxn[v]=max(maxn[v],u);
	}
	int fir=1;
	llt ans=0;
	for(int i=1;i<=n;++i){
		if(fir<=maxn[i]&&maxn[i]<i)
			fir=maxn[i]+1;
		ans+=i-fir+1;
	}
	cout<<ans<<endl;
	return 0;
}

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).