http://acm.hdu.edu.cn/showproblem.php?pid=4970
有n个格子在一条线标号1-n上,可以给范围在l到r内的格子架上攻击力为d的攻击塔,有m个怪物,每个怪物有个血量h和出生地x,现在要求有多少怪物可以活着走到第n个塔后,怪物每走一步就会被所在格子的塔(如果有)攻击。
线段树交了一发T了,其实只要离线出每个格子累计伤害,然后每次查询能否走到第n格即可
但是交c++的话还是会T,G++就过了
据说用树状数组可以过...
#include <cstdio> #include <cstdlib> #include <cmath> #include <cstring> #include <string> #include <queue> #include <vector> #include<map> #include <iostream> #include <algorithm> using namespace std; #define RD(x) scanf("%d",&x) #define RD2(x,y) scanf("%d%d",&x,&y) #define clr0(x) memset(x,0,sizeof(x)) typedef long long LL; int n; int l[110000]; int r[110000]; int d[110000]; LL h; int x; pair<int, int> pos[220000]; long long f[110000]; int main() { int n,m,l,r,d,k; while(~scanf("%d",&n),n){ RD(m); for(int i = 0;i < m;i++){ RD2(l,r);RD(d); pos[i * 2] = make_pair(l, d); pos[i * 2 + 1] = make_pair(r + 1, -d); } sort(pos, pos + m + m); pos[m + m] = make_pair(n + 1, 0); f[0] = 0; int p = 0; LL sum = 0; for (int i = 1; i <= n; i++) { while (pos[p].first <= i) { sum += pos[p].second; p++; } f[i] = f[i - 1] + sum; } scanf("%d",&k); int ans = 0; for (int i = 0; i < k; i++) { scanf("%I64d%d", &h, &x); if (f[n] - f[x - 1] < h) ans++; } printf("%d ", ans); } return 0; }