ZR National Day Round2 Problem Solving report

Source: Internet
Author: User
Tags fread

Spiritual Journey

Estimated score: 100 + 10-20 + 10 = 120

Actual score: 100 + 0 + 10 = 110

I feel this fight is quite steady. The opening second dropped a question, write + tune almost 1h

Then just T3 violence, just finished there is about 2h. Then, at this time I zz choice to play T2 violence, however T2 violence is not generally difficult to write.

Finally spent 1h dozen T2 violence, and hit the $n <= 10$ table, feeling a steady batch.

Then began to run $n = 11$, the result to the end of the game did not run out Qwq.

At the end of the game and 5min, we found that T3 was not related to K and took 20 less.

Afternoon to see the results of the time found T2 $n = 1$ points play the wrong perfect zero ....

If... Give me another 20min, let me finish T2 's watch 、、、、

If... Give me 15min, let me finish T3 of the optimized version of violence ....

seems to win the AH unfortunately not if ...

T1

Monotonous queue to do whatever ...

Maintain the maximum minimum value, greedy pop a bit better.

Because the data is random, so there are not many elements in the monotone queue, deque maintenance.

#include <bits/stdc++.h> #define LL Long long using namespace std;const int maxn = 2e7 + 10;inline int read () {Cha R C = GetChar ();    int x = 0, f = 1;    while (C < ' 0 ' | | c > ' 9 ') {if (c = = '-') f =-1; c = GetChar ();}    while (c >= ' 0 ' && C <= ' 9 ') x = x * ten + C-' 0 ', C = GetChar (); return x * f;} struct Node {int val, pos;}; int N, K, Seed, L, R; Deque<node> qmx, Qmn;int Main () {N = read ();    K = Read (); Seed = read ();    L = Read (), r = Read ();    LL ans = 0, pre = 0;        for (int i = 1; I <= N; i++) {int a = seed% (R-l + 1) + L;        Seed = (13331LL * seed + 23333)% 1000000007;        while (!qmx.empty () && a > Qmx.back (). val) Qmx.pop_back ();        while (!qmn.empty () && a < Qmn.back (). val) Qmn.pop_back ();        cout << a << Endl;        Qmx.push_back (Node) {A, i});           Qmn.push_back (Node) {A, i}); while (!qmx.empty () &&!qmn.empty () && (1LL * Qmx.front (). Val &GT             1LL * Qmn.front (). val * K) {if (Qmx.front (). Pos < Qmn.front (). pos) Pre = Qmx.front (). Pos, Qmx.pop_front ();        else Pre = Qmn.front (). Pos, Qmn.pop_front ();    } if (!qmx.empty () &&!qmn.empty ()) ans + = i-pre;    } cout << ans; return 0;} /*20000000 61234 4321 8765*/
T2

This is a real God problem ...

Just say the math.

Set $f[i][j]$ to represent $i$ nodes of the root tree, maximum depth of up to $j$ scheme number,

Set $g[i][j]$ to represent $i$ nodes without root tree, maximum maximum depth is exactly $j$ scheme number, obviously $g[i][j] = f[i][j]-f[i][j-1]$

Then $f[i][j] = i * \sum_{k = 0}^i \frac{f[i-k][j]}{i-k} * f[k][j-1] * c_{n-2}^{k-1}$

A formula: Contains countless trick. Orz Xudyh.

First, the root tree count is changed to a root tree count, and then the lowest numbered point connected to the root node is enumerated $k$

The reason we want to get rid of $i-k$ is because we don't know the root node at this point

The last $c_{n-2}^{k-1}$ means that we have the answer to the root node and the lowest numbered point that it is connected to.

So when it comes to statistical answers,

    • If the diameter is $2J + 1$, then the answer is

$$\sum G[k][j] * g[n-k][j] * c_{n-1}^{k-1}$$

This should be better understood, is the left and right to calculate a calculation.

    • If the diameter is $2j$, the answer is

$g [N][j]-\sum g[k][j-1] * f[n-k][j-1] * c_n^k$

This is more interesting, explain

Now that we have a root node, we just need to count the answers that are centered on it.

