A. United We Stand

题解

  • 赛时想复杂了
  • 题目要求我们保证数组\(c\)中的数不是数组\(b\)中任意一个数的因子
  • 我们考虑将最小值置于数组\(b\)即可
const int N = 2e5 + 10, M = 4e5 + 10;

int n;
int a[N]; void solve()
{
cin >> n;
int mi = INF;
for (int i = 1; i <= n; ++i)
{
cin >> a[i];
mi = min(a[i], mi);
}
vector<int> b, c;
for (int i = 1; i <= n; ++i)
{
if (a[i] == mi)
b.push_back(a[i]);
else
c.push_back(a[i]);
}
if (b.size() == 0 || c.size() == 0)
cout << -1 << endl;
else
{
cout << b.size() << " " << c.size() << endl;
for (auto x : b)
cout << x << " ";
cout << endl;
for (auto x : c)
cout << x << " ";
cout << endl;
}
}

B. Olya and Game with Arrays

题解

  • 我们考虑贪心
  • 对于所有数组中的最小值来说,不管我们怎么移动,他对答案的贡献不变
  • 所以我们考虑将每个数组中的最小值移动到某一个数组中,使得次小值对答案产生贡献
  • 我们如何确定被移动到的是哪一个数组呢
  • 只要对次小值排序即可,对于存在最小的次小值的数组就是被移动到的数组
const int N = 2e5 + 10, M = 4e5 + 10;

int n;
vector<int> vec[N]; void solve()
{
cin >> n;
int mi = INF;
vector<int> b;
for (int i = 1; i <= n; ++i)
{
int k;
cin >> k;
vec[i].clear();
for (int j = 1; j <= k; ++j)
{
int x;
cin >> x;
vec[i].push_back(x);
}
sort(all(vec[i]));
b.push_back(vec[i][1]);
mi = min(mi, vec[i][0]);
}
sort(all(b));
int ans = 0;
ans += mi;
for (int i = 1; i < b.size(); ++i)
ans += b[i];
cout << ans << endl;
}

C. Another Permutation Problem

题解

  • 打表找规律
  • 发现除了\(n=2\)时都是先升序后降序的形式,例如\([1, 2,3,4,8,7,6,5]\)
  • \(O(n^2)\)枚举在哪个位置开始降序即可
const int N = 2e5 + 10, M = 4e5 + 10;

int n;
int a[N], b[N], c[N]; void solve()
{
cin >> n;
if (n == 2)
{
cout << 2 << endl;
return;
}
int ans = 0;
for (int i = 1; i <= n; ++i)
{
int mx = 0, sum = 0;
for (int j = 1; j <= i; ++j)
{
sum += j * j;
mx = max(mx, j * j);
}
int t = n;
for (int j = i + 1; j <= n; ++j)
{
sum += t * j;
mx = max(mx, t * j);
--t;
}
ans = max(ans, sum - mx);
}
cout << ans << endl;
}

D. Andrey and Escape from Capygrad

\(1 \leq n, q\leq 2e5\)

题解

  • 显然越向右移动越好,所以我们肯定选择\(l_i \leq x \leq b_i\)中较大的\(b_i\)传送,因为只有\(b_j > l_i\)时才能传送,所以实际上的区间为\([l_i, b_i]\)
  • 所以问题转化为给定\(n\)个区间\([l_i,b_i]\),对于数轴上一点\(x > 0\),对于左端点\(l_i \leq x\)的区间,我们找到其最大的右端点
  • 所以我们先考虑将区间合并\(O(nlogn)\)
  • 然后离散化区间左端点和询问点
  • 然后线段树在左端点处单点修改加上右端点的值即可,维护区间最大值
const int N = 4e5 + 10, M = 4e5 + 10;

