CodeForces - 1353D Constructing the Array
CodeForces - 1353D
这道题也可能比较简单,主要是要想到优先队列要怎么使用,这一点如果用递归会写不了
但是因为对优先队列不太熟悉,只有被提示可以用优先队列才想到要怎么用,
还是很重要的STL
注意运算符的重构应该反着来写
其他的思维很朴素,运算符的重构就是,先比较长度,优先用长度长的,如果一样就是选择左边界小的,用结构体封装数据即可
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
int a[200005]={0};
int cnt=0;
struct Node{
int l;int r;int val;
};
bool operator<(Node a,Node b){
if(a.val==b.val) return a.l>b.l;
return a.val<b.val;
}
priority_queue<Node> q;
void solve(){
while(!q.empty()){
Node x=q.top();
q.pop();
if(x.val==1){
a[x.l]=++cnt;
continue;
}
int mid=(x.l+x.r)>>1;
a[mid]=++cnt;
Node aa;
aa.l=x.l;
aa.r=mid-1;
aa.val=aa.r-aa.l+1;
if(aa.val>0) q.push(aa);
Node bb;
bb.l=mid+1;
bb.r=x.r;
bb.val=bb.r-bb.l+1;
if(bb.val>0) q.push(bb);
}
}
signed main(){
int time;
cin>>time;
while(time--){
int n;
cnt=0;
cin>>n;
Node u;
u.l=1;u.r=n;u.val=n;
q.push(u);
solve();
for(int i=1;i<=n;++i){
cout<<a[i]<<" ";
}
cout<<endl;
}
}
CodeForces - 1353D Constructing the Array的更多相关文章
- Codeforces 442C Artem and Array(stack+贪婪)
题目连接:Codeforces 442C Artem and Array 题目大意:给出一个数组,每次删除一个数.删除一个数的得分为两边数的最小值,假设左右有一边不存在则算作0分. 问最大得分是多少. ...
- Codeforces Round #504 D. Array Restoration
Codeforces Round #504 D. Array Restoration 题目描述:有一个长度为\(n\)的序列\(a\),有\(q\)次操作,第\(i\)次选择一个区间,将区间里的数全部 ...
- Codeforces Round #642 (Div. 3) D. Constructing the Array (优先队列)
题意:有一个长度为\(n\)元素均为\(0\)的序列,进行\(n\)次操作构造出一个新序列\(a\):每次选择最长的连续为\(0\)的区间\([l,r]\),使得第\(i\)次操作时,\(a[\fra ...
- Educational Codeforces Round 21 D.Array Division(二分)
D. Array Division time limit per test:2 seconds memory limit per test:256 megabytes input:standard i ...
- Codeforces 754A Lesha and array splitting(简单贪心)
A. Lesha and array splitting time limit per test:2 seconds memory limit per test:256 megabytes input ...
- Codeforces 408 E. Curious Array
$ >Codeforces \space 408 E. Curious Array<$ 题目大意 : 有一个长度为 \(n\) 的序列 \(a\) ,\(m\) 次操作,每一次操作给出 \ ...
- Educational Codeforces Round 11A. Co-prime Array 数学
地址:http://codeforces.com/contest/660/problem/A 题目: A. Co-prime Array time limit per test 1 second me ...
- Codeforces 946G Almost Increasing Array (树状数组优化DP)
题目链接 Educational Codeforces Round 39 Problem G 题意 给定一个序列,求把他变成Almost Increasing Array需要改变的最小元素个数. ...
- CodeForces - 86D D. Powerful array —— 莫队算法
题目链接:http://codeforces.com/problemset/problem/86/D D. Powerful array time limit per test 5 seconds m ...
- 【Codeforces 722C】Destroying Array (数据结构、set)
题意 输入一个含有 n(1≤n≤100000) 个非负整数的 a 数组和一个 1-n 的排列 p 数组,求每次删除 a[p[i]] 后,最大连续子段和(不能跨越被删除的)是多少? 分析 因为都是非负整 ...
随机推荐
- 使用命令行 Windows 修改文件权限
修改文件访问权限的命令行工具是 icacls,其使用语法是这样的: icacls <file> # 查看文件的访问权限 icacls <file> /grant <SID ...
- 阿里云CTF and 其他
RE复现 login_system 这个函数就是判断username,点进去发现是线性方程,用z3解 from z3 import * s=Solver() a=[0]*16 for i in ran ...
- [Udemy] AWS Certified Data Analytics Specialty - 2.Storage
S3 Replication (CRR & SRR) S3 Encryption S3 Security 其中两个ACL基本不会考 记住这3个event发送的target DynamoDB D ...
- sicp每日一题[1.41]
Exercise 1.41 Define a procedure double that takes a procedure of one argument as argument and retur ...
- 录音转文字SDK哪家强?
最近在做一款录音App,有一个模块是录音转文字功能,于是对比了市面上常见的API,国内做的比较大的主要有讯飞.腾讯.阿里.百度.华为. 讯飞 讯飞在国内做语音SDK是做的比较早的,翻译出来的准确率挺不 ...
- 音视频 SDK |合理配置视频参数,提升使用质量
一.前言 在视频通话或直播时,开发者可以根据需要指定推流和拉流视频相关配置,如视频采集分辨率.视频编码输出分辨率.视频帧率.码率.视图模式和镜像模式. 设置合适的视频分辨率.帧率和码率可以在音视频场景 ...
- 火山引擎数智平台:高性能ChatBI的技术解读和落地实践
导读:大模型能力的发展和成熟,催生出新一代智能化 BI-- ChatBI,即通过自然语言处理(NLP)与大型语言模型(LLMs)的结合,极大简化数据分析过程,提高效率并降低分析门槛.火山引擎数智平台旗 ...
- 祝福 Eric 的下一段旅程,Flutter 3.3 现已发布
Flutter 团队及社区成员们在美丽的城市挪威奥斯陆向您发来问候,我们正在此参加社区举办的 Flutter Vikings 活动,这是一个为期两天的开发技术交流盛会,虽然线下门票已经售罄,但您还可以 ...
- 深入理解 Nuxt.js 中的 app:created 钩子
title: 深入理解 Nuxt 中的 app created 钩子 date: 2024/9/26 updated: 2024/9/26 author: cmdragon excerpt: 摘要:本 ...
- 4Templates Bootstrap Navbars and Links
链接 传递参数