JOISC 2020 do title record

JOISC 2020 do title record

Day1 T1 Building 4

The meaning of problems

There are two length \ (2N \) sequence \ (A_1, \ ldots, A_ 2N} {\) , \ (B_1, \ ldots, B_ \ 2N {}) , a configured length \ (2N \) of sequence \ (C \) , requires \ (C \) values for each position \ (a, b \) corresponding to a selected position, the entire shared \ (n-\) positions as \ (a \) , additional \ (n-\) positions selected from the \ (B \) , and \ (C \) nondecreasing. Seek a solution.

\ (n \ 5 \ Times 10 ^ 5 \) .

answer

First, there is a very obvious \ (\ mathcal {O} ( n ^ 2) \) a DP practice. Note \ (f (i, j, 0/1) \) represents only considered before \ (I \) positions, selected from the \ (J \) a \ (A \) , the first \ (I \) position selected from a \ (a \) / \ (b \) the possibility of a direct transfer. Restore program to restore the path.

Optimization considerations, it is easy to guess a conclusion: For a determination of \ (I \) , all such that \ (f (i, j, 0/1) \) is true \ (J \) , it must be a continuous period range.

A non-rigorous proof, we consider ways to replace the DP. We further define the DP, \ (G (I, 0/1) \) represents only considered before \ (I \) positions, the \ (I \) position selected from the \ (A \) / \ (B \ ) , so that is really \ (j \) collection.

Then the state transition explicitly FIG give drawn, so \ (A_i \) represents \ (g (i, 0) \) corresponding to a point, \ (B_i \) represents \ (g (i, 1) \) the corresponding point. Can be found, if \ (J \) is not a contiguous interval, necessarily requires the presence of a position \ (X \) , satisfies \ (A_x \) to \ (A_ {x + 1} \) connected side (i.e., \ ( a_x \ Le A_ {X +. 1} \) ), \ (B_X \) to \ (B_ {x + 1} \) connected edge, \ (a_x \) not to \ (B_ {x + 1} \) connected side, \ (B_X \) not to \ (A_ {x + 1} \) connected edges.

However, this is not possible. Category discuss \ (a_x \) and (b_x \) \ size relationship. If \ (a_x \ Le B_X \) , then \ (a_x \ Le B_X \ Le B_ {X +. 1} \) , described \ (A_x \) directed \ (B_ {x + 1} \) connected edge; if \ (B_X \ lt a_x \) , then \ (B_X \ lt a_x \ Le A_ {X +. 1} \) , described \ (B_X \) directed \ (A_ {x + 1} \) even sides, both with contradictory conditions. So the conclusion is proved.

Possible to know \ (J \) is a section on the simple, and with \ (G \) as the DP method, as long as the interval endpoint stored around like, out to optimize a \ (n-\) .

Time complexity \ (\ mathcal {O} (n-) \) , the spatial complexity \ (\ mathcal {O} (n-) \) .

Code

#include <algorithm>
#include <cstdio>
#include <cstring>

const int MaxN = 1000000;

int N;
int A[MaxN + 5], B[MaxN + 5];
int L[MaxN + 5][2], R[MaxN + 5][2];
bool F[MaxN + 5][2];
int Ans[MaxN + 5];

void init() {
  scanf("%d", &N);
  N <<= 1;
  for (int i = 1; i <= N; ++i) scanf("%d", &A[i]);
  for (int i = 1; i <= N; ++i) scanf("%d", &B[i]);
}

