답안 #617004

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
617004 2022-08-01T08:10:28 Z 1ne Sails (IOI07_sails) C++14
30 / 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;
	priority_queue<pair<long long,long long>>q;
	for (int i = 0;i<n;++i){
		vector<pair<int,int>>upd;
		while(arr[i].second > 0){
			int minny = st.query2(0,0,mxn,0,arr[i].first - 1);
			int pos = st.query(0,0,mxn,0,arr[i].first - 1,minny);
			int left = 0,right = min(arr[i].second - 1,arr[i].first - pos - 1);
			int p = 0;
			while(left<=right){
				int mid = (left + right)>>1;
				if (st.query3(0,0,mxn,pos,pos + mid) == minny){
					left = mid + 1;
					p = mid;
				}
				else right = mid - 1;
			}
			//cout<<arr[i].first<<" "<<pos<<" "<<pos + p<<'\n';
			upd.push_back({pos,p});
			arr[i].second-=p + 1;
			ans+=st.query4(0,0,mxn,pos,pos + p);
			st.update(0,0,mxn,pos,pos + p,1e8 + 1);	
		}
		for (auto x:upd){
			st.update(0,0,mxn,x.first,x.first + x.second,-1e8);
		}
	}
	cout<<ans<<'\n';
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 8916 KB Output is correct
2 Correct 5 ms 8916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8916 KB Output is correct
2 Correct 5 ms 8916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8916 KB Output is correct
2 Correct 5 ms 8892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 8916 KB Output is correct
2 Correct 57 ms 8916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1064 ms 8968 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1073 ms 9068 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1084 ms 9548 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1083 ms 9876 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1092 ms 10396 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1056 ms 10796 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1058 ms 10856 KB Time limit exceeded
2 Halted 0 ms 0 KB -