提出 #26328261


ソースコード 拡げる

#include<bits/stdc++.h>
#define lson (rt<<1)
#define rson (rt<<1|1)
#define mid ((l+r)>>1)

using namespace std;

const int N=6e5+5;

int n,ans[N];
pair<int,int> a[N];
int tmp[N],tot;
int tr[N<<2],tag[N<<2];
int d[N];

void pushdown(int rt,int l,int r)
{
	if(!tag[rt]) return;
	tag[lson]+=tag[rt],tag[rson]+=tag[rt];
	tr[lson]+=tag[rt]*(mid-l+1);
	tr[rson]+=tag[rt]*(r-mid);
	tag[rt]=0;
}
void pushup(int rt)
{
	tr[rt]=tr[lson]+tr[rson];
}
void update(int rt,int l,int r,int L,int R)
{
	if(L<=l&&r<=R){
		tr[rt]+=r-l+1;
		tag[rt]+=1;
		return;
	}
	pushdown(rt,l,r);
	if(L<=mid) update(lson,l,mid,L,R);
	if(R>mid) update(rson,mid+1,r,L,R);
	pushup(rt);
}
int ask(int rt,int l,int r,int L,int R)
{
	if(L<=l&&r<=R) return tr[rt];
	pushdown(rt,l,r);
	int res=0;
	if(L<=mid) res+=ask(lson,l,mid,L,R);
	if(R>mid) res+=ask(rson,mid+1,r,L,R);
	return res;
}
int main()
{
	ios::sync_with_stdio(false);cin.tie(0);

	cin>>n;
	for(int i=1;i<=n;++i){
		cin>>a[i].first>>a[i].second;
		a[i].second=a[i].first+a[i].second;
	}
	for(int i=1;i<=n;++i){
		tmp[++tot]=a[i].first;
		tmp[++tot]=a[i].second;
	}
	sort(tmp+1,tmp+tot+1);
	tot=unique(tmp+1,tmp+tot+1)-tmp-1;
	for(int i=1;i<=n;++i){
		a[i].first=lower_bound(tmp+1,tmp+tot+1,a[i].first)-tmp;
		a[i].second=lower_bound(tmp+1,tmp+tot+1,a[i].second)-tmp;
	}

	for(int i=1;i<=n;++i){
		update(1,1,tot,a[i].first,a[i].second-1);
	}
	for(int i=1;i<tot;++i){
		int now=ask(1,1,tot,i,i);
		ans[now]+=(tmp[i+1]-tmp[i]);
	}
	
	for(int i=1;i<=n;++i){
		cout<<ans[i]<<" ";
	}
	return 0;
}

提出情報

提出日時
問題 D - Online games
ユーザ hzy1
言語 C++ (GCC 9.2.1)
得点 400
コード長 1595 Byte
結果 AC
実行時間 268 ms
メモリ 15812 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 400 / 400
結果
AC × 2
AC × 24
セット名 テストケース
Sample example_00.txt, example_01.txt
All example_00.txt, example_01.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, hand_09.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt
ケース名 結果 実行時間 メモリ
example_00.txt AC 11 ms 3540 KiB
example_01.txt AC 2 ms 3476 KiB
hand_00.txt AC 66 ms 6620 KiB
hand_01.txt AC 5 ms 3540 KiB
hand_02.txt AC 170 ms 10380 KiB
hand_03.txt AC 265 ms 15672 KiB
hand_04.txt AC 4 ms 3484 KiB
hand_05.txt AC 2 ms 3540 KiB
hand_06.txt AC 72 ms 6736 KiB
hand_07.txt AC 47 ms 5516 KiB
hand_08.txt AC 199 ms 13968 KiB
hand_09.txt AC 268 ms 15812 KiB
random_00.txt AC 168 ms 7700 KiB
random_01.txt AC 167 ms 7508 KiB
random_02.txt AC 164 ms 7384 KiB
random_03.txt AC 165 ms 7264 KiB
random_04.txt AC 165 ms 7252 KiB
random_05.txt AC 211 ms 11224 KiB
random_06.txt AC 213 ms 11108 KiB
random_07.txt AC 210 ms 11108 KiB
random_08.txt AC 264 ms 15196 KiB
random_09.txt AC 268 ms 15252 KiB
random_10.txt AC 265 ms 15336 KiB
random_11.txt AC 268 ms 15384 KiB