Codeforces 比赛记录

Codeforces Round 990 (Div2)

E.Adventurers

平面上有若干点。选择一个划分点 \((x_0, y_0)\)。然后,对于坐标为 \((x_i, y_i)\) 的城市:

  • 如果 \(x_0 \le x_i\)\(y_0 \le y_i\),第一个商人在此城市销售商品;
  • 如果 \(x_0 > x_i\)\(y_0 \le y_i\),第二个商人在此城市销售商品;
  • 如果 \(x_0 \le x_i\)\(y_0 > y_i\),第三个商人在此城市销售商品;
  • 如果 \(x_0 > x_i\)\(y_0 > y_i\),第四个商人在此城市销售商品。

商人们希望选择一个划分点 \((x_0, y_0)\),使得他们中任何一个人得到的城市数量尽可能公平(即最小化得到的城市数量的最大值)。请为他们找到这样一个点。

hint

binary search

F.For the Emperor!

在古罗马,为了击败野蛮人,制定了一项计划,但要实施该计划,每个城市都必须得到通知。

罗马帝国的北部由 \(n\) 个城市组成,这些城市通过 \(m\) 条单向道路相连。起初,第 \(i\) 个城市有 \(a_i\) 名信使,每名信使可以沿着现有的道路自由地在城市间移动。一名信使可以携带一份计划副本,并在他访问的城市中传达信息,并且可以在他当前所在的城市为其他信使制作无限多的副本。

开始时,你需要制作一定数量的计划,并将它们交给选定的信使。你的目标是确保每座城市都被携带计划的信使访问过。找出最初需要制作的计划的最小数量,以确保信使能够将计划送到每一个城市,或者确定根本无法做到这一点。

hint

costflow

sol

考虑建立费用流模型,核心思想是让最大流量总是 \(\sum a_i\),而经过一个点的费用是 \(-B\)\(B\) 是一个极大的数),在一个点发放计划的费用是 1,这样求出最小费用之后,可以根据其除以 B 的整数部分计算其最多能让多少个点收到计划,根据余数计算出该前提下最小发放计划的数量。

[VP] Educational Codeforces Round 176 (Rated for Div. 2)

F. Beautiful Sequence Returns

如果以下条件成立,我们就把一个整数序列称为美丽

  • 除第一个元素外,每个元素的左边都有一个比它小的元素;
  • 除最后一个元素外,每个元素的右边都有一个比它大的元素;

给你一个大小为 \(n\) 的整数数组 \(a\) 。请求出最长优美子序列的长度。\(n \leq 5 \times 10^5\)

sol

一个子序列合法,当且仅当第一个元素是严格最小值,最后一个元素是严格最大值。

\((i,a_i)\) 表示在二维平面,只有一些点能成为左下角,一些点能成为右上角。求出来。

对于某个点,会将它统计进去的左下角,一定是一段区间,预先求出。

枚举右上角,线段树动态维护贡献。

Neowise Labs Contest 1 (Codeforces Round 1018, Div. 1 + Div. 2)

F. Wonderful Impostors

Today, you will play a game with \(n\) viewers numbered \(1\) to \(n\).Each player is either a crewmate or an impostor. You don't know the role of each viewer.

There are \(m\) statements numbered \(1\) to \(m\), which are either true or false. For each \(i\) from \(1\) to \(m\), statement \(i\) is one of two types:

  • \(0\:a_i\:b_i\) (\(1 \leq a_i \leq b_i \leq n\)) — there are no impostors among viewers \(a_i, a_i + 1, \ldots, b_i\);
  • \(1\:a_i\:b_i\) (\(1 \leq a_i \leq b_i \leq n\)) — there is at least one impostor among viewers \(a_i, a_i + 1, \ldots, b_i\).

Answer \(q\) questions of the following form:

  • \(l\:r\) (\(1 \leq l \leq r \leq m\)) — is it possible that statements \(l, l + 1, \ldots, r\) are all true?

\(n,m,q \leq 200000\).

sol

We'll use the two pointers method. To answer a question \(s_l\,s_r\), we just check that \(s_l \geq low(s_r)\).

  1. When we add a \(1\)-segment \([b_l, b_r]\), we can use a segment tree to check if it will be fully covered by a \(0\)-component.
  2. When we add a \(0\)-segment \([a_l, a_r]\), it might merge several \(0\)-components. So first we need to find the \(0\)-component \([c_l, c_r]\) that contains \([a_l, a_r]\).
  • \(c_l\) is the smallest value such that \(\min(count(c_l), count(c_l + 1), \ldots, count(a_l)) > 0\).
  • \(c_r\) is the largest value such that \(\min(count(a_r), count(a_r + 1), \ldots, count(c_r)) > 0\).
  • Both of these values can be found by performing a walk on the segment tree.
  • Now we only need to check if there's a \(1\)-segment that's fully covered by \([c_l, c_r]\).

G. Wonderful Guessing Game

This is an interactive problem.

Alice is thinking of an integer from \(1\) to \(n\), and you must guess it by asking her some queries.To make things harder, she says you must ask all the queries first, and she will ignore exactly \(1\) query.

For each query, you choose an array of \(k\) distinct integers from \(1\) to \(n\), where \(k\) is even. Then, Alice will respond with one of the following:

  • \(\texttt{L}\): the number is one of the first \(\frac{k}{2}\) elements of the array;
  • \(\texttt{R}\): the number is one of the last \(\frac{k}{2}\) elements of the array;
  • \(\texttt{N}\): the number is not in the array;
  • \(\texttt{?}\): this query is ignored.

You must find a strategy that minimizes the number of queries. Can you do it? We can show that \(f(n) \leq 20\) for all \(n\) such that \(2 \le n \le 2 \cdot 10^5\).

sol

考虑如果 Alice 老老实实回答每个问题怎么做。

\(L\) 视作 \(-1\),将 \(R\) 视作 \(1\),将 \(N\) 视作 \(0\)。每次询问和必须等于 \(0\)

只要对于任意两个数都满足,存在一组询问使得这两个数对应的值不同,就可以根据回答的序列唯一确定每个数。

如果 Alice 忽略了某次询问呢?想想怎么还原被忽略的询问。

再添加一个询问,使得对于任意权值,询问的和模 \(3\) 都等于 \(0\),这样我们可以根据和求出被忽略的询问,就可以做了。

posted @ 2025-02-21 15:31  wanggk  阅读(118)  评论(0)    收藏  举报