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的更多相关文章

  1. Codeforces 442C Artem and Array(stack+贪婪)

    题目连接:Codeforces 442C Artem and Array 题目大意:给出一个数组,每次删除一个数.删除一个数的得分为两边数的最小值,假设左右有一边不存在则算作0分. 问最大得分是多少. ...

  2. Codeforces Round #504 D. Array Restoration

    Codeforces Round #504 D. Array Restoration 题目描述:有一个长度为\(n\)的序列\(a\),有\(q\)次操作,第\(i\)次选择一个区间,将区间里的数全部 ...

  3. Codeforces Round #642 (Div. 3) D. Constructing the Array (优先队列)

    题意:有一个长度为\(n\)元素均为\(0\)的序列,进行\(n\)次操作构造出一个新序列\(a\):每次选择最长的连续为\(0\)的区间\([l,r]\),使得第\(i\)次操作时,\(a[\fra ...

  4. 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 ...

  5. Codeforces 754A Lesha and array splitting(简单贪心)

    A. Lesha and array splitting time limit per test:2 seconds memory limit per test:256 megabytes input ...

  6. Codeforces 408 E. Curious Array

    $ >Codeforces \space 408 E. Curious Array<$ 题目大意 : 有一个长度为 \(n\) 的序列 \(a\) ,\(m\) 次操作,每一次操作给出 \ ...

  7. 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 ...

  8. Codeforces 946G Almost Increasing Array (树状数组优化DP)

    题目链接   Educational Codeforces Round 39 Problem G 题意  给定一个序列,求把他变成Almost Increasing Array需要改变的最小元素个数. ...

  9. CodeForces - 86D D. Powerful array —— 莫队算法

    题目链接:http://codeforces.com/problemset/problem/86/D D. Powerful array time limit per test 5 seconds m ...

  10. 【Codeforces 722C】Destroying Array (数据结构、set)

    题意 输入一个含有 n(1≤n≤100000) 个非负整数的 a 数组和一个 1-n 的排列 p 数组,求每次删除 a[p[i]] 后,最大连续子段和(不能跨越被删除的)是多少? 分析 因为都是非负整 ...

随机推荐

  1. Python 潮流周刊#67:uv 的重磅更新(摘要)

    本周刊由 Python猫 出品,精心筛选国内外的 250+ 信息源,为你挑选最值得分享的文章.教程.开源项目.软件工具.播客和视频.热门话题等内容.愿景:帮助所有读者精进 Python 技术,并增长职 ...

  2. mysql 和 sqlalchemy 的一个测试环境

    Mysql: docker run -itd --name mysql-test -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysqldocker exec ...

  3. 『读书笔记』你不知道的JavaScript(上)

    前言 文章只记录理解以及容易遗忘的知识点. 词法作用域.块作用域 词法作用域 词法作用域:简单的说,词法作用域就是定义在词法阶段的作用域.换句话说,词法作用域就是在你写代码时将变量和块作用域写在哪里来 ...

  4. laravel框架中上传图片,并在本地显示

    1 //处理文件上传 2 if ($request->hasFile('image')&&$request->file('image')->isValid()){ 3 ...

  5. SQL数据库书的配套资源

    <SQL基础教程(视频教学版)>代码.课件.教学视频 https://pan.baidu.com/s/1QA5m5HN159wi3FX_KNDQzA 提取码: 4m9e <SQL S ...

  6. Thinkphp原生验证码的使用

    Thinkphp原生验证码的使用 一. 获取验证码 public function verifyCode(){ $captcha = new \think\captcha\Captcha(); $ca ...

  7. CF1661 Educational Codeforces Round 126 (Rated for Div. 2) 题解

    感觉,越来越拉胯了,有点难过,明天希望可以好好学习,好好准备考研!八成新的自己我来力! A Array Balancing 很明显的签到题,要求两个数组各自的相邻项差的绝对值最小,设\(mn=\min ...

  8. 基于 Nginx 的大型互联网集群架构与实战方案

    1. Nginx 负载均衡基础配置 首先,搭建一个基础的 Nginx 负载均衡器,用于将流量分发到多个后端服务器上. 步骤 1.1:安装 Nginx 在每台要作为负载均衡器的服务器上,安装 Nginx ...

  9. url 统一资源定位符的组成

    协议 protocol :http 或者 https = http + ssl  或者 file 文件(本地): 域名 host 或 ip 地址: 端口 port 省略默认 80  : 路径 path ...

  10. 7-11 leetcode 2612

    请你编写一个异步函数,它接收一个正整数参数 millis ,并休眠这么多毫秒.要求此函数可以解析任何值. ps: promise 期约函数 (异步函数)的使用 ,promise 是一个对象  new ...