记录编号 159693 评测结果 AAAAAAAAAAAAAAA
题目名称 奶牛跑步 最终得分 100
用户昵称 GravatarRP++ 是否通过 通过
代码语言 C++ 运行时间 1.116 s
提交时间 2015-04-22 13:56:10 内存使用 1.46 MiB
显示代码纯文本
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;

#define maxn 100010
#define lowbit(x) x&-x
#define LL long long

int n, tr[maxn];
LL end[maxn], num[maxn];

void Add(int x) {
	for(int i = x; i <= n; i += lowbit(i))
		tr[i]++;
}

int get_ans(int x) {
	int ans = 0;
	for(int i = x; i >= 1; i -= lowbit(i))
		ans += tr[i];
	return ans;
}

int find(LL x) {
	int s = 1, t = n, mid;
	while(s <= t) {
		mid = (s + t) >> 1;
		if(num[mid] >= x) t = mid - 1;
		else s = mid + 1;
	}
	return s;
}

int main() {
	freopen("cowjoga.in", "r", stdin);
	freopen("cowjoga.out", "w", stdout);
	LL t;
	scanf("%d%lld", &n, &t);
	LL s, v;
	for(int i = 1; i <= n; i++) {
		scanf("%lld%lld", &s, &v);
		end[i] = s + v * t, num[i] = end[i];
	}
	sort(num + 1, num + n + 1);
	int ans = 0;
	for(int i = 1; i <= n; i++) {
		ans += get_ans(n) - get_ans(find(end[i]) - 1);
		Add(find(end[i]));	
	}
	memset(tr, 0, sizeof(tr));
	for(int i = n; i >= 1; i--) {
		int tmp = get_ans(find(end[i]));
		if(tmp) ans -= tmp - 1;
		Add(find(end[i]));
	}
	printf("%d", n - ans);
}