void solve() {
  L[0][0] = L[0][1] = R[0][0] = R[0][1] = 0;
  F[0][0] = F[0][1] = true;
  for (int i = 1; i <= N; ++i) {
    L[i][0] = N + 1, R[i][0] = -1;
    L[i][1] = N + 1, R[i][1] = -1;
    if (A[i] >= A[i - 1] && F[i - 1][0] == true) {
      L[i][0] = std::min(L[i][0], L[i - 1][0] + 1);
      R[i][0] = std::max(R[i][0], R[i - 1][0] + 1);
      F[i][0] = true;
    }
    if (A[i] >= B[i - 1] && F[i - 1][1] == true) {
      L[i][0] = std::min(L[i][0], L[i - 1][1] + 1);
      R[i][0] = std::max(R[i][0], R[i - 1][1] + 1);
      F[i][0] = true;
    }
    if (B[i] >= A[i - 1] && F[i - 1][0] == true) {
      L[i][1] = std::min(L[i][1], L[i - 1][0]);
      R[i][1] = std::max(R[i][1], R[i - 1][0]);
      F[i][1] = true;
    }
    if (B[i] >= B[i - 1] && F[i - 1][1] == true) {
      L[i][1] = std::min(L[i][1], L[i - 1][1]);
      R[i][1] = std::max(R[i][1], R[i - 1][1]);
      F[i][1] = true;
    }
  }
  int ok = -1;
  if (F[N][0] == true && L[N][0] <= N / 2 && N / 2 <= R[N][0]) ok = 0;
  if (F[N][1] == true && L[N][1] <= N / 2 && N / 2 <= R[N][1]) ok = 1;
  if (ok == -1) puts("-1");
  else {
    int last = N / 2;
    for (int i = N; i >= 1; --i) {
      Ans[i] = ok;
      if (ok == 0) {
        last--;
        if (F[i - 1][0] == true && A[i - 1] <= A[i] && L[i - 1][0] <= last && last <= R[i - 1][0]) ok = 0;
        else ok = 1;
      } else {
        if (F[i - 1][0] == true && A[i - 1] <= B[i] && L[i - 1][0] <= last && last <= R[i - 1][0]) ok = 0;
        else ok = 1;
      }
    }
    for (int i = 1; i <= N; ++i)
      putchar("AB"[Ans[i]]);
    putchar('\n');
  }
}

int main() {
  init();
  solve();
  return 0;
}

Day1 T2 Hamburg Steak

The meaning of problems

There plane \ (n-\) rectangular, to elect \ (K \) points, such that there is at least one point in each rectangle. Data guarantee solvable.

\ (n \ 2 \ Times 10 ^ 5 \) , \ (k \ 4 \) .

answer

No, first he muttered.

Day1 T3 Sweeping

The meaning of problems

\ (n \ times n \) on a plane, there is an initial \ (m \) points for \ (Q \) operations. Operation the following four:

  • Asks position of a point.
  • Given parameter \ (L \) , all \ ((x, y) \ ) satisfies \ (x \ lt n - l , y \ le l \) to point to the \ ((n - l, y ) \ ) .
  • Given parameter \ (L \) , all \ ((x, y) \ ) satisfies \ (x \ le l, y \ lt n - l \) to point to the \ ((x, n - l ) \ ) .
  • Add a point.

\ (n \ 10 ^ 9 \) , \ (m \ 5 \ 5 times 10 ^ \) , \ (q \ 6 10 ^ \) .

answer

No, first he muttered.

Day2 T1 Chameleon’s Love

The meaning of problems

This is an interactive title.

There \ (2N \) chameleon, \ (n-\) only for male, \ (n-\) only for female. Each has an initial color chameleon \ (C_i \) , to meet the male and female for internal, \ (C_i \) is a \ (1 \ sim n \) arrangement. In addition, there is like a chameleon each object \ (L_i \) .

You can hold no more than \ (20 \ 000 \) times party. In the party, for a participant chameleon \ (the X-\) , if \ (l_x \) is also participating, its color would be \ (c_ L_x {} \) , otherwise the color is \ (c_x \) . You can get several kinds of participants chameleon colors. Make sure that each pair of the same color chameleon.

\ (n \ the 500 \) .

answer

No, first he muttered.

Day2 T2 Making Friends on Joitter is Fun

The meaning of problems

