Laying Cables (单调栈)

本文介绍了一维国家的互联网部署难题,通过计算找出每个城市的父节点,即拥有更大人口且距离最近的上级城市。算法实例展示了如何确定城市间电缆布局,优化网络覆盖,提升国家通信效率。

One-dimensional country has n cities, the i-th of which is located at the point xi and has population pi, and all xi, as well as all pi, are distinct. When one-dimensional country got the Internet, it was decided to place the main server in the largest city, and to connect any other city j to the city k that has bigger population than j and is the closest to it (if there are many such cities, the largest one should be chosen). City k is called a parent of city j in this case.

Unfortunately, the Ministry of Communications got stuck in determining from where and to where the Internet cables should be laid, and the population of the country is suffering. So you should solve the problem. For every city, find its parent city.

Input
The first line contains a single integer n (1 ≤ n ≤ 200000) — the number of cities.

Each of the next n lines contains two space-separated integers xi and pi (1 ≤ xi,  pi ≤ 109) — the coordinate and the population of the i-th city.

Output
Output n space-separated integers. The i-th number should be the parent of the i-th city, or  - 1, if the i-th city doesn’t have a parent. The cities are numbered from 1 by their order in the input.

Examples
Input
4
1 1000
7 10
9 1
12 100
Output
-1 4 2 1
Input
3
1 100
2 1
3 10
Output
-1 1 1
Input
3
1 10
3 100
2 1
Output
2 -1 2

