洛谷 P2879 [USACO07JAN]区间统计Tallest Cow
牛客 25044 Tallest Cow
#include<cstdio>
using namespace std;
#define min(a,b) (a<b ? a:b)
bool b[10001][10001];
int a[10002];//差分数组
int main() {
int highest,highest_pos,R,n;
scanf("%d%d%d%d",&n,&highest_pos,&highest,&R);
a[1]=highest;
for(int x,y,l,r; R--;) {
scanf("%d%d",&x,&y);
if (b[x][y] || b[y][x]) continue;//去重
b[x][y]=b[y][x]=1;
if (x>y) x^=y^=x^=y;
a[x+1]--,a[y]++;
}
for (int i=2,sum=a[1]; i<=n+1; i++) printf("%d\n",sum),sum+=a[i];//输出差分数组对应的原数组
}网上讲解很多,在这里就不赘述了qwq

京公网安备 11010502036488号