Given a \ (n-\) FIG points, for \ (m \) operations, each operation was added a directed edge \ ((U, V) \) .

FIG then maintain, if the presence of triplet \ ((X, Y, Z) \) , there meet the edges \ ((X, Y), (Y, Z), (Z, Y) \) , is added directed edge \ ((X, Z) \) . Has not add new operations until edges so far.

Seeking the number of sides on each step after FIG.

\ (n \ 10 ^ 5 \) , \ (m \ 3 \ Times 10 ^ 5 \) .

answer

No, first he muttered.

We are mended.

Day2 T3 Ruins 3

The meaning of problems

There \ (2N \) seat pillars, initially for each \ (X ~ (. 1 \ Le X \ n-Le) \) , has two columns height \ (X \) , ensued \ (n-\ ) earthquake, the \ (i \) earthquake will make all the height is not \ (0 \) pillars \ (J \) , set up its original height \ (h_j \) , if satisfied there is a \ (k \) such that \ (h_j h_k = \) , pillars \ (J \) height would be reduced by one.

Finally only the \ (n-\) seat pillars, columns are given in the original sequence corresponding to the index, capable of forming such an initial seeking the number of programs. For \ (9 + 10 ^ 7 \) modulo.

\ (n \ the 600 \) .

answer

No, first the goo.

Day3 T1 Constellation 3

The meaning of problems

A \ (n \ times n \) plane, there are several grid blacked out on a plane, wherein the first \ (I \) column is blacked out for the first grid \ (1 \) line beginning to the \ (a_i \) all grid lines.

When it is not dyed black grid, there are a number of key grid. Each keyframe has a value \ (C_i \) .

You need to delete some of the key grid so that there is a rectangle on the plane, so that no black rectangle inside this grid, and more than two keyframe. Consideration for the delete key and the value of the sum. Seek minimum cost.

\ (n, m \ 2 \ Times 10 ^ 5 \) .

answer

First of all the buildings around to push, leaving only wall left end right end, ie \ (I \) columns \ (i + 1 \) wall height between the column of \ (\ max (a_i, a_ {i + 1}) \) . Now become required within the rectangle can not have a wall.

The abstracted into a sequence of length \ (n-\) chains connected \ (I \) dot and \ (i + 1 \) high value of the wall between the number of dots, i.e., \ (\ max (a_i, + {I}. 1 A_) \) . Then build a large tree root Kruskal reconstruction.

For every star, we find it most shallow ancestors, meet \ (weight_f \ the y-lt \) , which guarantees \ (fa_f \ the y-GE \) , this approach is similar to the way out NOI 2018, can multiply to find.

The answer is converted into all the stars - the stars and the selected maximum value.

And then design \ (f_i \) represents the sub-tree \ (i \) inside, joined the ownership value does not exceed \ (weight_ {fa (i) } \) stars (that is, not to be merged interval conflict) is maximum.

In \ (U \) do, when combined on a special operation is not, \ (= F_ {f_u LSON (U)} + {rson F_ (U)} \) .

Another is that there may be some stars to be in \ (u \) added on, that is the most shallow ancestors previously found useful.

When adding a star, the tree drawn, it will find the answer is that star of \ (c \) plus some from the leaves to the \ (u \) on the path (not on all the sons path) \ (f \) the sum.

This may be simply a tree maintenance chain split, each node is able to save weight son \ (F \) values, calculate the value of the individual light son upon the severity of the chain switching. In accordance with some optimization of the nature referred to suffixes and one heavy chain \ (\ log \) .

Time complexity \ (\ mathcal {O} (n-\ log n-m + \ log n-) \) .

Code

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>

const int MaxN = 200000, MaxM = 200000;
const int MaxV = 400000, MaxLog = 19;

struct edge_t {
  int u, v, w;
  edge_t(int _u = 0, int _v = 0, int _w = 0) { u = _u, v = _v, w = _w; }
  inline friend bool operator<(const edge_t &a, const edge_t &b) { return a.w < b.w; }
};

