1,Convoluted Intervals
1,Convoluted Intervals
题意:
思路:区间数很多,但是端点值都在0~5000,所以可以用桶来存;
因为i和j的取值都在(0~m)所以双重遍历构建差分数组
就是考虑i+j对区间的值的增加的贡献度,左端点就是加,右端点就是减(因为贡献的是一段区间,所以到右端点时就停止贡献);然后还原0~m*2的区间;
#include<bits/stdc++.h>
#define rep1(i,a,n) for( int i=a;i<n;++i)
#define rep2(i,a,n) for( int i=a;i<=n;++i)
#define per1(i,n,a) for( int i=n;i>a;i--)
#define per2(i,n,a) for( int i=n;i>=a;i--)
#define quick_cin() cin.tie(0),cout.tie(0),ios::sync_with_stdio(false)
#define memset(a,i,b) memset((a),(i),sizeof (b))
#define memcpy(a,i,b) memcpy((a),(i),sizeof (b))
#define pro_q priority_queue
#define pb push_back
#define pf push_front
#define endl "\n"
#define lowbit(m) ((-m)&(m))
#define YES cout<<"YES\n"
#define NO cout<<"NO\n"
#define Yes cout<<"Yes\n"
#define No cout<<"No\n"
#define yes cout<<"yes\n"
#define no cout<<"no\n"
#define yi first
#define er second
#define INF 0x3f3f3f3f
using namespace std;
typedef pair<int,int> PII;
typedef pair<long long,long long>PLL;
typedef pair<int,PII> PIII;
typedef long long LL;
typedef double dob;
#define int LL
const int N=1e6+10;
int cf[N],a[N];
int lcs[N],rcs[N];
int n,m;
signed main()
{
quick_cin();
cin>>n>>m;
while(n--)
{
int l,r;
cin>>l>>r;
lcs[l]++;
rcs[r]++;
}
rep2(i,0,m+1)
rep2(j,0,m+1)
{
cf[i+j]+=lcs[i]*lcs[j];
cf[i+j+1]-=rcs[i]*rcs[j];
}
cout<<cf[0]<<endl;
a[0]+=cf[0];
rep2(i,1,m*2)
{
a[i]=a[i-1]+cf[i];
cout<<a[i]<<endl;
}
return 0;
}