NOIP2011 D2 T2 聪明的质检员
2017-12-23 17:39
267 查看
这题目有毒
花了一个下午在这水(shen)题上,最后才看见0
< S≤10^12。
题目不难:
二分无限逼近答案+前缀和
#include<cstdio> #include<cstring> #include<cstdlib> #include<algorithm> #include<iostream> #include<cmath> #pragma warning(disable:4996) using namespace std; #define MAXN 200009 #define LL long long LL n , m ; LL S; struct _ { LL val , wei; }a[MAXN]; struct __ { int l , r; }b[MAXN]; LL c[MAXN];//前缀和数组 LL d[MAXN];//前缀和,w[j]>W个数 LL L , R , cnt; void count(LL L, LL R) { if (L == R) return; LL mid = (L + R) >> 1; memset(c , 0 , sizeof(c)); memset(d , 0 , sizeof(d)); for (int i = 1; i <= n; i++) { if (a[i].wei >= mid) { c[i] = c[i - 1] + a[i].val; d[i] = d[i - 1] + 1; } else { c[i] = c[i - 1]; d[i] = d[i - 1]; } } LL ans = 0; for (int i = 1; i <= m; i++) { ans += ((c[b[i].r] - c[b[i].l - 1])*(d[b[i].r] - d[b[i].l - 1])); } if (abs(S - ans) < abs(S - cnt)) cnt = ans; if (S > ans) count(L , mid); if (S == ans) { cnt = ans; return; } if (S < ans) count(mid + 1 , R); } int main() { scanf("%lld%lld%lld" , &n , &m , &S); for (int i = 1; i <= n; i++) { scanf("%lld%lld" , &a[i].wei , &a[i].val); } for (int i = 1; i <= m; i++) scanf("%lld%lld" , &b[i].l , &b[i].r); count(1 , 100000); printf("%lld\n" , abs(cnt - S)); return 0; }无视#pragma
那句
相关文章推荐
- P1314 聪明的质检员NOIP 2011T2
- [NOIP2011]聪明的质监员 D2 T2 二分答案
- 【NOIP 2011 Day2 T2】聪明的质检员(二分)
- Noip 提高组 2011 Day2 T2 聪明的质检员 二分法
- NOIP2011提高组 聪明的质检员(二分答案)
- NOIP2011 聪明的质检员
- [NOIP 2011]聪明的质检员 二分+前缀和
- Luogu 1314 【NOIP2011】聪明的质检员 (二分)
- NOIP2011提高组 聪明的质检员
- NOIP2011 tyvj1696 聪明的质检员
- 【NOIP2011提高组】聪明的质检员
- 【noip2011】聪明的质检员
- [FT][1]NOIP 2011 聪明的质检员
- NOIP2011 Day2 T2 聪明的质监员
- noip2011聪明的质检员
- NOIP2011提高组 聪明的质检员(重庆一中高2018级信息学竞赛测验6) 解题报告
- [luogu-1314]noip2011 day2-T2聪明的质监员 题解
- NOIP2011 聪明的质检员 二分
- 【二分】NOIP2011聪明的质检员
- [NOIP2011]聪明的质检员