struct star_t {
  int x, y, c;
  star_t(int _x = 0, int _y = 0, int _c = 0) { x = _x, y = _y, c = _c; }
};

int N, M, V;
long long Sum;
int Height[MaxN + 5];
star_t A[MaxM + 5];
int Par[MaxV + 5], Fa[MaxLog + 1][MaxV + 5], Dep[MaxV + 5], Weight[MaxV + 5], Lson[MaxV + 5], Rson[MaxV + 5];
int Siz[MaxV + 5], Wson[MaxV + 5], Top[MaxV + 5];
std::vector<int> Vec[MaxV + 5];
long long F[MaxV + 5], Suf[MaxV + 5];

void init() {
  scanf("%d", &N);
  for (int i = 1; i <= N; ++i) scanf("%d", &Height[i]);
  N++; Height[N] = N;
  scanf("%d", &M);
  for (int i = 1; i <= M; ++i) {
    scanf("%d %d %d", &A[i].x, &A[i].y, &A[i].c);
    Sum += A[i].c;
  }
}

int find(int x) { return x == Par[x] ? x : Par[x] = find(Par[x]); }

void dfs(int u) {
  Siz[u] = 1;
  if (u <= N) return;
  Dep[Lson[u]] = Dep[u] + 1;
  Fa[0][Lson[u]] = u;
  for (int i = 1; (1 << i) <= Dep[Lson[u]]; ++i)
    Fa[i][Lson[u]] = Fa[i - 1][Fa[i - 1][Lson[u]]];
  Dep[Rson[u]] = Dep[u] + 1;
  Fa[0][Rson[u]] = u;
  for (int i = 1; (1 << i) <= Dep[Rson[u]]; ++i)
    Fa[i][Rson[u]] = Fa[i - 1][Fa[i - 1][Rson[u]]];
  dfs(Lson[u]), dfs(Rson[u]);
  Siz[u] += Siz[Lson[u]] + Siz[Rson[u]];
  if (Siz[Lson[u]] > Siz[Rson[u]]) Wson[u] = Lson[u];
  else Wson[u] = Rson[u];
}

void dfs(int u, int chain) {
  Top[u] = chain;
  if (u <= N) return;
  dfs(Wson[u], chain);
  dfs(Wson[u] == Lson[u] ? Rson[u] : Lson[u], Wson[u] == Lson[u] ? Rson[u] : Lson[u]);
}

inline int binSearch(int u, int val) {
  for (int i = MaxLog; i >= 0; --i) {
    if (Fa[i][u] == 0) continue;
    if (Weight[Fa[i][u]] < val) u = Fa[i][u];
  }
  return u;
}

inline long long queryPath(int u, int f) {
  long long res = 0;
  while (Top[u] != Top[f]) {
    res += Suf[Top[u]] - Suf[u];
    u = Fa[0][Top[u]];
    res += F[Wson[u]];
  }
  res += Suf[f] - Suf[u];
  return res;
}

void bfs() {
  static int que[MaxV + 5], ind[MaxV + 5];
  int head = 1, tail = 0;
  for (int i = N + 1; i <= V; ++i) ind[i] = 2;
  for (int i = 1; i <= N; ++i) que[++tail] = i;
  while (head <= tail) {
    int u = que[head++];
    if (u > N) {
      F[u] = F[Lson[u]] + F[Rson[u]];
      Suf[u] += Suf[Wson[u]];
    }
    for (int id : Vec[u]) {
      int x = A[id].x, c = A[id].c;
      F[u] = std::max(F[u], queryPath(x, u) + c);
    }
    if (u != V && Wson[Fa[0][u]] != u) Suf[Fa[0][u]] += F[u];
    ind[Fa[0][u]]--;
    if (ind[Fa[0][u]] == 0) que[++tail] = Fa[0][u];
  }
}

