Educational Codeforces Round 76 (Rated for Div. 2) E (rising longest sequence)

#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
int a[200007],b[200007],c[200007];
int cnt1[200007],cnt2[200007],cnt3[200007];
int mn[200007];
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int k1,k2,k3;
cin>>k1>>k2>>k3;
for(int i=1;i<=k1;++i){
cin>>a[i];
++cnt1[a[i]];
}
for(int i=1;i<=k2;++i){
cin>>b[i];
++cnt2[b[i]];
}
for(int i=1;i<=k3;++i){
cin>>c[i];
++cnt3[c[i]];
}
int n=k1+k2+k3;
for(int i=1;i<=n;++i){
cnt1[i]=cnt1[i-1]+cnt1[i];// number i is less than or equal
CNT2 [I] = CNT2 [-I. 1] + CNT2 [I];
CNT3 [I] = CNT3 [-I. 1] + CNT3 [I];
}
for (int I = 0; I <= n-; I ++ )
Mn [I] = [I] CNT3 -cnt2 [I];
for (int. 1-n-= I; I> = 0; - I)
Mn [I] = min (Mn [I +. 1], Mn [ I]);
int ANS = 1E9;
for (int I = 0; I <= n-; I ++)
ANS = min (ANS, CNT2 [I] -cnt1 [I] + Mn [I] + CNT1 [n-] CNT2 + [n-]);
/ *
assume a first state to a final individuals 0 ~ i, the second person has i + 1 ~ j, a third person has j + 1 ~ n
then the minimum equal to the second operand and the individual third person has 1 to I plus the number of first individual and a third person has I ~ j + 1 j plus the number of first individual and the second individual has a number n + 1 -
i.e. cnt2 [i] + cnt3 [i] + cnt1 [j] -cnt1 [i] + cnt3 [j] -cnt3 [i] + cnt1 [n] -cnt1 [j] + cnt2 [n] -cnt2 [j]
Simplification is cnt2 [i] -cnt1 [i] + cnt3 [j] -cnt2 [j] + cnt1 [n] + cnt2 [n]
from 0 to n enumeration i, only cnt3 [j] -cnt2 [j] a variable
maintains a suffix array mn [i] represents a [i, n] smallest CNT3 [J] -cnt2 [J]
* /
COUT << ANS;
return 0;
}

Guess you like

Origin www.cnblogs.com/ldudxy/p/11876625.html