codeforcesPlayrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2)B题B. T-shirt buying

Mamba SSM 实战:IMDb 文本分类 + Mamba-ssm 全流程 Mamba SSM 文本分类链路:IMDb 二分类 → MambaLMHeadModel (d_model=256, n_layer=8, d_state=16, exp2=2) → 末 token 分类头。5 epoch 达 89.2% 准确率 (与 BERT-base 持平), 但显存降低 44% (3.5GB vs 6.2GB)。建议序列长度 ≥ 1024 再选 Mamba, 短序列 (< 512) 用 BERT 更高效。扩展时注意d_state。 阅读详情

B. T-shirt buying*

time limit per test 3 seconds
memory limit per test 256 megabytes
input standard input
output standard output

A new pack of n t-shirts came to a shop. Each of the t-shirts is characterized by three integers pi, ai and bi, where pi is the price of the i-th t-shirt, ai is front color of the i-th t-shirt and bi is back color of the i-th t-shirt. All values pi are distinct, and values ai and bi are integers from 1 to 3.

m buyers will come to the shop. Each of them wants to buy exactly one t-shirt. For the j-th buyer we know his favorite color cj.

A buyer agrees to buy a t-shirt, if at least one side (front or back) is painted in his favorite color. Among all t-shirts that have colors acceptable to this buyer he will choose the cheapest one. If there are no such t-shirts, the buyer won’t buy anything. Assume that the buyers come one by one, and each buyer is served only after the previous one is served.

You are to compute the prices each buyer will pay for t-shirts.

Input
The first line contains single integer n (1 ≤ n ≤ 200 000) — the number of t-shirts.

The following line contains sequence of integers p1, p2, …, pn (1 ≤ pi ≤ 1 000 000 000), where pi equals to the price of the i-th t-shirt.

The following line contains sequence of integers a1, a2, …, an (1 ≤ ai ≤ 3), where ai equals to the front color of the i-th t-shirt.

The following line contains sequence of integers b1, b2, …, bn (1 ≤ bi ≤ 3), where bi equals to the back color of the i-th t-shirt.

The next line contains single integer m (1 ≤ m ≤ 200 000) — the number of buyers.

The following line contains sequence c1, c2, …, cm (1 ≤ cj ≤ 3), where cj equals to the favorite color of the j-th buyer. The buyers will come to the shop in the order they are given in the input. Each buyer is served only after the previous one is served.

Output
Print to the first line m integers — the j-th integer should be equal to the price of the t-shirt which the j-th buyer will buy. If the j-th buyer won’t buy anything, print -1.

Examples
input
5
300 200 400 500 911
1 2 1 2 3
2 1 3 2 1
6
2 3 1 2 1 1
output
200 400 300 500 911 -1
input
2
1000000000 1
1 1
1 2
2
2 1
output
1 1000000000

#include<bits/stdc++.h>
using namespace std;
int n,m;
#define N 210001
#define PER(i,a,b) for(int i=a;i<=b;i++)
int a[N],b[N];int p[N];int c[N];bool pg[4][4];int t[4][4][2*N];int size[4][4];
void up(int x,int y,int k)
{
    while(k>1&&t[x][y][k]<t[x][y][k/2]) 
    {
        swap(t[x][y][k],t[x][y][k/2]);
        k/=2;
    }
}
void down(int x,int y,int k)
{
    int j;
    int le=k*2,ri=le+1;
    while(le<=size[x][y])
    {
        if(le==size[x][y]||t[x][y][le]<t[x][y][ri]) j=le;else j=ri;
        if(t[x][y][j]<t[x][y][k]) swap(t[x][y][j],t[x][y][k]);
        else return;
        k=j;le=k*2,ri=le+1;
    }
    return;
}
void add(int x,int y,int p)
{
    int num=++size[x][y];
    t[x][y][num]=p;up(x,y,num);
}
int co;
int back,on[4];
int QwQ;
int bb,cc;
int main()
{
    scanf("%d",&n); PER(i,1,n) scanf("%d",&p[i]);
    PER(i,1,3)PER(j,1,3)PER(xx,1,n+1) t[i][j][xx]=2e9;
    PER(i,1,n)scanf("%d",&a[i]);PER(i,1,n)scanf("%d",&b[i]);
    PER(i,1,n) if(a[i]>b[i]) swap(a[i],b[i]);
    PER(i,1,n) add(a[i],b[i],p[i]); scanf("%d",&m);
    PER(i,1,m)
    {
        scanf("%d",&co);
        PER(j,1,3)
        {
            bb=co;cc=j;
            if(bb>cc) swap(bb,cc);
            on[j]=t[bb][cc][1];
        }
        QwQ=2e9;
        PER(j,1,3) {if(QwQ>on[j]) {back=j;QwQ=on[j];}}if(back==0||QwQ>1e9+4001) QwQ=-1;
        printf("%d ",QwQ);
        bb=co;cc=back;if(bb>cc) swap(bb,cc);t[bb][cc][1]=2e9+5;down(bb,cc,1);   
    }
}

