답안 #617110

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
617110 2022-08-01T08:45:31 Z 1ne Sails (IOI07_sails) C++14
0 / 100
1000 ms 10856 KB
#include<bits/stdc++.h>
using namespace std;
struct dataa{
	long long minny = 0,maxxy = 0,lazy = 0,index = 0,sum = 0;
	void add(long long left,long long right,long long val){
		minny+=val;
		maxxy+=val;
		lazy+=val;
		sum+=val * (right - left + 1);
		//sum += val *(right - left + 1);
	}
};
struct Segment_Tree{
	vector<dataa>tree;
	void build(long long node,long long left,long long right,vector<long long>&arr,long long n){
		if (left == right){
			tree[node].minny = arr[left];
			tree[node].maxxy = arr[left];
			tree[node].index = left;
			tree[node].sum = 0;
			return ;
		}
		long long mid = (left + right)>>1;
		long long z = node + ((mid - left + 1)<<1);
		build(node + 1,left,mid,arr,n);
		build(z,mid + 1,right,arr,n);
		tree[node] = combine(tree[node + 1],tree[z]);
	}
	void init(long long n,vector<long long>&arr){
		tree.resize(2*n - 1);
		build(0,0,n-1,arr,n);
	}
	dataa combine(dataa left,dataa right){
		dataa res;
		res.minny = min(left.minny,right.minny);
		res.maxxy = max(left.maxxy,right.maxxy);
		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;
		}
	}
	int query(long long node,long long left,long long right,long long qleft,long long qright,long long v){
		if (qright<left|| qleft > right)return -1;
		if (tree[node].minny > v)return -1;
		if (left == right){
			return tree[node].index;
		}
		push(node,left,right);
		long long mid = (left + right)>>1;
		long long z = node + ((mid - left + 1)<<1);
		if (tree[node + 1].minny <= v){
			 return query(node + 1,left,mid,qleft,qright,v);
		}
		return query(z,mid + 1,right,qleft,qright,v);
	}
	int query2(long long node,long long left,long long right,long long qleft,long long qright){
		if (qright<left|| qleft > right)return INT_MAX;
		if (qleft<=left && qright>=right){
			return tree[node].minny;
		}
		push(node,left,right);
		long long mid = (left + right)>>1;
		long long z = node + ((mid - left + 1)<<1);
		return min(query2(node + 1,left,mid,qleft,qright) , query2(z,mid + 1,right,qleft,qright));
	}
	int query3(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].maxxy;
		}
		push(node,left,right);
		long long mid = (left + right)>>1;
		long long z = node + ((mid - left + 1)<<1);
		return max(query3(node + 1,left,mid,qleft,qright) , query3(z,mid + 1,right,qleft,qright));
	}
	int query4(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 query4(node + 1,left,mid,qleft,qright) + query4(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<int,int>>arr(n);
	vector<long long>v(100001,0);
	Segment_Tree st;
	st.init(100001,v);
	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){
		int cur_ans = 1e8,index = 0;
		for (int j = 0;j + arr[i].second - 1< arr[i].first;++j){
			int temp = st.query4(0,0,mxn,j,j + arr[i].second - 1);
			if (temp < cur_ans){
				cur_ans = temp;
				index = j; 
			}
		}
		//cout<<cur_ans<<" "<<index<<'\n';
		ans+=cur_ans;
		st.update(0,0,mxn,index,index + arr[i].second - 1,1);
	}
	cout<<ans<<'\n';
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 8916 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 8916 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 8952 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 8916 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 201 ms 8972 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1078 ms 9044 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 50 ms 9496 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1072 ms 9836 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1063 ms 10324 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1077 ms 10672 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1069 ms 10856 KB Time limit exceeded
2 Halted 0 ms 0 KB -