日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

hdu5489(2015合肥网络赛F题)

發布時間:2025/3/15 编程问答 10 豆豆
生活随笔 收集整理的這篇文章主要介紹了 hdu5489(2015合肥网络赛F题) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

轉載自:http://blog.csdn.net/lwt36/article/details/48774103


題意:

給出一個數列,在其中刪除連續的L個數字,使得剩余的數字LIS最大,輸出此LIS。


思路:

nlogn的LIS+線段樹。


代碼:

//#pragma comment(linker, "/STACK:1024000000,1024000000") #include <algorithm> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <string> #include <set> #include <vector>using namespace std; #define pr(x) cout << #x << " = " << x << " " #define prln(x) cout << #x << " = " << x << endl const int N = 1e5 + 10, INF = 0x3f3f3f3f, MOD = 1e9 + 7;int n, L, a[N], all[N]; int f[N], g[N], h[N];int maxv[N << 2]; void update(int o, int v, int l, int r, int rt) {if(l == r) {maxv[rt] = max(maxv[rt], v);return;}int m = l + r >> 1;if(o <= m) update(o, v, l, m, rt << 1);else update(o, v, m + 1, r, rt << 1 | 1);maxv[rt] = max(maxv[rt << 1], maxv[rt << 1 | 1]); }int query(int L, int R, int l, int r, int rt) {if(L <= l && r <= R) return maxv[rt];int m = l + r >> 1, ret = -INF;if(L <= m) ret = max(ret, query(L, R, l, m, rt << 1));if(R > m) ret = max(ret, query(L, R, m + 1, r, rt << 1 | 1));return ret; }int main() { #ifdef LOCALfreopen("in.txt", "r", stdin); // freopen("out.txt","w",stdout); #endifios_base::sync_with_stdio(0);int t; scanf("%d", &t);int kase = 0;while(t--) {scanf("%d%d", &n, &L);for(int i = 1; i <= n; ++i) {scanf("%d", a + i);all[i] = a[i];}sort(all + 1, all + 1 + n);int m = unique(all + 1, all + 1 + n) - all - 1;memset(h, 0x3f, sizeof h);for(int i = 1; i <= n; ++i) {int k = lower_bound(h + 1, h + 1 + n, a[i]) - h;f[i] = k;h[k] = a[i];}memset(h, 0x3f, sizeof h);for(int i = n; i; --i) {int k = lower_bound(h + 1, h + 1 + n, -a[i]) - h;g[i] = k;h[k] = -a[i];}int ans = 0;a[n + 1] = INF; g[n + 1] = 0;memset(maxv, 0, sizeof maxv);//delete [i-l,i-1] length:l [0,i-l-1]->maxvfor(int i = L + 1; i <= n + 1; ++i) {int o = lower_bound(all + 1, all + 1 + m, a[i]) - all;ans = max(ans, query(0, o - 1, 0, m, 1) + g[i]);o = lower_bound(all + 1, all + 1 + m, a[i - L]) - all; //插入一個新的if(i <= n) update(o, f[i - L], 0, m, 1);}printf("Case #%d: %d\n", ++kase, ans);}return 0; }

總結

以上是生活随笔為你收集整理的hdu5489(2015合肥网络赛F题)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。