답안 #618024

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
618024 2022-08-01T19:32:36 Z 1ne Sails (IOI07_sails) C++14
0 / 100
507 ms 6936 KB
#include<bits/stdc++.h>
using namespace std;
struct dataa{
	long long lazy = 0,sum = 0;
	void add(long long left,long long right,long long val){
		lazy+=val;
		sum+=val * (right - left + 1);
		//sum += val *(right - left + 1);
	}
};
struct Segment_Tree{
	vector<dataa>tree;
	void init(long long n){
		tree.resize(2*n - 1);
	}
	dataa combine(dataa left,dataa right){
		dataa res;
		res.sum = left.sum + right.sum;
		return res;
	}
	void push(long long node,long long left,long long right){
		long long mid = (left + right)>>1;
		long long z = node + ((mid - left + 1)<<1);
		if (tree[node].lazy!=0){
			tree[node + 1].add(left,mid,tree[node].lazy);
			tree[z].add(mid + 1,right,tree[node].lazy);
			tree[node].lazy = 0;
		}
	}
	long long query(long long node,long long left,long long right,long long qleft,long long qright){
		if (qright<left|| qleft > right)return 0;
		if (qleft<=left && qright >=right){
			return tree[node].sum;
		}
		push(node,left,right);
		long long mid = (left + right)>>1;
		long long z = node + ((mid - left + 1)<<1);
		return query(node + 1,left,mid,qleft,qright) + query(z,mid + 1,right,qleft,qright);
	}
	void update(long long node,long long left,long long right,long long uleft,long long uright,long long v){
		if (left > uright || right < uleft) return;
		if (uleft <= left && right <=uright){
			tree[node].add(left,right,v);
			return;
		}
		push(node,left,right);
		long long mid = (left + right)>>1;
		long long z = node + ((mid - left + 1)<<1);
		if (uleft<=mid){
			update(node + 1,left,mid,uleft,uright,v);
		}
		if (uright > mid){
			update(z,mid + 1,right,uleft,uright,v);
		}
		tree[node] = combine(tree[node + 1],tree[z]);
	}
};

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;cin>>n;
	vector<pair<long long,long long>>arr(n);
	vector<long long>v(100001,0);
	Segment_Tree st;
	st.init(100001);
	int mxn = 100000;
	for (int i = 0;i<n;++i){
		cin>>arr[i].first>>arr[i].second;
	}
	sort(arr.begin(),arr.end(),[&](auto x,auto y){
		return x.first < y.first;
	});
	long long ans = 0;
	for (int i = 0;i<n;++i){
		ans+=st.query(0,0,mxn,arr[i].first - arr[i].second,arr[i].first - 1);
		st.update(0,0,mxn,arr[i].first - arr[i].second,arr[i].first - 1,1);
		int left = 0,right = min(arr[i].second - 1,arr[i].first - arr[i].second - 1);
		int p = -1;
		while(left<=right){
			int mid = (left  + right)>>1;
			if (st.query(0,0,mxn,arr[i].first - arr[i].second - 1 - mid,arr[i].first - arr[i].second - 1 - mid) < st.query(0,0,mxn,arr[i].first - 1 -  mid,arr[i].first - 1 - mid)){
				left = mid + 1;
				p = mid;
			}
			else right = mid - 1;
		}
		if (p!=-1){
			st.update(0,0,mxn,arr[i].first - arr[i].second - 1 - p,arr[i].first - arr[i].second - 1,1);
			st.update(0,0,mxn,arr[i].first - 1 - p,arr[i].first - 1,-1);
		}
	}
	cout<<ans<<'\n';
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 4180 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 4156 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 4180 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 4180 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 4180 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 35 ms 4428 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 36 ms 4984 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 237 ms 5580 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 442 ms 6276 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 310 ms 6680 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 507 ms 6936 KB Output isn't correct
2 Halted 0 ms 0 KB -