> 这里的算法非常暴力,建衣服前后两面为集合(1,2),(1,3),(2,3),(1,1),(2,2),(3,3)共6个堆,然后就可以暴力乱弹,对每个询问比一下大小弹个堆即可。其实是可以用三个优先队列,维护一下有没有被取过来解决的,但复杂度没我这个优。

把 ABAP writable CDS view entity 讲透:从只读建模到可写模型的 ABAP CDS 新能力 摘要:SAP引入的writable CDS view entity突破了传统CDS视图只读的限制,允许通过ABAP SQL直接进行数据修改。该特性通过WRITABLE关键字定义,使CDS视图成为与数据库表同等级别的可写对象。其核心价值在于为数据集成、中间层同步等场景提供结构化写入入口,但需注意不应绕过业务规则。最佳实践建议保持底层表结构简单映射,避免复杂变形。这一特性标志着CDS从单纯消费模型向双向数据交互能力的演进,为ABAP开发提供了新的数据边界设计思路。 阅读详情

相关推荐

别再乱改grub.cfg了!手把手教你用GRUB2自定义多系统启动菜单(含UEFI/BIOS双模式配置)

本文详细介绍了如何安全、高效地使用GRUB2自定义多系统启动菜单,涵盖UEFI/BIOS双模式配置。通过避免直接编辑grub.cfg文件,采用正确的配置方法和命令,帮助用户打造稳定且美观的启动环境,特别适合Linux多系统用户和开发者。

weixin_42553471的博客 598

Codeforces Round #413 Div. 1 + Div. 2 B. T-shirt buying

Codeforces Round #413 Div. 1 + Div. 2 B. T-shirt buying B. T-shirt buying time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard output A new pack of n

心随我动 668

Qt Tab Widget 实战:如何打造一个可动态增删的标签页管理器(附完整代码)

本文深入探讨了使用Qt框架中的Tab Widget控件构建动态标签页管理器的实战方法。通过分析动态增删的核心挑战,提供了完整的C++代码示例,涵盖信号槽机制、页面生命周期管理、上下文菜单实现以及状态持久化等关键功能,帮助开发者打造高效、用户友好的桌面应用界面。

bb456的博客 1052

【CF799B】T-shirt buying(一道很水的小根堆)

点此看题面 大致题意:有n件T恤衫,告诉你每件T恤衫的价格以及它正面和反面的颜色(1≤颜色的编号≤3),现在有m个顾客,已知每个人想要的衣服的颜色(一件T恤衫只要有一面的颜色满足他的需求即可),请你求出每个人所需支付的最低价格(一件T恤衫只能被买一次)。 由于这道题的颜色最多只有3种,因此,我们只要开3个小根堆来存储每种颜色的衣服的价格和编号(价格为第一关键字)即可。 由于每件衣服只能被买一...

CXR的博客 830

Redis 可视化工具 RedisInsight 的保姆级安装以及使用(最新)

Redis 可视化工具 RedisInsight 的保姆级安装以及使用(最新)

一名全栈小白的博客 1万+

python点云可视化

Python三种点云可视化方案:mayavi、matplotlib、CloudCompare。

叶子的博客 1万+

蓝桥杯 buying sets求闭合子图最小,最大权

题目: 给定n个集合, 要求选出其中某些集合, 使得这些集合的并集的势, 等于选出的集合的数目.对于任意的k(1<=k<=n), 满从中选出任意k个集合, 这k个集合的并集的势一定大于等于k.每个集合有一个权值, 每个选择方案的代价是所选的集合的权值的和.请输出代价最小的选择方案的代价.当然, 不选择任何一个集合是一个可行的方案(权值和为0), 但不一定最优(权值和可以为负). ...

qq_40678690的博客 1090

自动驾驶算法-滤波器系列(三)——不同运动模型(CV、CA、CTRV、CTRA)的建模和推导

CV & CA & CTRV & CTRA1. CV模型2. CA模型3. CTRV模型4. CTRA模型 1. CV模型 2. CA模型 3. CTRV模型 4. CTRA模型

weixin_41480034的博客 2万+

CodeForces - 103E Buying Sets(最小权闭合子图)

