2019 Multi-University Training Contest 6 Nonsense Time (pure violence)

Meaning of the questions: to give you a permutation of n, the number of these at first does not work, then there is an array subscript represents the i-th number i can use.

Q rise up sequence corresponding to each of a i.

 

answer:

It can be pushed down, forward, regardless of conversion from it, and then a number is to delete, to a maximum of two numbers increased sequence number n.

When the game will not be counted out of the computational complexity is n ^ 2log (n), dare not write, I have been looking for ways to optimize

Solution of this problem is the practice game, but because the data illustrating the random questions, so LIS desired length is O (√ n),

Deleted located probability x LIS is √ 1 n, that is expected to delete O (√ n) will modify the number of LIS,

So the number of LIS will not change much. Expected time complexity is O (n √ n log n).

LIS desired length is O (√ n), there is a proof of Click here

(This story tells us to dare to write off, not so many pieces, it wants Mang)

 This problem is like a pure violence 

 

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <queue>
 4 #include <cmath>
 5 #include <algorithm>
 6 #include <set>
 7 #include <iostream>
 8 #include <map>
 9 #include <stack>
10 #include <string>
11 #include <vector>
12 #define  pi acos(-1.0)
13 #define  eps 1e-9
14 #define  fi first
15 #define  se second
16 #define  rtl   rt<<1
17 #define  rtr   rt<<1|1
18 #define  bug         printf("******\n")
19 #define  mem(a,b)    memset(a,b,sizeof(a))
20 #define  name2str(x) #x
21 #define  fuck(x)     cout<<#x" = "<<x<<endl
22 #define  f(a)        a*a
23 #define  sf(n)       scanf("%d", &n)
24 #define  sff(a,b)    scanf("%d %d", &a, &b)
25 #define  sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
26 #define  sffff(a,b,c,d) scanf("%d %d %d %d", &a, &b, &c, &d)
27 #define  pf          printf
28 #define  FRE(i,a,b)  for(i = a; i <= b; i++)
29 #define  FREE(i,a,b) for(i = a; i >= b; i--)
30 #define  FRL(i,a,b)  for(i = a; i < b; i++)+
31 #define  FRLL(i,a,b) for(i = a; i > b; i--)
32 #define  FIN         freopen("data.txt","r",stdin)
33 #define  gcd(a,b)    __gcd(a,b)
34 #define  lowbit(x)   x&-x
35 #define rep(i,a,b) for(int i=a;i<b;++i)
36 #define per(i,a,b) for(int i=a-1;i>=b;--i)
37 using namespace std;
38 typedef long long  LL;
39 typedef unsigned long long ULL;
40 const int maxn = 100000 + 7;
41 const int maxm = 8e6 + 10;
42 const int mod = 1e9 + 7;
43 const int INF = 0x3f3f3f3f;
44 int T, n, a[maxn], b[maxn], vis[maxn], ans[maxn], len, dp[maxn], pre[maxn];
45 void solve() {
46     for ( int i = 0 ; i <= n ; i++ ) dp[i] = INF, pre[i] = 0, vis[i] = 0;
47     dp[0] = 0;
48     for ( int i = 1 ; i <= n ; i++ ) {
49         if ( !a[i] ) continue;
50         int pos = lower_bound ( dp + 1, dp + 1 + n, a[i] ) - dp;
51         pre[a[i]] = dp[pos - 1];
52         dp[pos] = a[i];
53     }
54     for ( int i = 1 ; i <= n ; i++ ) {
55         if ( dp[i] != INF ) len = i;
56         else break;
57     }
58     int x = dp[len];
59     while ( x ) {
60         vis[x] = 1;
61         x = pre[x];
62     }
63 }
64 int main() {
65     sf ( T );
66     while ( T-- ) {
67         sf ( n );
68         for ( int i = 1 ; i <= n ; i++ ) sf ( a[i] );
69         for ( int i = 1 ; i <= n ; i++ ) sf ( b[i] );
70         reverse ( b + 1, b + 1 + n );
71         solve();
72         ans[1] = len;
73         for ( int i = 1 ; i < n ; i++ ) {
74             if ( vis[a[b[i]]] ) {
75                 a[b[i]] = 0;
76                 solve();
77             } else   a[b[i]] = 0;
78             ans[i + 1] = len;
79         }
80         reverse ( ans + 1, ans + 1 + n );
81         for ( int i = 1 ; i <= n ; i++ ) printf ( "%d%c", ans[i], ( i == n ? '\n' : ' ' ) );
82     }
83     return 0;
84 }
View Code

 

Guess you like

Origin www.cnblogs.com/qldabiaoge/p/11317780.html