Problem 1. Difference
Series A1, A2,..., An, Q questions (Li, RI), Ali, Ali + 1,..., Ari are different.
Input
Row 1st, two integers n, Q,
2nd rows, N integers A1, A2,...,
Row Q, with two integers Li, RI in each row
Output
Output a line for each query, "yes" or "no"
• For 50% of data, N, Q ≤ 10 ^ 3
• For 100% of data, 1 ≤ n, Q ≤ 10 ^ 5, 1 ≤ AI ≤ n, 1 ≤ Li ≤ rI ≤ n
Question: since this question requires querying whether there are repeated elements in the range from L to R, we may record the next position of the same vertex for each element, then, we only need to query the minimum value (closest to L) of the repetition location of each element in L to R, which is recorded as Min. When Min is greater than R, it is obviously a non-repeating sequence. To achieve this, both the st and the line segment tree can be used.
Problem 2. Increasing
The number of A1, A2,..., An, with the least number modified makes the number of columns increase monotonically.
Input
1st rows, 1 integer n
2nd rows, N integers A1, A2,...,
Output
1 integer, indicating the minimum number modified
• For 50% of data, n ≤ 10 ^ 3
• For 100% of data, 1 ≤ n ≤ 10 ^ 5, 1 ≤ AI ≤ 10 ^ 9
Question: in fact, the description of this question misses a condition, that is, the number of inserts can be non-integers, at least 2333 of the data, which also leads to the wide wa
Then, this question is obviously the longest ascending subsequence ~ (ANS = N-length) length is the longest ascending subsequence;
Of course, this question is about optimizing 100000 of the data ~~
1 #include <cstdio> 2 using namespace std; 3 int a[100010]; 4 int f[100010]; 5 int main() 6 { 7 freopen("incr.in", "r", stdin); 8 freopen("incr.out", "w", stdout); 9 int n;10 scanf("%d", &n);11 for(int i = 1; i <= n; i++)12 scanf("%d", &a[i]);13 int l = 0;14 for(int i = 1; i <= n; i++)15 {16 if(a[i] > f[l])17 f[++l] = a[i];18 else19 {20 int u = 1, y = l;21 while(u != y)22 {23 int mid = (y + u) / 2;24 if(f[mid] > a[i])y = mid;25 else u = mid + 1;26 }27 f[u] = a[i];28 }29 }30 printf("%d", n - l);31 return 0;32 }Skyfall code
9.28 Review