$g [n][j]$ represents the number of scenarios with a depth maximum of $j$, but there are some unmet answers (only one chain that is $j$ long)

Consider subtracting those that do not meet the criteria

Enumerates two subtrees trees, $g [k][j-1]$ guarantees one of them satisfies the condition, and the other that does not satisfy the condition is a scheme that starts at a depth of up to $j-1$ from the root node.

I can't read the code. I can't get it out of my own writing. The Cuckoo goo.

#include <bits/stdc++.h> #define CHMAX (A, b) (A = (a < b b:a)) #define Chmin (A, b) (A = (a < b a:b))//#de Fine GetChar (P1 = = P2 && (P2 = (P1 = buf) + fread (buf, 1, 1 <<, stdin), p1 = = p2)?    EOF: *p1++) using namespace std;const int maxn = 501;//char buf[1 <<], *p1 = buf, *p2 = buf;inline int read () { char C = GetChar ();    int x = 0, f = 1;    while (C < ' 0 ' | | c > ' 9 ') {if (c = = '-') f =-1; c = GetChar ();}    while (c >= ' 0 ' && C <= ' 9 ') x = x * ten + C-' 0 ', C = GetChar (); return x * f;}    int N, M, F[MAXN][MAXN], G[MAXN][MAXN], C[MAXN][MAXN], mod;int fastpow (int a, int p) {int base = 1;        while (p) {if (P & 1) base = 1ll * A * base% MoD; A = 1ll * A * a% mod;    P >>= 1; } return base;} int inv (int x) {return Fastpow (x, mod-2);}    Main () {N = read (); mod = read ();    C[1][1] = 1;        for (int i = 2; I <= N; i++) {c[i][0] = c[i][i] = 1; for (int j = 1; J <= N; j + +)C[I][J] = (C[i-1][j-1] + c[i][j-1])% MoD;    } for (int i = 0; I <= N; i++) f[0][i] = g[0][i] = F[1][i] = G[1][i] = 1;         for (int i = 1; I <= N; i++) {f[i][1] = i;            for (int j = 2; J <= N; j + +) {int sum = 0; for (int k = 0; k <= i; k++) (sum + + 1ll * f[i-k][j] * INV (i-k)% mod * f[k][j-1]% mod * C[n-2]            [k-1]% mod)%= mod;        if (!f[i][j]) f[i][j] = 1ll * i * sum% mod; } for (int j = 0; J <= N; j + +) G[i][j] = (F[i][j]-f[i][j-1] + MoD)% mod, printf ("%d%d%d\n", I, J, F[i][j])    ;        } for (int i = 0; i < N; i++) {int ans = 0;            if (I & 1) {int J = (i-1)/2;            for (int k = 1; k < N; k++) (ans + 1ll * g[k][j] * g[n-k][j]% mod * c[n-1][k-1]% mod)%= mod;        cout << ans << "";            } else {int j = I/2;            ans = g[n][i]; for (int k = 1; k < N; k++) ans = (ANS-1LL * G[k][J-1] * f[n-k][j-1]% mod * c[n][k]% mod + mod)% MoD;        cout << ans << "";   }    }}/**/
T3

First, it has nothing to do with $k$ because you can take the $=$ number

This means that each point is selected or not selected in two states

Direct 01 score planning, each $a[i]-x$, the problem into can delete some points, so that the remaining weights $>0$

Then a point can be an answer when and only if it is not an outlier and a separate set is formed with the other not selected points (because there is a minimum of two edges to choose)

Which means we're going to find $a[i]-the smallest independent set of val$,

But it doesn't seem like a good idea, take a negative, find out the largest independent set of $val-a[i]$

Then you can have DP.

$DP [i]$] Consider the $i$ point on the right, enumerate the previous point $j$, and then enumerate the points on the left. See if you can join a standalone set

Third-dimensional prefixes and optimizations, time complexity: $O (n^2) $

A different DP method, plus a $f[j]$ to represent the optimal cost of moving from $j$ to the current point

for i = 1...n    dp[i] = max(f[j], 1 <= j < i)    f[i] = dp[i]    for all 区间 r = i    [l, r] = w    f[0....l - 1]  += W

Segment tree optimization, interesting.