题目链接:点击查看 题目大意:给出n个数列集合,每个集合都有一个权值,现在要求从中选出k个集合(k可以为0),要求满足: 权值和最小 k个集合取并集后的集合大小等于k 题目要求输出最小权值和 题目分析:如果直接去分析还是比较难想的,不过我们可以从条件出发,因为题目需要让最后的匹配结果满足k个集合和k个数字匹配,也就是满足了一种二分图的完备匹配,我们不妨从这里入手,先用匈牙利跑出其完备匹配,...

Falcon的博客 981

微信公众号 - 最新详细实现H5网页接入微信支付功能,开发移动端、PC端网站集成使用微信支付流程及示例代码,公众号网页利用JS-SDK/JSAPI/H5支付授权唤起微信支付,可脱离微信环境支付或内置浏

微信公众号,微信支付,网页,移动端,h5,扫码支付,二维码付款,手机网页,电脑pc网页生成支付二维码,js-sdk,jsapi,外部浏览器调起微信支付,脱离微信环境,在微信内置浏览器如何进行微信支付,前端H5微信支付,web网站,vue2,vue3,nuxt2,nuxt3,jquery,微信公众号h5支付流程,如何实现,怎么做,回调报错,redirect_uri参数错误,必须部署才能调试吗,怎么不打包发布就能在本机测试,微信H5支付能力,uniapp微信支付,h5页面调起支付,支付没反应,无效,失败,H5页

🏆 前端领域优质创作者 6111

YOLO26涨点改进 | 全网首发Conv独家改进篇 | CVPR 2025 | YOLO26引入FDConv频率动态卷积改进,含FDC3k2二次创新,小目标检测,能够捕捉更加丰富和复杂的特征信息

本文提出了一种频率动态卷积(FDConv)模块,用于改进YOLO26目标检测模型的性能。FDConv通过在傅里叶域内划分参数预算,构建具有频率多样性的权重,有效提升了模型对低频和高频信息的处理能力。该模块包含内核空间调制(KSM)和频率带调制(FBM)两个关键组件,分别实现空间级和频域级的动态调节。实验表明,FDConv仅增加3.6M参数就能超越其他需要大幅增加参数的方法,并在目标检测、实例分割等任务中表现优异。文章详细介绍了FDConv的原理、实现方法及在YOLO26中的集成方式,提供了完整的代码实现。

Ai缝合怪、助力小伙伴高效发论文 255

T-shirt buying(set顺序查找)

题目链接:http://codeforces.com/problemset/problem/799/BB. T-shirt buyingtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA new pack of n t-shirts came ...

永远鲜红の幼月的博客 396

PyTorch生成式人工智能(3)——使用PyTorch构建神经网络

在本节中,我们使用 PyTorch 在简单数据集上构建了一个神经网络,训练神经网络来映射输入和输出,并通过执行反向传播来更新权重值以最小化损失值,并利用 Sequential 类简化网络构建过程;介绍了获取网络中间值的常用方法,以及如何使用 save、load 方法保存和加载模型,以避免再次训练模型。

盼小辉丶的博客 1万+

E - T-shirt buying

A new pack of n t-shirts came to a shop. Each of the t-shirts is characterized by three integers pi, ai and bi, where pi is the price of the i-th t-shirt, ai is front color of the i-th t-shirt and bi i

海绵的博客 857

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

Codeforces Round #413 B. T-shirt buying

A new pack of n t-shirts came to a shop. Each of the t-shirts is characterized by three integers pip_i, aia_i and bib_i, where pip_i is the price of the i-th t-shirt, aia_i is front color of the i-th t

DorMOUSENone的博客 929

贝叶斯统计 [韦来生编]

贝叶斯(Bayes)统计是近几十年来迅速发展起来的数理统计的一个重要分支。贝叶斯方法与经典统计方法的主要不同之处是进行统计推断时除了利用样本信息外,还要利用参数的先验信息,因此可以提高统计推断或统计决策的效果。它在经济、金融、生物、医学、自然科学和社会科学等许多领域具有广泛的应用。贝叶斯方法的研究已渗透到了统计学的几乎所有领域。作者在给中国科学技术大学概率论与数理统计专业本科生开设的“数理统计”课程中有一章专门讲授“贝叶斯方法和统计决策理论”,近十年来也给中国科学技术大学概率统计专业研究生开设过几次“贝叶斯分析”课。本书是在对过去讲稿的内容作了适当的增减和调整的基础上完成的。  本书共分六章。第1章是绪论,介绍了贝叶斯统计的若干基本概念,同时对必要的数理统计的基础知识有重点地作了回顾。第二章介绍了确定先验分布的若干可供选择的方法。第三章介绍了几类常见统计模型参数的后验分布的主要结果和计算方法。第四章和第五章分别介绍了“贝叶斯统计推断”和“贝叶斯统计决策”的内容。第六章介绍了贝叶斯统计计算的若干方法,包括蒙特卡洛方法和马尔可夫链蒙特卡洛(MCMC)方法以及相关统计软件的简介。本书的每一章附右大量的例题和习题,书末附有常用的几个表格和部分习题解答供读者查用。  大约可在54学时内讲授本书的第1章至第六章的主要内容,教师可根据学时需要选讲本书第1章至第六章的部分内容。书中标“*”号的章节可略去不讲,留给读者作为阅读材料。第六章例题中的R代码和部分例题的数据文件等可从作者个人主页下载。  作者在编写本书的过程中参考了J.O.Berger教授的《统计决策论及贝叶斯分析》和茆诗松教授编写的《贝叶斯统计》等书中的一些内容,以及《贝叶斯分析》一书中由张伟平博士编写的有关贝叶斯统计计算的一些内容。在此表示衷心感谢。  本书编写准备过程中,中国科学技术大学统计与金融系的几个研究生帮助完成了本书部分中文的录入和排版,作者对他们的辛勤工作表示真诚的感谢。高等教育出版社为本书的出版给予了大力支持。在此一并致谢。

