HDU 4970 Killing Monsters

Doubi Gao3 posted @ 2014年8月23日 21:17 in acm with tags BIT , 1051 阅读

比赛时线段树超时,然后用树状数组暴力过了。

 

#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <string>
using namespace std;

typedef long long LL;

void readint(LL &x)
{
	char c = getchar();
	while(!isdigit(c)) c = getchar();
	
	x = 0;
	while(isdigit(c))
	{
		x = x*10+c-'0';
		c = getchar();
	}
}

void writeint(LL x)
{
	if(x > 9) writeint(x/10);
	putchar(x%10+'0');
}

/////////////////////////////////

const LL maxn = 100000 + 10;
LL n, m;
LL C[maxn];

LL lowbit(LL x)
{
	return x & -x;
}

void add(LL x, LL d)
{
	while(x > 0)
	{
		C[x] += d; x -= lowbit(x);
	}
}

LL sum(LL x)
{
	LL ans = 0;
	while(x <= n)
	{
		ans += C[x]; x += lowbit(x);
	}
	return ans;
}

LL f[maxn];

int main()
{
	for(;;)
	{
		readint(n);
		if(!n) break;
		for(int i = 0; i <= n; i++)
			C[i] = f[i] = 0;
		
		readint(m);
		
		for(int i = 1; i <= m; i++)
		{
			LL x, y, z; readint(x), readint(y), readint(z);
			add(y, z), add(x-1, -z);
		}
		
		f[n] = sum(n);
		
		for(int i = n-1; i >= 1; i--)
		{
			f[i] = sum(i)+f[i+1];
		}
		
		LL k; readint(k);
		
		LL ans = 0;
		for(int i = 1; i <= k; i++)
		{
			LL h, x; readint(h), readint(x);
			if(h > f[x]) ans++;
		}
		writeint(ans), puts("");
	}
	return 0;
}
JAC 8th Question Pap 说:
2022年8月25日 16:48

Prepare students for the State of Jharkhand Academic Council JAC 8th Class Public Examination 2023, which will be held in April and May 2023. JAC Board Class 8th Syllabus and Pattern may be downloaded. Class 8th Model JAC 8th Question Paper 2023 Question Paper for Jharkhand in 2023 In 2023, the Jharkhand Academic Council will provide sample questions for the disciplines of mathematics, science, and English as well as for the subjects of Hindi and social studies according to the syllabus. The JAC Jharkhand Board 8th Model Question Paper with Answer Solutions is available for download for all candidates for the upcoming Jharkhand Board 8th Class Secondary Examination 2023. 

Alyssa 说:
2023年1月01日 01:12

There are many reasons why people enjoy playing video games. For some, it is a way to unwind and relieve stress. For others, it is a way to socialize and connect with friends. But for many people, it is a way to escape cbd oil from the reality of their lives. In a video game, you can be whoever you want to be. You can be the hero who saves the world, or the villain who conquers it. You can be the king or the beggar, the warrior or the wizard. You can be anything you want, and you can do anything you want. There are no limits.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter