标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1361 Accepted Submission(s): 492
#include <bits/stdc++.h> using namespace std; const int N = 100000 + 5; #define lson rt << 1, l, m #define rson rt <<1|1, m + 1, r int num[N << 2]; int a[N], pos[N], ans[N], res[N], n; void build(int rt, int l, int r) { num[rt] = r - l + 1; if(l == r) return ; int m = (l + r) >> 1; build(lson); build(rson); } void update(int rt, int l, int r, int k, int v) { if(l == r) { pos[l] = v; num[rt] = 0; return; } int m = (l + r) >> 1; if(k > num[rt << 1]) update(rson, k - num[rt << 1], v); else update(lson, k, v); num[rt] = num[rt << 1] + num[rt << 1|1]; } int LIS[N], len; void solve() { len = 1; LIS[0] = 0; for(int i = 1; i <= n; ++i) { int p = upper_bound(LIS, LIS + len, pos[i]) - LIS - 1; LIS[p + 1] = pos[i]; ans[i] = p + 1; if(p + 1 == len) len++; } } int main() { // freopen("in.txt", "r", stdin); int _, cas = 1; scanf("%d", &_); while(_ --) { scanf("%d", &n); build(1, 1, n); // puts("-----BUG-----"); for(int i = 1; i <= n; ++i) { scanf("%d", a + i); a[i]++; } for(int i = n; i >= 1; --i) update(1, 1, n, a[i], i); solve(); for(int i = 1; i <= n; ++i) res[ pos[i] ] = ans[i]; for(int i = 2; i <= n; ++i) res[i] = max(res[i], res[i - 1]); printf("Case #%d:\n", cas++); for(int i = 1; i <= n; ++i) printf("%d\n", res[i]); puts(""); } }
标签:
原文地址:http://www.cnblogs.com/orchidzjl/p/5487770.html