C. Upgrade Required
开一个桶来维护每种版本的电脑数量,一开始每个桶中的电脑数都是 \(1\)
用变量 \(r\) 来维护“第一个可能非空的版本号”,并且 \(r\) 只会单调递增。每次操作把 \(r\) 指向的连续若干个桶(直到 \(x\))合并到 \(y\),并把这些痛清空。
代码实现
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)using namespace std;int main() {int n, q;cin >> n >> q;vector<int> cnt(n+1);for (int i = 1; i <= n; ++i) cnt[i] = 1;int r = 1;rep(qi, q) {int x, y;cin >> x >> y;int ans = 0;while (r <= x) {ans += cnt[r];cnt[r] = 0;r++;}cnt[y] += ans;cout << ans << '\n';}return 0;
}
D. Pop and Insert
固定某个极大同字符连续段,和它不在一段的相同字符的代价是 \(2\),剩下其他不同字符的代价是 \(1\)
代码实现
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)using namespace std;void solve() {int n;string s;cin >> n >> s;vector<int> cnt(2);vector<pair<char, int>> d(1, {s[0], 0});for (char c : s) {cnt[c-'0']++;if (d.back().first == c) {d.back().second++;}else {d.emplace_back(c, 1);}}int ans = n*2;for (auto [c, num] : d) {int i = c-'0';vector<int> ncnt = cnt;ncnt[i] -= num;int now = ncnt[i]*2 + ncnt[i^1];ans = min(ans, now);}cout << ans << '\n';
}int main() {int t;cin >> t;while (t--) solve();return 0;
}
E. Closest Moment
将两人的位置做相对位移(把 Aoki 的位置视为参照,把原点看作 Aoki 的位置)——这样问题变为“一个点(Takahashi 相对于 Aoki 的位置)在时间上沿线段-线段折线运动,求到原点的最小距离”。
因为速度相同且是匀速行直线,故相对位移随时间是分段线性的,只需在关键时间点(\(0\),短者到达时,长者到达时)取位置,得到最多两条线段的折线。
最小距离即是原点到这条折线的最短距离,可逐段求点到线段距离并取最小值。
代码实现
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)using namespace std;const double eps = 1e-9;
struct V {double x, y;V(double x=0, double y=0): x(x), y(y) {}V& operator+=(const V& v) { x += v.x; y += v.y; return *this; }V operator+(const V& v) const { return V(*this) += v; }V& operator-=(const V& v) { x -= v.x; y -= v.y; return *this; }V operator-(const V& v) const { return V(*this) -= v; }V& operator*=(double s) { x *= s; y *= s; return *this; }V operator*(double s) const { return V(*this) *= s; }V& operator/=(double s) { x /= s; y /= s; return *this; }V operator/(double s) const { return V(*this) /= s; }double dot(const V& v) const { return x*v.x + y*v.y; }double cross(const V& v) const { return x*v.y - v.x*y; }double norm2() const { return x*x + y*y; }double norm() const { return sqrt(norm2()); }int ort() const { // orthantif (abs(x) < eps and abs(y) < eps) return 0;if (y > 0) return x > 0 ? 1 : 2;else return x < 0 ? 3 : 4; }bool operator<(const V& v) const {int o = ort(), vo = v.ort();if (o != vo) return o < vo;return cross(v) > 0;}
};
istream& operator>>(istream& is, V& v) {is >> v.x >> v.y; return is;
}
ostream& operator<<(ostream& os, const V& v) {os << "(" << v.x << "," << v.y << ")"; return os;
}struct Line {V s, t;Line(V s=V(0,0), V t=V(0,0)):s(s),t(t){}V dir() const { return t-s;}// V normalize() const { return dir().normalize();}double norm() const { return dir().norm();}/* +1: s-t,s-p : ccw* -1: s-t,s-p : cw* +2: t-s-p* -2: s-t-p* 0: s-p-t */int ccw(const V& p) const {if (dir().cross(p-s) > eps) return +1;if (dir().cross(p-s) < -eps) return -1;if (dir().dot(p-s) < -eps) return +2;if (dir().norm()+eps < (p-s).norm()) return -2;return 0;}bool touch(const Line& l) const {int a = ccw(l.s)*ccw(l.t), b = l.ccw(s)*l.ccw(t);return !a || !b || (a == -1 && b == -1);}V divpoint(double p) const {return s*(1-p) + t*p;}double distSP(V p) const {if ((p-s).dot(t-s) < eps) return (s-p).norm();if ((p-t).dot(s-t) < eps) return (t-p).norm();return abs((s-p).cross(t-p))/(t-s).norm();}
};void solve() {Line t, a;cin >> t.s >> t.t >> a.s >> a.t;if (t.norm() < a.norm()) swap(t, a);double tlen = t.norm();double alen = a.norm();double ans = 1e18;{Line l;l.s = t.s-a.s;l.t = t.divpoint(alen/tlen) - a.t;ans = min(ans, l.distSP(V(0, 0)));}{Line l;l.s = t.divpoint(alen/tlen) - a.t;l.t = t.t-a.t;ans = min(ans, l.distSP(V(0, 0)));}printf("%.10f\n", ans);
}int main() {int t;cin >> t;while (t--) solve();return 0;
}
F. Clearance
使用支持区间加法和区间最小值查询的带延迟标记的线段树来维护数组状态。
当某次操作使得某个元素变为负数时,先在线段树上通过二分查找定位该位置,然后将其置为 \(+\infty\) 。同时再用树状数组维护 \(+\infty\) 值的个数,以支持查询区间内至少有 \(k\) 件的商品种类数。
代码实现
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
#define rep(i, n) for (int i = 0; i < (n); ++i)using namespace std;
using ll = long long;ll op(ll a, ll b) { return min(a, b); }
ll e() { return 1e18; }
ll mapping(ll f, ll x) { return x-f; }
ll composition(ll f, ll g) { return f+g; }
ll id() { return 0; }int main() {int n;cin >> n;vector<ll> a(n);rep(i, n) cin >> a[i];int q;cin >> q;lazy_segtree<ll, op, e, ll, mapping, composition, id> rem(a);fenwick_tree<int> sold(n);rep(qi, q) {int l, r, k;cin >> l >> r >> k;--l;ll ans = ll(r-l-sold.sum(l, r))*k;rem.apply(l, r, k);while (1) {auto f = [&](ll x) { return x >= 0; };int i = rem.max_right(l, f);if (i >= r) break;ans += rem.get(i);rem.set(i, e());sold.add(i, 1);}cout << ans << '\n';}return 0;
}
G. Range Knapsack Query
二区间合并(又叫“猫树分治”)
在这里,只需对左半区间做从右往左的 \(01\) 背包,以及对右半区间做从左往右的 \(01\) 背包
代码实现
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)using namespace std;
using ll = long long;
using Q = tuple<int, int, int, int>;inline void chmax(ll& a, ll b) { if (a < b) a = b; }int main() {cin.tie(nullptr) -> sync_with_stdio(false);int n, q;cin >> n >> q;vector<int> w(n), v(n);rep(i, n) cin >> w[i];rep(i, n) cin >> v[i];vector<Q> qs;rep(qi, q) {int l, r, c;cin >> l >> r >> c;--l;qs.emplace_back(l, r, c, qi);}vector<ll> ans(q);const int m = 200;vector dp(n+1, vector<ll>(m+1));auto f = [&](auto& f, int l, int r, vector<Q> qs) -> void {int k = (l+r)/2;dp[k] = vector<ll>(m+1);for (int i = k-1; i >= l; --i) {dp[i] = dp[i+1];for (int j = m-w[i]; j >= 0; --j) {chmax(dp[i][j+w[i]], dp[i][j]+v[i]);}}for (int i = k; i < r; ++i) {dp[i+1] = dp[i];for (int j = m-w[i]; j >= 0; --j) {chmax(dp[i+1][j+w[i]], dp[i+1][j]+v[i]);}}vector<Q> ql, qr;for (auto [nl, nr, c, qi] : qs) {if (nr < k) ql.emplace_back(nl, nr, c, qi);else if (nl > k) qr.emplace_back(nl, nr, c, qi);else {ll now = 0;rep(j, c+1) chmax(now, dp[nl][j]+dp[nr][c-j]);ans[qi] = now;}}if (ql.size()) f(f, l, k, ql);if (qr.size()) f(f, k, r, qr);};f(f, 0, n, qs);rep(qi, q) cout << ans[qi] << '\n';return 0;
}
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/928299.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!相关文章
muse cc 做网站wordpress 中文社区
商家转账到零钱是什么?
通过商家转账到零钱这个功能,如果我们系统需要对用户支付费用,比如发放佣金、提成、退款之类的,可以直接转账到用户的微信零钱。
【商家转账到零钱】是【企业付款到零钱】的升级版,2022年5月1…
完整教程:OS9.【Linux】基本权限(下)
完整教程:OS9.【Linux】基本权限(下)pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Mona…
wordpress一个主站多个子站百度百科优化排名
腾讯云4核8G服务器支持多少人在线访问?支持25人同时访问。实际上程序效率不同支持人数在线人数不同,公网带宽也是影响4核8G服务器并发数的一大因素,假设公网带宽太小,流量直接卡在入口,4核8G配置的CPU内存也会造成计算…
怎么样在服务器上建设网站济南建设网济南市建培中心
摘要:近几年,Android系统占据着智能移动设备操作系统领域中极大的市场份额。随着Android市场中软件数量的不断攀升,移动用户对Android应用的质量要求也越来越高。如何保证Android软件的质量,成为移动应用领域中亟待解决的问题。重视移动应用的测试工作,是提高Androi…
楚雄建设局网站成都平面设计公司
从叶到花,或从花到叶,于科研是一个过程,而于生命自身则永远只在此刻。花和叶都是一种记忆方式,果子同时也是种子。生命是闪耀的此刻,不是过程,就像芳香不需要道路一样。 ——顾城《一个人应该活得是他自己并且干净》 二叉搜索树:右子树节点值都比node大,…
专业的外贸网站建设安徽合肥网站制作
1⃣️环境准备
准备 Java 环境:终端输入 java -version 命令来确认版本是否符合 Elasticsearch 要求下载并解压 Elasticsearch:前往(https://www.elastic.co/downloads/elasticsearch)选择适合你的 Mac 系统的 Elasticsearch 版本…
完整教程:JVM——云原生时代JVM的演进之路
pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", …
价值原语博弈:AI元人文的伦理架构探索
价值原语博弈:AI元人文的伦理架构探索
在人工智能伦理研究的当前阶段,我们面临着将抽象道德原则转化为可实践框架的挑战。本文提出“价值原语博弈”作为实现AI元人文理念的一种工程化路径,通过构建动态的价值计算模…
实用指南:【C++高并发内存池篇】性能卷王养成记:C++ 定长内存池,让内存分配快到飞起!
实用指南:【C++高并发内存池篇】性能卷王养成记:C++ 定长内存池,让内存分配快到飞起!pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !importan…
商丘家具网站建设个人网页制作模板html
2023.12.2 做一个后台管理网页(左侧边栏实现手风琴和隐藏/出现效果)
网页源码见附件,比较简单,之前用很多种方法实现过该效果,这次的效果相对更好。 实现功能: (1)实现左侧边栏的手…
设备管理系统网站模板企业怎么做网站建设
一,单层板:
1,铜皮
和导线类似,提供电路板上的电信号传导路径。
因为铜具有良好的导热性能,因此铜皮还可以用于散热。在高功率电子设备中,通过在PCB上增加铜皮面积和散热片,可以提高散热效果…
VR/AR 显示瓶颈将破!铁电液晶技巧迎来关键突破
VR/AR 显示瓶颈将破!铁电液晶技巧迎来关键突破pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", &…
珠海网站制作推广ai做的比较好的网站
摘要: Cloud Native 应用架构随着云技术的发展受到业界特别重视和关注,尤其是 CNCF(Cloud Native Computing Foundation)项目蓬勃发展之际。Dubbo 作为服务治理的标志性项目,自然紧跟业界的潮流,拥抱技术的…
Axure 基础入门 - 实践
pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", …
博客园-awescnb插件-geek皮肤异常问题修复
💖简介
awescnb插件因字节的CDN关闭,导致皮肤部分依赖外部js的插件功能受影响,例如:图标不显示、音乐播放器无显示等。
all.min.css与typed.min.js无法正常拉取
📣官方通知
https://www.yuque.com/awescnb/pugl…
国庆 Day1 强基化学
有一点意思但不多。给你爹唐死了。又是清北教授。又是那副很高高在上的态度,讲你妈一上午啥都没讲。
动力学(提高)
一、Arrhenius 公式
\[\large k=Ae^{-\frac{E_a}{RT}}
\]大学中对于数据分析常用线性回归,在对数…
leetcode付费题 353. 贪吃蛇游戏解题思路 - 指南
leetcode付费题 353. 贪吃蛇游戏解题思路 - 指南pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", …
实用指南:【发布实录】云原生+AI,助力企业全球化业务创新
pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", …