Codeforces Round 314 Div.2

Source: Internet
Author: User
Tags stdin

This game is played with trumpet, so now the trumpet is higher than the large rating ... QwQ

A and B are very simple and not much to say.

C: The number of equal-ratio sequences with a length of 3 in the statistical subsequence and K K for the male ratio.

The number of sequences that meet the conditional length of three-to-three are counted from the back-to-forward process.
F (i,j) =∑f (i−1,t) |t=j∗k f (i,j) = \sum f (i-1,t) | t = j*k, when implemented discretization is good ~

However, at that time only judged the A[i]*k<=a[max], and did not judge A[i]*k>=a[min] (k may be negative), so fst ...

 const int MAXN = 2e5 + 5, size = maxn*3;
int N, K, A[MAXN];
Long long ans;
int CNT[MAXN], p[maxn], pl;


Long Long F[MAXN], G[MAXN];
    int main () {#ifndef Online_judge freopen ("c.in", "R", stdin);
Freopen ("C.out", "w", stdout);

    #endif read (n), read (k);

    for (int i = 1; I <= n; i++) read (A[i]), p[i] = a[i];
    Std::sort (p + 1, p + n + 1);

    PL = Std::unique (p + 1, p + N + 1)-(p + 1);

        for (int i = n; i > 0; i--) {int t = Std::lower_bound (p + 1, p + PL + 1, a[i])-p;  if (long long) a[i]*k <= P[PL] && (Long long) a[i]*k >= p[1]) {int v = std::lower_bound (P
            + 1, p + PL + 1, a[i]*k)-p;
        if (A[i]*k = = P[v]) g[t] + = F[v], f[t] + = Cnt[v];
    } cnt[t]++;

    } for (int i = 1; I <= pl; i++) ans + = g[i];

Write (ANS);
    #ifndef Online_judge fclose (stdin);
Fclose (stdout);
#endif return 0; }

D: Reverse processing from the end state, using and checking the set to maintain the longest interval, until the number of >= to meet the actual number of ships to get the answer.

const int MAXN = 2e5 + 5, maxk = MAXN;

int N, K, A, m;
int x[maxk], CNT;
BOOL E[MAXN];

int FA[MAXN], SIZE[MAXN];
int find (int x) {return (x = = Fa[x])? x: (Fa[x] = find (fa[x]));

    } void gather (int x,int y) {if (x > Y) std::swap (x, y);
    x = Find (x), y = Find (y), fa[y] = x;
if (x! = y) size[x] + = Size[y], size[y] = 0;
    } void Init () {read (n), read (k), read (a), read (m);
for (int i = 1; I <= m; i++) read (X[i]), e[x[i]] = true;

    } void Prework () {for (int i = 1; I <= n; i++) Fa[i] = i, size[i] = 1;

    for (int i = 1; I <= n; i++) if (i > 1 &&!e[i] &&!e[i-1]) gather (I, i-1);       
for (int i = 1; I <= n; i++) if (fa[i] = = i &&!e[i]) cnt + = (size[i]+1)/(a+1);

    } int Solve () {if (CNT >= k) return-1; for (int i = m; I >= 1; i--) {if (X[i] > 1 &&!e[x[i]-1]) {cnt-= (size[find (x[i]-1)]
            +1)/(a+1); Gather (X[i]-1, x[I]);
            } if (X[i] < n &&!e[x[i]+1]) {cnt-= (Size[find (x[i]+1)]+1)/(a+1);
        Gather (X[i], x[i] + 1);

        } cnt + = (Size[find (x[i])]+1)/(a+1);

        E[x[i]] = false;
    if (CNT >= k) return i;
} return 0;
    } int main () {#ifndef Online_judge freopen ("d.in", "R", stdin);
Freopen ("D.out", "w", stdout);

    #endif init (), prework ();

Write (Solve ());
    #ifndef Online_judge fclose (stdin);
Fclose (stdout);
#endif return 0; }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.