很妙的差分思想~~
题目链接: https://www.acwing.com/problem/content/description/103/
#include<iostream>
#include<algorithm>
using namespace std;
const int N = 10010;
int n,p,h,m;
int q[N];
bool flag[N][N];
int main()
{
cin>>n>>p>>h>>m;
q[1] = h;
while(m--)
{
int a,b;
cin>>a>>b;
if(a > b) swap(a,b);
if(!flag[a][b])
{
flag[a][b] = 1;
q[a+1] -= 1,q[b] += 1;
}
}
for(int i = 1;i <= n;i++)
{
q[i] += q[i-1];
cout<<q[i]<<endl;
}
return 0;
}
,,,,,,,,,,,,,