Draymonders / Code-Life

The marathon continues though.
27 stars 3 forks source link

双指针模板 #64

Open Draymonders opened 4 years ago

Draymonders commented 4 years ago

// 双指针模板

// 区间[l, r]的信息

unordered_map<int, int> mp;
int cnt = 0;
int l = 0;
int sz = INF;
for (int r=0; r<n; r++) {
    if (mp[r] == 0)
        cnt++;
    mp[r] ++;

    while (cover(cnt)) {
        if (r - l + 1 > sz) {
            sz = r - l + 1;
            // todo 更新
        }
        mp[l]--;
        if (mp[l] == 0)
            cnt--;
        l++;
    }
}