IOI 2015 Teams 鍒嗙粍
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了IOI 2015 Teams 鍒嗙粍相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/%e5%b9%b3%e9%9d%a2' title='骞抽潰'>骞抽潰 ax1 ++ 瀛樺湪 閫氳繃 ioi sum const
IOI 2015 Teams 鍒嗙粍
[ made by Ameiyo ]
璐績鍋氭硶
瀵逛簬姣忕粍璇㈤棶锛?鎴戜滑浠庡皬鍒板ぇ鑰冭檻 K
锛岄偅涔堟瘡娆¤偗瀹氭槸鍦?A
灏忎簬绛変簬 K
鐨?$ (A, B) $ 涓€夊彇鏈€灏忕殑 K
涓?B
锛屽洜涓烘洿澶х殑 B
鍙兘鍚庨潰浼氱敤鍒般€?/p>
鍥犳姣忔鐩存帴鏆村姏鍙互寰楀埌 $ O(N * S * log N) $ 鐨勭畻娉?鍏堟寜 A
鎺掑簭锛岀劧鍚庣淮鎶?B
鐨勫€硷紝鍙互鑰冭檻鏍戠姸鏁扮粍)銆?/p>
浣嗘槸鎴戜滑涓嶈兘鐩存帴鐢ㄦ墍鏈夋弧瓒虫潯浠剁殑鐐癸紝鍥犱负鍙兘鏈夌殑鐐瑰凡缁忚鍓嶉潰鐨勭煩褰㈢敤杩囦簡锛?/p>
瀵逛簬褰撳墠鐨勭煩褰紝浠栦竴瀹氫細鐢ㄦ帀鑳介€夌殑鐐逛腑锛岀旱鍧愭爣鏈€灏忕殑 $ K_i $ 涓偣锛岃娌¤鐢ㄦ帀鐨勭偣涓渶灏忕殑绾靛潗鏍囨槸 $ H_i $ (娉ㄦ剰杩欓噷鐨?$ H_i $ 鏄寚鑷繁鍒颁笂涓煩褰㈢殑鑼冨洿鍐咃紝鍥犱负鑷繁鎵€缁存姢鐨勭煩褰㈡槸杩欎竴娈?銆?/p>
(鍦ㄤ笅鍥句腑锛岃櫧鐒?A
鏄?j
鍙€変絾鏄病鏈夐€夋嫨鐨勭偣涓渶浣庣殑锛屼絾鏄?B
鐨勯珮搴︽墠鏄?$ H_j $ )
閭d箞瀵逛簬涓€涓?$ K_j ge K_i $ 鐨?$ K_j $ 锛屽鏋?$ K_j > H_i $ 锛岄偅涔堢敱浜庡彲浠ヨ $ j $ 浣跨敤鐨勭偣 $ i $ 閮芥病鏈夌敤杩囷紝鎵€浠?$ j $ 鍙互鐩存帴浣跨敤锛涗絾濡傛灉 $ k_j le H_i $ 锛岄偅涔堝彲鑳芥煇浜涚偣(娉ㄦ剰瀛樺湪鍜?$ H_i $ 楂樺害鐩稿悓鐨勭偣)宸茬粡琚?$ i $ 鐢ㄨ繃浜嗭紝鎵€浠ュ氨涓嶈兘鐩存帴璁℃暟銆?/p>
浣嗘槸鎴戜滑鍙互缁存姢鍑?$ i $ 杩樻病鏈夌敤杩囩殑鐐圭殑鏁伴噺 $ rem_i $ 锛岃繖鏍风敱浜?$ K_j < H_i $ 锛屾墍浠?$ rem_i $ 杩欎簺鐐?$ j $ 涔熸槸鍙互鐩存帴鐢ㄧ殑锛屽啀鍔犱笂妯潗鏍囧湪 $ (H_i, H_j] $ 涔嬮棿鐨?$ j $ 鍙互浣跨敤鐨勭偣锛屽氨鏄叏閮?$ j $ 鍙互浣跨敤鐨勭偣銆?/p>
娉ㄦ剰鍒版垜浠鐞嗙殑 K
鏄崟璋冧笉闄嶇殑锛屾墍浠ュ彲浠ョ敤涓€涓崟璋冩爤缁存姢涓€涓?H
鍗曡皟閫掑噺鐨勫簭鍒楋紝姣忔澶勭悊涔嬪墠锛屾妸 H
灏忎簬褰撳墠楂樺害鐨勭煩褰㈤兘鍑烘爤(娉ㄦ剰鍙湁灏忎簬鐨勫彲浠ュ嚭鏍?锛岀劧鍚庡啀閫氳繃鍓嶉潰鐨?rem
浠ュ強鏂扮殑鐐规暟鏉ュ垽鏂槸鍚﹀彲琛屽苟涓旂淮鎶ゃ€?/p>
鍥犱负杩欐槸涓€涓簩缁村钩闈笂鐨勮鏁伴棶棰橈紝鎵€浠ュ彲浠ョ敤涓诲腑鏍戠淮鎶ょ偣鐨勬暟閲忋€?/p>
浠g爜
int Rt[N], lson[M], rson[M], val[M], cntNode;
void Insert(int &rt, int pre, int l, int r, int x) {
rt = ++cntNode;
lson[rt] = lson[pre], rson[rt] = rson[pre];
val[rt] = val[pre] + 1;
if (l == r) return ;
int mid = (l + r) >> 1;
if (x <= mid) Insert(lson[rt], lson[pre], l, mid, x);
else Insert(rson[rt], rson[pre], mid + 1, r, x);
}
int Query(int L, int R, int l, int r, int k) { // (cnt) >= k
if (l == r) return val[R] - val[L];
int mid = (l + r) >> 1, sum = val[rson[R]] - val[rson[L]];
if (k > mid) return Query(rson[L], rson[R], mid + 1, r, k);
else return sum + Query(lson[L], lson[R], l, mid, k);
}
int Queryk(int L, int R, int l, int r, int k) { // kth
if (l == r) return l;
int mid = (l + r) >> 1, sum = val[rson[R]] - val[rson[L]];
if (k > sum) return Queryk(lson[L], lson[R], l, mid, k - sum);
else return Queryk(rson[L], rson[R], mid + 1, r, k);
}
int n, m, A[N];
struct NODE {
int x, y;
inline int operator < (const NODE &__) const {
return x < __.x || (x == __.x && y < __.y);
}
} node[N];
int stk[N], rem[N], high[N], Top;
int main() {
n = read<int>();
rep (i, 1, n) node[i].x = read<int>(), node[i].y = read<int>();
sort(node + 1, node + n + 1);
int cur = 1;
rep (i, 1, n) {
Rt[i] = Rt[i - 1];
for ( ; cur <= n && node[cur].x == i; ++cur)
Insert(Rt[i], Rt[i], 1, n, node[cur].y);
}
rep (ks, 1, read<int>()) {
rep (i, 1, m = read<int>()) A[i] = read<int>();
sort(A + 1, A + m + 1), Top = 0;
rep (i, 1, m) {
for ( ; high[Top] < A[i] && Top; --Top) ;
int tot = rem[Top]
+ Query(Rt[stk[Top]], Rt[A[i]], 1, n, A[i]) - A[i];
if (tot < 0) { puts("0"); break; }
else if (i == m) { puts("1"); break; }
int H = Queryk(Rt[stk[Top]], Rt[A[i]], 1, n, tot - rem[Top]);
for ( ; H > high[Top] && Top; )
--Top, H = Queryk(Rt[stk[Top]], Rt[A[i]], 1, n, tot - rem[Top]);
stk[++Top] = A[i], rem[Top] = tot, high[Top] = H;
}
}
return 0;
}
[ on 2019.12.15 ]
以上是关于IOI 2015 Teams 鍒嗙粍的主要内容,如果未能解决你的问题,请参考以下文章
csharp CRM 2015-2016 C#Helper #Teams #Sharing#CRM2016 #MoussaElAnnan