前缀和
题目连接:http://www.noobdream.com/DreamJudge/Issue/page/1209/#
#include <iostream> #include <string> #include <math.h> #include <algorithm> #include <vector> const int N = 200005; int wall[N]; int b[N],e[N]; using namespace std; int main() { int B,E; while(scanf("%d%d", &B, &E) && (B || E)) { wall[B]++;wall[E+1]--; } for (int i = 1; i < N; i++) wall[i]+=wall[i-1]; while(scanf("%d%d", &B, &E) && (B || E)) { for (int i = B; i <= E; i++) printf("%d ", wall[i]); } return 0; }