首页 > 其他分享 >codeforces 1257E The Contest(lis)

codeforces 1257E The Contest(lis)

时间:2023-02-03 12:33:41浏览次数:43  
标签:200005 Contest int ans codeforces lis include pos2 pos1


codeforces 1257E The Contest(lis)_ios

codeforces 1257E The Contest(lis)_ci_02

题意:3堆数,要求使得第一堆的数为前缀,第三堆数为后缀,第二堆数为剩下的数,要求最少调整多少个数的位置使得要求成立。

其实就是就把a1,a2,a3排个序然后拼成一个数组,问题转为一个串需要多少次交换数字变成上升了,那就是n-最长上升子序列了

AC代码:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdlib.h>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<math.h>
using namespace std;
typedef long long ll;
typedef double ld;
const int INF = 0x3f3f3f3f;
const int N = 200005;
int i,j,k;
int cnt,temp,pos;
int n,m;
int x,y,z;
int a[200005],b[200005],c[200005];
int ans,pos1,pos2;
int res1[200005],res2[200005],g[200005];
int main()
{
scanf("%d %d %d",&x,&y,&z);
ans=n=x+y+z;
for(i=1; i<=x; ++i)
cin>>a[i];
for(i=1; i<=y; ++i)
cin>>b[i];
for(i=1; i<=z; ++i)
cin>>c[i];
sort(a+1,a+x+1);
sort(b+1,b+y+1);
sort(c+1,c+z+1);
pos1=1;
res1[0]=x;
for(i=1; i<=n; ++i)
{
if(a[pos1]==i)
pos1++;
res1[i]=i-pos1+1+x-pos1+1;
}
pos1=z;
pos2=y;
res2[n+1]=z;
g[n+1]=z;
for(i=n; i>0; --i)
{
if(c[pos1]==i)
pos1--;
else if(b[pos2]==i)
pos2--;
res2[i]=pos1+y-pos2;
g[i]=min(res2[i],g[i+1]);
}
for(i=0; i<=n; ++i)
ans=min((ll)ans,(ll)(res1[i]+g[i+1]-(lower_bound(c+1,c+z+1,i)-c-1)));
printf("%d\n",ans);
return 0;
}

 

标签:200005,Contest,int,ans,codeforces,lis,include,pos2,pos1
From: https://blog.51cto.com/u_15952369/6035771

相关文章

  • codeforces 1257C Dominated Subarray
    题意就是找到一个最小的子区间使得这个区间中只有一个数的个数为2.AC代码:#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<vector>#inclu......
  • Codeforces1151B-Dima and a Bad XOR(构造)
    这道题真的想复杂了,作为div2的B题肯定不算难。只要构造出任意一种异或和大于1就行,如果第一列的值异或和>1,就直接全输入1即可,如果等于0,我们只要在任意一行中找到一个不等于......
  • Codeforces Round #661 (Div. 3)
    A.RemoveSmallest题意:给定一个序列,每次操作可以任选两个差的绝对值小于等于排序后计算相邻数的差,只要有大于AC代码:constintN=2e5+50;intn,m;inta[N];intmain......
  • Codeforces Round #662 (Div. 2)
    A.RainbowDash,FluttershyandChessColoring题意:有手动写几个找找规律。AC代码:intn,m;intmain(){intT;sd(T);while(T--){sd(n);pd(n/2+1);......
  • Codeforces Round #658 (Div. 2)
    ACommonSubsequence只要找到有一个相同的元素输出即可。AC代码:constintN=1010;inta[N],b[N];intans;intcnt[N];intmain(){intt;sd(t);while(t--){......
  • Codeforces Round #657 (Div. 2)
    A.AcaciusandString题意:给你一个串,你可以把换成任意字符,使得这个串最后只出现一次暴力枚举AC代码:strings;intn;stringT="abacaba";boolcheck(string&a){int......
  • Codeforces Round #656 (Div. 3)
    A.ThreePairwiseMaximums题意:给你三个正整数和,请你找到正整数和,使得,或者确定不可能找到这样的和AC代码:intmain(){intt;sd(t);while(t--){int......
  • Codeforces Round #655 (Div. 2)
    AOmkarandCompletion只要找两个相加不等的数交叉构造即可。AC代码:intmain(){intt;sd(t);while(t--){sd(n);rep(i,1,n){if(i&1)......
  • Codeforces 1360 D. Buying Shovels
    题意:要买个铲子,商店中有中不同的卖法,依次每一次卖到个铲子,现在只能选择其中的一种买法,问最少买几次同一种的买法,使得刚好买到直接选择小于的AC代码:intn,m,k;......
  • Codeforces 1360 E. Polygon
    题意:在一个的网格上方和左边都有一排大炮,每次可以发射一个,遇到边界和都会停下来,有没有一种发射频率可以组成给出的大炮的位置在左和上,所以每个非右边界或者下边界的......