Complexity: $O (NLOG^2N) $

#include <bits/stdc++.h> #define CHMAX (A, b) (A = (a < b b:a)) #define Chmin (A, b) (A = (a < b a:b)) #defi Ne getchar (p1 = = P2 && (P2 = (P1 = buf) + fread (buf, 1, 1 <<, stdin), p1 = = p2)? EOF: *p1++) #define LS k << 1#define rs k << 1 |  1 using namespace Std;const int maxn = 30001;const double INF = 1e18, eps = 1e-9;char buf[1 <<], *p1 = buf, *p2 =    Buf;inline int Read () {char c = getchar (); int x = 0, f = 1;    while (C < ' 0 ' | | c > ' 9 ') {if (c = = '-') f =-1; c = GetChar ();}    while (c >= ' 0 ' && C <= ' 9 ') x = x * ten + C-' 0 ', C = GetChar (); return x * f;} int N, M, K, L[MAXN], r[maxn];vector<int> V[MAXN];d ouble DP[MAXN], A[MAXN], B[MAXN], TA[MAXN], tb[maxn];struct Node    {int L, r, Siz; Double V, F;} T[MAXN << 2];void Add (int k, double val) {t[k].v + = val; T[k].f + = val;}    void pushdown (int k) {if (T[k].f < EPS) return; Add (LS, t[k].f);    Add (rs, T[K].F); T[K].F = 0;} void UPDATe (int k) {t[k].v = max (T[LS].V, T[RS].V);} void Build (int k, int ll, int rr) {t[k].l = ll; T[K].R = RR; T[k].siz = rr-ll + 1;    T[K].V = T[K].F = 0;    if (LL = = RR) return;    int mid = T[k].l + T[K].R >> 1; Build (LS, ll, mid);    Build (RS, mid + 1, RR); Update (k);} void Intadd (int k, int ll, int RR, double val) {if (ll <= t[k].l && T[K].R <= rr) {Add (k, Val); R    Eturn;    } pushdown (k);    int mid = T[k].l + T[K].R >> 1;     if (ll <= mid) Intadd (LS, LL, RR, Val);    if (RR > Mid) Intadd (RS, LL, RR, Val); Update (k);}    Double Query (int k, int ll, int rr) {if (ll <= t[k].l && T[K].R <= RR) return T[K].V;    Pushdown (k);    int mid = T[k].l + T[K].R >> 1;    if (ll > Mid) return Query (RS, LL, RR);    else if (RR <= mid) return Query (LS, LL, RR); else return max (query (LS, LL, RR), query (RS, LL, RR));}    BOOL Check (double val) {double sum = 0; for (int i = 1; I <= N; i++) ta[i] = max ((double) 0, Val-a[i]), sum + = A[i]-val;    for (int i = 1; I <= M; i++) tb[i] = max (double) 0, val-b[i]), sum + = B[i]-val;    Build (1, 0, M);        for (int i = 1; I <= M + 1; i++) {Dp[i] = Query (1, 0, i-1) + tb[i];        for (int j = 0; J < V[i].size (); j + +) Intadd (1, 0, L[v[i][j]]-1, ta[v[i][j]]);    if (i! = M + 1) intadd (1, I, I, dp[i]);    } double ans = 0;    for (int i = 1; I <= M + 1; i++) ans = max (ans, dp[i]); return sum + ans >-eps;}    Main () {//freopen ("a.in", "R", stdin); N = Read (); M = Read ();    K = Read ();    Double L = INF, r =-inf;    for (int i = 1; I <= N; i++) A[i] = Read (), Chmin (L, A[i]), Chmax (R, A[i]);    for (int i = 1; I <= M; i++) B[i] = Read (), Chmin (L, B[i]), Chmax (R, B[i]);        for (int i = 1; I <= N; i++) {L[i] = read (), r[i] = read ();    V[r[i]].push_back (i);    } Double ans =-1;    while (R-l > EPs) {double mid = (L + r)/2;        printf ("%.10lf\n", mid); if (check (mid)) L =Mid, ans = mid;    else R = Mid; } printf ("%.10lf", ans);}

ZR National Day Round2 Problem Solving report

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.