void solve() {
  static edge_t e[MaxN + 5];
  for (int i = 1; i < N; ++i) e[i] = edge_t(i, i + 1, std::max(Height[i], Height[i + 1]));
  std::sort(e + 1, e + N);
  for (int i = 1; i <= N; ++i) Par[i] = i;
  V = N;
  for (int i = 1; i < N; ++i) {
    int u = e[i].u, v = e[i].v, w = e[i].w;
    int p = find(u), q = find(v);
    V++;
    Par[p] = Par[q] = Par[V] = V;
    Weight[V] = w;
    Lson[V] = p, Rson[V] = q;
  }
  dfs(V), dfs(V, V);
  for (int i = 1; i <= M; ++i) {
    int f = binSearch(A[i].x, A[i].y);
    Vec[f].push_back(i);
  }
  bfs();
  printf("%lld\n", Sum - F[V]);
}

int main() {
  init();
  solve();
  return 0;
}

Day3 T2 Harvest

The meaning of problems

Has a length \ (L \) of the ring, with a \ (N \) staff, \ (M \) of fruit trees, the \ (I \) employees located \ (A_i \) , the \ (I \) fruit trees located in \ (B_i \) . \ (A_i, B_i \) This \ (N + M \) number of pairwise disjoint.

Per employee per second to be \ (+ 1 \) to move one space. If an employee reaches an apple tree, and the apple tree, he would have plucked an apple. Apple picking time is negligible.

There will only be up to each of them an apple on an apple tree. If an apple is taken under the tree takes \ (C \) time will grow a new apple.

There \ (Q \) once asked, each time asked to give two numbers \ (V_i, T_i \) , asked for the first \ (V_i \) number of employees, were \ (T_i \) after time, the number of apple picking.

\ (L, C \ 10 ^ 9 \) , \ (N, N \ 2 \ Times 10 ^ 5 \) , \ (T_i \ 10 ^ {18} \) .

answer

No, first the goo.

Day3 T3 Stray Cat

The meaning of problems

This is a communication problem. Two men Anthony and Catherine, need to implement their programs, respectively.

Given a \ (n-\) points, \ (m \) FIG strip edges. Anthony mark may be placed on the side, a total marking \ (A \) species. Catherine beginning at a node, she needs to get information in advance by Anthony placed mark, no more than a few steps in excess \ (b \) arriving within walking \ (0 \) number of nodes.

Catherine information is acquired, for the current point, in addition to the way other than that edge, the number of each marker for the other edges. She can choose a color to go, you can walk back along that first came to the edge.

Please strategic design of Anthony and Catherine.

\ (n, m \ 20 \ 000 \) .

There are two types of data:

  • \(a = 3, b = 0\)
  • \(a = 2, m = n - 1, b = 6\)

answer

Two types resolved.

The first category \ (a = 3, b = 0 \)

Noting \ (\ Binom {2} = {}. 3. 3 \) , we can be determined according to the adjacent color are a number of types which should go on edge. We might as well make Catherine's policy, if the adjacent color is only one, that kind of went away; otherwise adjacent color into two, if it is \ (0, 1 \) , select the color \ (0 \) , If it is \ (1, 2 \) , a color selection \ (1 \) , if it is \ (2, 0 \) , a color selection \ (0 \) . Anthony's next construction program so that he can properly guide Catherine.

From \ (0 \) Shortest dot began to run the original image, build a shortest path tree. The triangle inequality, for each side of the original, or two adjacent connection or connecting the two points in the same layer. We make two connecting adjacent edges according to the color depth of the order of \ (0,. 1, 2, 0,. 1, 2, \ ldots \) , connected to one side of the same color in this layer is connected to the next layer side color to ensure that Catherine would never go.

So that you can correctly guide the score \ (15 \) points.

The second category \ (a = 2, m = n - 1, b = 6 \)

Guess you like

Origin www.cnblogs.com/tweetuzki/p/12572031.html