AMPPZ 2011 E Gophers

发现cf上竟然有这套题…
以及发现coach mode的提交不算在submission里面,奥妙重重
coach mode真香!D不想写,翻了翻其他人代码,收获一个看上去非常优雅的分数类板子。
这个E好像挺水的…
线段树区间合并的做法什么时候补一下吧(什么时候 等我学会线段树

题意

数轴上有一些住着人的洞窟,有一个人试图用m台CD机播放摇滚音乐来打扰洞窟里的住民。每台CD机可以影响的范围为l。CD机的主人会移动一台CD机。每次移动后,询问有多少个洞窟会受到音乐的影响。

解法

由于区间等长,把区间中点扔进set里,每次修改找前驱和后继查询一下受影响的点有几个,删点,查询一下修改后位置前驱后继看看受影响的点有几个,加点。维护答案。

#include <iostream>
#include <set>
#include <algorithm>

const int maxn = 500000+7;

int n, m, d, l;
int x[maxn];
std::set<int> z;
int p, r;
int zz;

int main(int argc, char *argv[]) {  
	std::ios::sync_with_stdio(false);
	std::cin.tie(0); 
	std::cin >> n >> m >> d >> l;
	x[1] = 0;
	for (int i = 2; i <= n; i++) {
		std::cin >> x[i];
	}
	for (int i = 0; i < m; i++) {
		std::cin >> zz;
		z.insert(zz);
	}
	z.insert(-1000000007);
	z.insert(2000000007);
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		auto it1 = z.lower_bound(x[i]);
		auto it2 = it1;
		it2--;
		if (std::abs(*it1-x[i]) <= l || std::abs(*it2-x[i]) <= l) {
			ans++;
		}
	}
	std::cout << ans << '\n';
	int left, right, ll, rr;
	for (int i = 0; i < d; i++) {
		std::cin >> p >> r;
		auto it1 = z.lower_bound(p);
		auto it2 = it1;
		it1++;
		it2--;
		left = std::max(*it2+l+1, p-l);
		right = std::min(*it1-l-1, p+l);
		ll = std::lower_bound(x+1, x+n+1, left)-(x+1);
		rr = std::lower_bound(x+1, x+n+1, right+1)-(x+1);
		ans -= std::max(0, rr-ll);
		z.erase(p);
		auto it3 = z.lower_bound(r);
		auto it4 = it3;
		it4--;
		left = std::max(*it4+l+1, r-l);
		right = std::min(*it3-l-1, r+l);
		ll = std::lower_bound(x+1, x+n+1, left)-(x+1);
		rr = std::lower_bound(x+1, x+n+1, right+1)-(x+1);
		ans += std::max(0, rr-ll);
		std::cout << ans << '\n';
		z.insert(r);
	}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
移植curl但是zlib无法使能,如何解决该问题 Host setup: arm-unknown-linux-gnueabihf Install prefix: /opt/rootfs/curl-7.79.0/curl-7.79.0/_install Compiler: arm-linux-gnueabihf-gcc CFLAGS: -Werror-implicit-function-declaration -O2 -Wno-system-headers -pthread CPPFLAGS: -isystem /opt/rootfs/openssl-1.1.1/openssl-1.1.1/_install/include LDFLAGS: -L/opt/rootfs/openssl-1.1.1/openssl-1.1.1/_install/lib LIBS: -lssl -lcrypto -ldl -lpthread curl version: 7.79.0 SSL: enabled (OpenSSL) SSH: no (--with-{libssh,libssh2}) zlib: no (--with-zlib) brotli: no (--with-brotli) zstd: no (--with-zstd) GSS-API: no (--with-gssapi) GSASL: no (libgsasl not found) TLS-SRP: enabled resolver: POSIX threaded IPv6: enabled Unix sockets: enabled IDN: no (--with-{libidn2,winidn}) Build libcurl: Shared=yes, Static=yes Built-in manual: enabled --libcurl option: enabled (--disable-libcurl-option) Verbose errors: enabled (--disable-verbose) Code coverage: disabled SSPI: no (--enable-sspi) ca cert bundle: no ca cert path: no ca fallback: no LDAP: no (--enable-ldap / --with-ldap-lib / --with-lber-lib) LDAPS: no (--enable-ldaps) RTSP: enabled RTMP: no (--with-librtmp) PSL: no (libpsl not found) Alt-svc: enabled (--disable-alt-svc) HSTS: enabled (--disable-hsts) HTTP1: enabled (internal) HTTP2: no (--with-nghttp2, --with-hyper) HTTP3: no (--with-ngtcp2, --with-quiche) ECH: no (--enable-ech) Protocols: DICT FILE FTP FTPS GOPHER GOPHERS HTTP HTTPS IMAP IMAPS MQTT POP3 POP3S RTSP SMB SMBS SMTP SMTPS TELNET TFTP Features: AsynchDNS HSTS HTTPS-proxy IPv6 Largefile NTLM NTLM_WB SSL TLS-SRP UnixSockets alt-svc
06-13

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值