正文
增加 9 行删除 9 行
31 行未改动323334353637383940414243448 行未改动53545556575859606111 行未改动73747576777879808118 行未改动1001011021031041051061071085 行未改动11411511611711811912012112212312412512612712812913013113213313448 行未改动18318418518618718818919031 行未改动return ans;}signed main() {ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);cin >> T;while(T--) {cin >> n;for(int i = 1; i <= n; i++) {8 行未改动add(a[i], -1);}cout << (ans & 1 ? "No" : "Yes") << "\n";}return 0;}```11 行未改动int C, T, n, x1, c1, x2, c2;signed main() {cin >> C >> T;while(T--) {cin >> n >> x1 >> c1 >> x2 >> c2;if(x2 == 1) {18 行未改动mul *= x2;}cout << (ans == 1e18 ? -1 : ans) << "\n";}return 0;}```5 行未改动直接 $O(n^2)$ DP会T,所以考虑优化。因为对于一个区间,如果其两个端点都不为区间的最大/最小值,则不如把这两个端点丢给其他区间算,所以可以单调栈,找出每个点右边的第一个大于/小于当前值的位置,不断往后跳着转移,虽然依然是 $O(n^2)$,但已经可以拿到 $96$ 分的高分了,然后看到 T 的那个点是单调递减,那么直接把这种情况特判掉就行了。```cpp#include <bits/stdc++.h>#define int long longusing namespace std;const int N = 1e6 + 10;int n, a[N], nxt1[N], nxt2[N], dp[N];signed main() {ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);cin >> n;bool flag = 1;for(int i = 1; i <= n; i++) {cin >> a[i];48 行未改动}}}cout << dp[n] << "\n";return 0;}```31 行未改动323334353637383940414243448 行未改动53545556575859606111 行未改动73747576777879808118 行未改动1001011021031041051061071085 行未改动11411511611711811912012112212312412512612712812913013113213313448 行未改动18318418518618718818919031 行未改动return ans;}signed main() {ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);cin >> T;while(T--) {cin >> n;for(int i = 1; i <= n; i++) {8 行未改动add(a[i], -1);}cout << (ans & 1 ? "No" : "Yes") << "\n";}return 0;}```11 行未改动int C, T, n, x1, c1, x2, c2;signed main() {cin >> C >> T;while(T--) {cin >> n >> x1 >> c1 >> x2 >> c2;if(x2 == 1) {18 行未改动mul *= x2;}cout << (ans == 1e18 ? -1 : ans) << "\n";}return 0;}```5 行未改动直接 $O(n^2)$ DP会T,所以考虑优化。因为对于一个区间,如果其两个端点都不为区间的最大/最小值,则不如把这两个端点丢给其他区间算,所以可以单调栈,找出每个点右边的第一个大于/小于当前值的位置,不断往后跳着转移,虽然依然是 $O(n^2)$,但已经可以拿到 $96$ 分的高分了,然后看到 T 的那个点是单调递减,那么直接把这种情况特判掉就行了。```cpp#include <bits/stdc++.h>#define int long longusing namespace std;const int N = 1e6 + 10;int n, a[N], nxt1[N], nxt2[N], dp[N];signed main() {ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);cin >> n;bool flag = 1;for(int i = 1; i <= n; i++) {cin >> a[i];48 行未改动}}}cout << dp[n] << "\n";return 0;}```