1
#include <iostream>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;
const int N = 200010;
bool num[N];
int main(){
int n; scanf("%d", &n);
for(int i=0; i<n; i++){
int t; scanf("%d", &t);
num[t] = true;
}
for(int i=1; i<N; i++){
if(num[i] && num[i-1]) num[i] = false;
}
int cnt = 0;
for(int i=0; i<N; i++){
if(num[i]) cnt ++;
}
printf("%d", cnt);
}
#2
https://blog.csdn.net/winter2121/article/details/72848482
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+5;
const int INT_INF=0x3f3f3f3f;
int n,m = 2;
ll a[N],multi_dp[2][N];
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%lld",a+i);
for(int i=0;i<=n;i++)
multi_dp[0][i]=0,multi_dp[1][i]=0;
for(int i=1,k=1;i<=m;i++,k^=1)
{
multi_dp[k][i-1]=-INT_INF;
ll maxpre=-INT_INF;
for(int j=i;j<=n-m+i;j++)
{
maxpre=max(maxpre,multi_dp[k^1][j-1]);
multi_dp[k][j]=max(multi_dp[k][j-1],maxpre)+a[j];
}
}
ll ans=-INT_INF;
for(int i=m;i<=n;i++)
ans=max(ans,multi_dp[m&1][i]);
printf("%lld\n",ans);
}
3
#include <iostream>
using namespace std;
const int N = 1005;
char ops[N];
int vals[N];
bool gps[3][N];
int n, k;
int help(int i)
{
int m = 0;
int l = 0, r = 0;
while (l <= n && r <= n){
if(!gps[i][r]) r++;
else{
m = max(m, r - l);
l = r; r++;
}
}
return m;
}
int main(){
cin >> n >> k;
for(int i=0; i<k; i++){
cin >> ops[i];
}
for(int i=0; i<k; i++){
cin >> vals[i];
}
gps[0][0] = gps[0][n] = true;
gps[1][0] = gps[1][n] = true;
gps[2][0] = gps[2][n] = true;
int mx = n, my = n, mz = n;
for(int i=0; i<k; i++){
char c = ops[i];
int v = vals[i];
if(c == 'x') {gps[0][vals[i]] = true; mx = help(0); }
if(c == 'y') {gps[1][vals[i]] = true; my = help(1); }
if(c == 'z') {gps[2][vals[i]] = true; mz = help(2); }
printf("%d\n", mx*my*mz);
}
}
4
树状数组?线段树? 变形?
5
https://blog.csdn.net/benbendlianlian/article/details/108614510
/*
*
4 5
1234 3 0
1204 3 0
5678 0 1
5679 0 0
5670 0 0
1284
*/