[Codeforces 486E] LIS of Sequence (LIS套路)
2017-01-21 18:16
429 查看
Codeforces - 486E
给定一个序列,问其中每一个值是否在 LIS上如果在 LIS上,是否在所有LIS上
判断是否在 LIS上,只要正反搞两次
然后把前后的加起来,看是否等于 LIS
判断是否在每一个 LIS 上
只要记录一下前面是 LIS的最大值
然后看是否能接到上面,也是正反各搞一次
感觉这个题挺重要的,今天又碰到一题需要这个作为前提
#pragma comment(linker, "/STACK:102400000,102400000") #include <cstdio> #include <iostream> #include <cstdlib> #include <cstring> #include <algorithm> #include <cmath> #include <cctype> #include <map> #include <set> #include <queue> #include <bitset> #include <string> #include <complex> using namespace std; typedef pair<int,int> Pii; typedef long long LL; typedef unsigned long long ULL; typedef double DBL; typedef long double LDBL; #define MST(a,b) memset(a,b,sizeof(a)) #define CLR(a) MST(a,0) #define SQR(a) ((a)*(a)) #define PCUT puts("\n----------") const int maxn=1e5+10, INF=0x3f3f3f3f; int N; int A[maxn]; int dp[2][maxn]; int tmin[2][maxn]; bool multi[2][maxn]; char res[maxn]; int DP(int); int main() { #ifdef LOCAL freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); #endif while(~scanf("%d", &N)) { for(int i=1; i<=N; i++) scanf("%d", &A[i]); CLR(multi); int ans = DP(0); for(int i=1; i<=N; i++) A[i]=-A[i]; reverse(A+1, A+1+N); DP(1); for(int i=1; i<=N; i++) A[i]=-A[i]; reverse(A+1, A+1+N); reverse(dp[1]+1, dp[1]+1+N); reverse(multi[1]+1, multi[1]+1+N); // for(int i=1; i<=N; i++) printf("%d ", multi[0][i]); puts(""); // for(int i=1; i<=N; i++) printf("%d ", multi[1][i]); puts(""); res[N+1]=0; for(int i=1; i<=N; i++) { if(dp[0][i]+dp[1][i]-1<ans) res[i]='1'; else res[i]='3'; } int tes=0; for(int i=1; i<=N; i++) if(res[i]!='1') { if(tes>=A[i]) res[i]='2'; tes = max(tes, A[i]); } tes=INF; for(int i=N; i>=1; i--) if(res[i]!='1') { if(tes<=A[i]) res[i]='2'; tes = min(tes, A[i]); } puts(res+1); } return 0; } int DP(int id) { int ans=0; MST(tmin,0x3f); tmin[0][0] = -INF; for(int i=1; i<=N; i++) { int p = lower_bound(tmin[0], tmin[0]+N+1, A[i]) - tmin[0]; dp[id][i] = p; if(p>1 && tmin[1][p-1] < A[i]) multi[id][i]=1; tmin[1][p] = tmin[0][p]; tmin[0][p] = A[i]; ans = max(ans, dp[id][i]); } return ans; }
相关文章推荐
- [Codeforces 486E] LIS of Sequence (LIS套路)
- 486E - LIS of Sequence(LIS)
- 486E - LIS of Sequence(LIS)
- Codeforces 486E LIS of Sequence --树状数组求LIS
- Codeforces 486E LIS of Sequence(线段树+LIS)
- 最长不降子序列/longest increasing sequence(LIS) O(n*lgn) POJ3670
- 编程之美--数组中的最长递增子序列(LIS longest increasement sequence)
- Codeforces 612C: Replace To Make Regular Bracket Sequence(栈)
- Codeforces 486E LIS of Sequence
- CodeForces 5C Longest Regular Bracket Sequence
- codeforces 438D. The Child and Sequence(线段树)
- codeforces 172B B. Pseudorandom Sequence Period(暴力)
- Codeforces 371D Vessels【思维+并查集】经典套路题
- CodeForces 3 D.Least Cost Bracket Sequence(贪心+优先队列)
- Codeforces 3D. Least Cost Bracket Sequence
- [CF486E] LIS of Sequence && DP
- codeforces 602 D. Lipshitz Sequence (单调栈)
- Codeforces 583D. Once Again... (LIS变形)
- 【CodeForces】612C - Replace To Make Regular Bracket Sequence(栈,括号配对问题)
- [Codeforces 67C] Sequence of Balls (字符串DP)