【CF549F】Yura and Developers

题目大意

给出一个长度为n的序列A。问有多少对(l,r)满足
ri=lAimaxri=lAi=0(modm)


分析

大致上就是求有多少个区间去掉最大值后元素总和是m的倍数。

考虑分治。
将区间劈开两部分,然后分开左右递归。重点是中间怎么做。

我一开始只想到了把左边用桶存起前缀和,然后右边用指针移动统计答案。但是这么做很难处理去掉最大值的问题。
实际上两个都作为指针移动也是可以的。处理完一边移动另外一边只是一种特殊情况。
也就是说初始下设l=midr=mid
每一步移动lr时,考虑[l,midr][lmid,r]对答案的贡献。
这道题里面移动lr也是有技巧的。我们需要移动最大值较小者位于的方向。因为这样才能够保证每个区间和它们要减去的最大值一一对应。否则就会出现移动lr时,最大值不是当前的lmaxrmax

于是这道题就在O(nlogn)的时间复杂度内解决了。


Debug logs

11676027 Jun/20/2015 04:16 Wrong answer on test 13
debug : 答案没开long long
11676030 Jun/20/2015 04:17 Accepted

Sure, I can help you create a simple Node.js script to perform a single-ping check with a timeout of 100 milliseconds on IP addresses within the 192.168.19.0/24 subnet. Here's an example using the `net` and `child_process` modules: ```javascript const net = require('net'); const { exec } = require('child_process'); // Define the target subnet and timeout const subnet = '192.168.19.'; const timeoutMs = 100; function pingHost(ip) { const cmd = `ping -c 1 -w ${timeoutMs} ${ip}`; return new Promise((resolve, reject) => { exec(cmd, (error, stdout, stderr) => { if (error) { console.log(`Failed to ping ${ip}:`, error); reject(error); } else { // Check if ping was successful (no "Request timed out" in output) if (!stdout.includes('Request timed out')) { resolve(true); // Ping succeeded } else { resolve(false); // Ping timed out } } }); }); } async function scanSubnet() { try { for (let i = 1; i <= 254; i++) { const address = `${subnet}${i}`; await pingHost(address); } } catch (error) { console.error('Error scanning subnet:', error); } } scanSubnet(); ``` This script defines a function `pingHost` that sends a single ping command with a given timeout and checks if it succeeds or times out. The `scanSubnet` function iterates through all possible IP addresses in the 192.168.19.0/24 range and calls `pingHost` for each one. Keep in mind that this script assumes you have a Unix-like system with `ping` utility installed. If your environment is different, you might need to adjust the command accordingly.
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值