int n, q;
struct node
{
int l, r, a, b;
bool operator<(const node &t) const
{
return l < t.l;
}
} line[N];
int l[N], r[N], tot, qry[N]; struct info
{
int mx;
friend info operator+(const info &a, const info &b)
{
info c;
c.mx = max(a.mx, b.mx);
return c;
}
};
struct SEG
{
info val;
} seg[N << 2]; void up(int id)
{
seg[id].val = seg[lson].val + seg[rson].val;
} void build(int id, int l, int r)
{
if (l == r)
{
seg[id].val.mx = 0;
return;
}
int mid = l + r >> 1;
build(lson, l, mid);
build(rson, mid + 1, r);
up(id);
} void change(int id, int l, int r, int x, int val)
{
if (l == r)
{
seg[id].val.mx = val;
return;
}
int mid = l + r >> 1;
if (x <= mid)
change(lson, l, mid, x, val);
else
change(rson, mid + 1, r, x, val);
up(id);
} info query(int id, int l, int r, int ql, int qr)
{
if (ql <= l && r <= qr)
{
return seg[id].val;
}
int mid = l + r >> 1;
if (qr <= mid)
return query(lson, l, mid, ql, qr);
else if (ql > mid)
return query(rson, mid + 1, r, ql, qr);
else
return query(lson, l, mid, ql, qr) + query(rson, mid + 1, r, ql, qr);
} void solve()
{
cin >> n;
for (int i = 1; i <= n; ++i)
{
int l, r, a, b;
cin >> l >> r >> a >> b;
line[i] = {l, r, a, b};
}
// 区间合并
sort(line + 1, line + n + 1);
tot = 0;
int st = line[1].l, ed = line[1].b;
line[n + 1] = {INF, INF, INF, INF};
for (int i = 2; i <= n + 1; ++i)
{
auto [L, R, a, b] = line[i];
if (L > ed)
{
tot++;
l[tot] = st, r[tot] = ed;
st = L, ed = b;
}
else
ed = max(ed, b);
}
vector<int> vec;
auto find = [&](int x)
{
return lower_bound(all(vec), x) - vec.begin() + 1;
};
for (int i = 1; i <= tot; ++i)
vec.push_back(l[i]);
cin >> q;
for (int i = 1; i <= q; ++i)
{
cin >> qry[i];
vec.push_back(qry[i]);
}
sort(all(vec));
vec.erase(unique(all(vec)), vec.end());
int m = vec.size() + 10;
build(1, 1, m);
for (int i = 1; i <= tot; ++i)
change(1, 1, m, find(l[i]), r[i]);
for (int i = 1; i <= q; ++i)
{
int x = find(qry[i]);
int mx = query(1, 1, m, 1, x).mx;
cout << max(mx, qry[i]) << " ";
}
cout << endl;
}

Codeforces Round 892 (Div.2)的更多相关文章

  1. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  2. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  3. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  4. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  5. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

  6. Codeforces Round #262 (Div. 2) 1003

    Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...

  7. Codeforces Round #262 (Div. 2) 1004

    Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory lim ...

  8. Codeforces Round #371 (Div. 1)

    A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...

  9. Codeforces Round #268 (Div. 2) ABCD

    CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...

  10. 贪心+模拟 Codeforces Round #288 (Div. 2) C. Anya and Ghosts

    题目传送门 /* 贪心 + 模拟:首先,如果蜡烛的燃烧时间小于最少需要点燃的蜡烛数一定是-1(蜡烛是1秒点一支), num[g[i]]记录每个鬼访问时已点燃的蜡烛数,若不够,tmp为还需要的蜡烛数, ...

随机推荐

  1. 常回家看看之house_of_kiwi

    house of kiwi 前言:house_of_kiwi 一般是通过触发__malloc_assert来刷新IO流,最后可以劫持程序流或者通过和setcontext来打配合来进行栈迁移来得到fla ...

  2. SPIE独立出版。遥感征稿中--2024年遥感与数字地球国际学术会议(RSDE 2024)

    ​ [成都,遥感主题,稳定EI检索]2024年遥感与数字地球国际学术会议(RSDE 2024) 2024 International Conference on Remote Sensing and ...

  3. manim边学边做--通用多边形

    manim提供了通用多边形模块,可以绘制任意的多边形. 通用多边形模块有两种,Polygon和Polygram. Polygon是一个几何学术语,主要指的是由三条或三条以上的线段首尾顺次连接所组成的平 ...

  4. 1Before You Install Flask...Watch This! Flask Fridays #1

    flask官网: https://flask.github.net.cn/ git官网: https://git-scm.com/ 建立文件: 建立虚拟环境.激活: source virt/Scrip ...

  5. 国庆快乐!附ssh实战

    小伙伴们,有一段时间没更新了,目前在中科院软件所实习,在这里我祝大家国庆快乐! 今天这一期带来ssh命令的实战教程,ssh在工作当中遇到的非常多,因为总是需要登服务器,而且玩法也有不少,这是我常用的几 ...

  6. Android Qcom USB Driver学习(八)

    因为要看usb charging的问题,所以需要补充一下battery的相关知识,算是入门吧 BAT SCH (1)VBATT_VSNS_P (2)BAT_THERM (3)I2C_SDA (4)I2 ...

  7. CRLF the next time Git touches it warning: in the working copy of '', LF will be replaced by CRLF the next time Git touches it warning: in the working copy of

    git config --global core.autocrlf true

  8. MongoDB安装及配置Navicat MongoDB Tools

    一.下载MongoDB 1.下载网址:https://www.mongodb.com/try/download/community 注:本文档以Windows和msi安装为例 二.安装MongoDB ...

  9. 再见,Centos!

    近日,CentOS官方宣布CentOS系列稳定版Linux系统将停止维护,取而代之的是测试版的CentOS Stream,这也意味着CentOS将会退出历史舞台,因此引发了CentOS用户的强烈不满. ...

  10. Top100(下)

    Top100(下) 栈 20. 有效的括号 bool isValid(char *s) { int len = strlen(s); if (len % 2 == 1) return false; / ...