T-shirt buying Codeforce 贪心

B. T-shirt buying time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output A new pack of n t-shirts came to a shop.

GDUFE_SSS 922

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

CodeForces - 799B T-shirt buying(思维,,优先队列!!)

T-shirt buying A new pack of n t-shirts came to a shop. Each of the t-shirts is characterized by three integers pi, ai and bi, where pi is the price of the i-th t-shirt, ai is front color of the i-th...

Error Man 的博客 402

CF - 799B. T-shirt buying - STL的set应用

1.题目描述: B. T-shirt buying time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output A new pack of n t-shirts cam

终有绿洲摇曳在沙漠 426

优先队列实现成员的增减

B. T-shirt buying time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output A new pack of n t-shirts came to a shop.

Accepted ALL lve 564

Educational Codeforces Round 46 (Rated for Div. 2) A Codehorses T-shirts

A. Codehorses T-shirtstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputCodehorses has just hosted the second Codehorses Cup. This year, the same as...

Ant_e_zz的博客 790

CodeForces - 799B T-shirt buying

B. T-shirt buying time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard output A new pack of n t-shirts came to a shop. Each of the t-shirts is characterized by three integers pi, ai and bi, where pi is the pric

海岛Blog 699

CodeForce-799B T-shirt buying (STL_set)

有 n 件T恤。第 i 件T恤的价格为 pi 。每个T恤有两面,第 i 件T恤正面颜色为 ai ,反面颜色为 bi 。 有 m 个人想买T恤,每个人都恰好买一件。第 j 个人最喜欢颜色 cj。 一个人会选择买一件至少有一面颜色为他喜欢的颜色的,最便宜的T恤。如果没有合法的T恤,则不买。这些人按照给定的顺序来购买。 你的任务是求出每个人会花多少钱。 Input 第...

236

c++优先队列(priority_queue)

包含头文件#include <queue>, 他和queue不同的就在于我们可以自定义其中数据的优先级, 让优先级高的排在队列前面,优先出队 优先队列具有队列的所有特性,包括基本操作,只是在这基础上添加了内部的一个排序,它本质是一个堆实现的 和队列基本操作相同: top 访问队头元素 empty 队列是否为空 size 返回队列内元素个数 push 插入元素到队尾 (并排序) emplace 原地构造一个元素并插入队列 pop 弹出队头元素 定义:priority_queue<Ty.

weixin_42438346的博客 250

Codeforces 799B - T-shirt buying

cf 一般都在晚上,这一场没做,听同学说这个题很迷,来了兴趣,就做了一下 开始想用set ,但感觉好恶心的,不易实现,细思之下想到了好的办法,算是 “贪心” 了一下 运用 queue 先进先出 结合 结构体,嗯,不错 这种顺序问题,最好寻找一种规律,想到了 会很简单;整个代码我也就敲了20分钟吧,前面思考的过程耗时间 #include #include #include #include

床前明月光 458

Codeforces - Buying Sets

题目链接:Codeforces - Buying Sets 如果不考虑 k 的限制,那么就是一个最小权闭合子图。 然后现在需要相等,所以我们给集合一个正的权值,元素一个负的权值,保证可以相等。 AC代码: #pragma GCC optimize("-Ofast","-funroll-all-loops") #include<bits/stdc++.h> #define int long long using namespace std; const int inf=0x3f3f3f3f3f

青烟绕指柔的博客 508

T-shirt buying

T-shirt buying 优先队列

m0_63683383的博客 440
上一篇: codeforcesPlayrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2)A题
下一篇: CodeforcesPlayrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2)C题C. Fountains
Timsei
博客等级 码龄10年 344粉丝 159原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值