#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
struct node {
    int x, sum, id;
} s[N];
int cmp(node a, node b) { return a.x < b.x; }
int n, ans[N];
node a[N];
int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d%d", &s[i].x, &s[i].sum);
        s[i].id = i;
    }
    sort(s + 1, s + 1 + n, cmp);
    int cnt = 0;
    for (int i = 1; i <= n; i++) {
        if (cnt == 0)
            a[++cnt] = s[i];
        else {
            while (s[i].sum > a[cnt].sum && cnt >= 1) {
                if (cnt == 1)
                    ans[a[cnt].id] = s[i].id;
                else {
                    if (a[cnt].x - a[cnt - 1].x == s[i].x - a[cnt].x) {
                        if (a[cnt - 1].sum > s[i].sum)
                            ans[a[cnt].id] = a[cnt - 1].id;
                        else
                            ans[a[cnt].id] = s[i].id;
                    } else if (a[cnt].x - a[cnt - 1].x < s[i].x - a[cnt].x) {
                        ans[a[cnt].id] = a[cnt - 1].id;
                    } else
                        ans[a[cnt].id] = s[i].id;
                }
                cnt--;
            }
            a[++cnt] = s[i];
        }
    }
    for (int i = cnt; i >= 2; i--) {
        ans[a[i].id] = a[i - 1].id;
    }
    ans[a[1].id] = -1;
    for (int i = 1; i <= n; i++) {
        if (i == n)
            printf("%d\n", ans[i]);
        else
            printf("%d ", ans[i]);
    }
}
【SCI复现】含可再生能源与储能的区域微电网最优运行:应对不确定性的解鲁棒性与非预见性研究(Matlab代码实现)内容概要:本文围绕含可再生能源与储能的区域微电网最优运行展开研究,重点探讨应对不确定性的解鲁棒性与非预见性策略,通过Matlab代码实现SCI论文复现。研究涵盖多阶段鲁棒调度模型、机会约束规划、需求响应机制及储能系统优化配置,结合风电、光伏等可再生能源出力的不确定性建模,提出兼顾系统经济性与鲁棒性的优化运行方案。文中详细展示了模型构建、算法设计(如C&CG算法、大M法)及仿真验证全过程,适用于微电网能量管理、电力系统优化调度等领域的科研与工程实践。; 适合人群:具备一定电力系统、优化理论和Matlab编程基础的研究生、科研人员及从事微电网、能源管理相关工作的工程技术人员。; 使用场景及目标:①复现SCI级微电网鲁棒优化研究成果,掌握应对风光负荷不确定性的建模与求解方法;②深入理解两阶段鲁棒优化、分布鲁棒优化、机会约束规划等先进优化方法在能源系统中的实际应用;③为撰写高水平学术论文或开展相关课题研究提供代码参考和技术支持。; 阅读建议:建议读者结合文档提供的Matlab代码逐模块学习,重点关注不确定性建模、鲁棒优化模型构建与求解流程,并尝试在不同场景下调试与扩展代码,以深化对微电网优化运行机制的理解。
个人防护装备实例分割数据集 一、基础信息 数据集名称:个人防护装备实例分割数据集 图片数量: 训练集:4,524张图片 分类类别: - Gloves(手套):工作人员佩戴的手部防护装备。 - Helmet(安全帽):头部防护装备。 - No-Gloves(未戴手套):未佩戴手部防护的状态。 - No-Helmet(未戴安全帽):未佩戴头部防护的状态。 - No-Shoes(未穿安全鞋):未佩戴足部防护的状态。 - No-Vest(未穿安全背心):未佩戴身体防护的状态。 - Shoes(安全鞋):足部防护装备。 - Vest(安全背心):身体防护装备。 标注格式:YOLO格式,包含实例分割的多边形坐标和类别标签,适用于实例分割任务。 数据格式:来源于实际场景图像,适用于计算机视觉模型训练。 二、适用场景 工作场所安全监控系统开发:数据集支持实例分割任务,帮助构建能够自动识别工作人员个人防护装备穿戴状态的AI模型,提升工作环境安全性。 建筑与工业安全检查:集成至监控系统,实时检测PPE穿戴情况,预防安全事故,确保合规性。 学术研究与创新:支持计算机视觉在职业安全领域的应用研究,促进AI与安全工程的结合。 培训与教育:可用于安全培训课程,演示PPE识别技术,增强员工安全意识。 三、数据集优势 精准标注与多样性:每个实例均用多边形精确标注,确保分割边界准确;覆盖多种PPE物品及未穿戴状态,增加模型鲁棒性。 场景丰富:数据来源于多样环境,提升模型在不同场景下的泛化能力。 任务适配性强:标注兼容主流深度学习框架(如YOLO),可直接用于实例分割模型开发,支持目标检测和分割任务。 实用价值高:专注于工作场所安全,为自动化的PPE检测提供可靠数据支撑,有助于减少工伤事故。
io-3.35 Starting 8 processes randread: Laying out IO file (1 file / 10240MiB) randread: Laying out IO file (1 file / 10240MiB) randread: Laying out IO file (1 file / 10240MiB) fio: ENOSPC on laying out file, stopping fio: pid=0, err=28/file:filesetup.c:240, func=write, error=No space left on device randread: Laying out IO file (1 file / 10240MiB) fio: pid=0, err=28/file:filesetup.c:174, func=open, error=No space left on device randwrite: Laying out IO file (1 file / 10240MiB) fio: pid=0, err=28/file:filesetup.c:174, func=open, error=No space left on device randwrite: Laying out IO file (1 file / 10240MiB) fio: pid=0, err=28/file:filesetup.c:174, func=open, error=No space left on device randwrite: Laying out IO file (1 file / 10240MiB) fio: pid=0, err=28/file:filesetup.c:174, func=open, error=No space left on device randwrite: Laying out IO file (1 file / 10240MiB) fio: pid=0, err=28/file:filesetup.c:174, func=open, error=No space left on device Jobs: 2 (f=2): [r(2),X(6)][100.0%][r=279KiB/s][r=69 IOPS][eta 00m:00s] randread: (groupid=0, jobs=1): err= 0: pid=4012: Wed Jul 16 22:21:23 2025 read: IOPS=36, BW=144KiB/s (148kB/s)(8668KiB/60032msec) slat (nsec): min=1960, max=423031k, avg=27609589.07, stdev=25336672.45 clat (msec): min=9, max=8015, avg=411.63, stdev=396.00 lat (msec): min=35, max=8015, avg=439.24, stdev=395.86 clat percentiles (msec): | 1.00th=[ 89], 5.00th=[ 262], 10.00th=[ 288], 20.00th=[ 309], | 30.00th=[ 330], 40.00th=[ 347], 50.00th=[ 359], 60.00th=[ 380], | 70.00th=[ 418], 80.00th=[ 468], 90.00th=[ 535], 95.00th=[ 625], | 99.00th=[ 768], 99.50th=[ 1921], 99.90th=[ 7684], 99.95th=[ 7752], | 99.99th=[ 8020] bw ( KiB/s): min= 24, max= 211, per=49.95%, avg=144.88, stdev=31.58, samples=114 iops : min= 6, max= 52, avg=35.96, stdev= 7.92, samples=114 lat (msec) : 10=0.05%, 20=0.14%, 50=0.37%, 100=0.65%, 250=2.86% lat (msec) : 500=81.50%, 750=13.15%, 1000=0.60%, 2000=0.23%, >=2000=0.46% cpu : usr=0.32%, sys=99.26%, ctx=735, majf=0, minf=26 IO depths : 1=0.1%, 2=0.1%, 4=0.2%, 8=0.4%, 16=99.3%, 32=0.0%, >=64=0.0% submit : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0% complete : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.1%, 32=0.0%, 64=0.0%, >=64=0.0% issued rwts: total=2167,0,0,0 short=0,0,0,0 dropped=0,0,0,0 latency : target=0, window=0, percentile=100.00%, depth=16 randread: (groupid=0, jobs=1): err= 0: pid=4013: Wed Jul 16 22:21:23 2025 read: IOPS=36, BW=144KiB/s (148kB/s)(8680KiB/60180msec) slat (nsec): min=1979, max=438546k, avg=27562216.01, stdev=25336850.71 clat (msec): min=6, max=8611, avg=411.96, stdev=584.57 lat (msec): min=33, max=8632, avg=439.52, stdev=583.69 clat percentiles (msec): | 1.00th=[ 128], 5.00th=[ 236], 10.00th=[ 257], 20.00th=[ 284], | 30.00th=[ 305], 40.00th=[ 321], 50.00th=[ 342], 60.00th=[ 368], | 70.00th=[ 393], 80.00th=[ 435], 90.00th=[ 502], 95.00th=[ 575], | 99.00th=[ 1636], 99.50th=[ 7013], 99.90th=[ 8423], 99.95th=[ 8490], | 99.99th=[ 8658] bw ( KiB/s): min= 32, max= 247, per=49.95%, avg=144.90, stdev=32.09, samples=115 iops : min= 8, max= 61, avg=36.01, stdev= 8.06, samples=115 lat (msec) : 10=0.09%, 20=0.05%, 50=0.37%, 100=0.28%, 250=7.00% lat (msec) : 500=81.94%, 750=8.39%, 1000=0.74%, 2000=0.32%, >=2000=0.83% cpu : usr=0.36%, sys=98.93%, ctx=813, majf=0, minf=27 IO depths : 1=0.1%, 2=0.1%, 4=0.2%, 8=0.4%, 16=99.3%, 32=0.0%, >=64=0.0% submit : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0% complete : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.1%, 32=0.0%, 64=0.0%, >=64=0.0% issued rwts: total=2170,0,0,0 short=0,0,0,0 dropped=0,0,0,0 latency : target=0, window=0, percentile=100.00%, depth=16 Run status group 0 (all jobs): READ: bw=288KiB/s (295kB/s), 144KiB/s-144KiB/s (148kB/s-148kB/s), io=16.9MiB (17.8MB), run=60032-60180msec Disk stats (read/write): dm-0: ios=4336/6, merge=0/0, ticks=469085/1169, in_queue=470254, util=100.00%, aggrios=4337/5, aggrmerge=0/1, aggrticks=477332/1114, aggrin_queue=478446, aggrutil=79.54% sda: ios=4337/5, merge=0/1, ticks=477332/1114, in_queue=478446, util=79.54%
07-17
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值