比赛 20150422 评测结果 AAAAAAAAAAAAAAA
题目名称 奶牛跑步 最终得分 100
用户昵称 RP++ 运行时间 0.867 s
代码语言 C++ 内存使用 2.22 MiB
提交时间 2015-04-22 11:55:56
显示代码纯文本
#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);
}