HDU 4970 Killing Monsters
比赛时线段树超时,然后用树状数组暴力过了。
#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; }