제출 #1158030

#제출 시각아이디문제언어결과실행 시간메모리
1158030SmuggingSpunAdvertisement 2 (JOI23_ho_t2)C++20
69 / 100
225 ms27280 KiB
#include<bits/stdc++.h>
#define taskname "B"
using namespace std;
template<class T>void maximize(T& a, T b){
	if(a < b){
		a = b;
	}
}
const int lim = 5e5 + 5;
int n, X[lim], E[lim];
namespace sub1{
	void solve(){
		map<int, bool>cnt;
		for(int i = 1; i <= n; i++){
			cnt[X[i]] = true;
		}
		cout << cnt.size();
	}
}
namespace sub23{
	void solve(){
		map<int, int>repu;
		for(int i = 1; i <= n; i++){
			maximize(repu[X[i]], E[i]);
		}
		n = repu.size();
		vector<pair<int, int>>vertex;
		for(pair<const int, int>& it : repu){
			vertex.emplace_back(it);
		}
		vector<bool>d(n, true);
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				if(i != j && abs(vertex[i].first - vertex[j].first) <= vertex[i].second - vertex[j].second){
					d[j] = false;
				}
			}
		}
		cout << count(d.begin(), d.end(), true);
	}
}
//x[i] - x[j] <= e[i] - e[j] -> x[i] - e[i] <= x[j] - e[j]
//x[j] - x[i] <= e[i] - e[j] -> x[i] + e[i] >= x[j] + e[j]
namespace sub4{
	void solve(){
		map<int, int>repu;
		for(int i = 1; i <= n; i++){
			maximize(repu[X[i]], E[i]);
		}
		n = repu.size();
		vector<pair<int, int>>vertex;
		for(pair<const int, int>& it : repu){
			vertex.emplace_back(it);
		}
		vector<bool>d(n, true);
		priority_queue<pair<int, int>>left;
		priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>>right;
		for(int i = 1; i <= n; i++){
			right.emplace(vertex[i].first + vertex[i].second, i);
		}
		for(int i = 1; i <= n; i++){
			int side = vertex[i].first - vertex[i].second;
			while(!left.empty()){
				auto [S, I] = left.top();
				if(S < side){
					break;
				}
				d[I] = false;
				left.pop();
			}
			left.emplace(side, i);
			side = vertex[i].first + vertex[i].second;
			while(!right.empty()){
				auto [S, I] = right.top();
				if(S > side){
					break;
				}
				right.pop();
				if(I <= i){
					continue;
				}
				d[I] = false;
			}
		}
		cout << count(d.begin(), d.end(), true);
	}
}
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	if(fopen(taskname".inp", "r")){
		freopen(taskname".inp", "r", stdin);
	}
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> X[i] >> E[i];
	}
	if(*min_element(E + 1, E + n + 1) == *max_element(E + 1, E + n + 1)){
		sub1::solve();
	}
	else if(n <= 1000){
		sub23::solve();
	}
	else{
		sub4::solve();
	}
}

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp: In function 'int main()':
Main.cpp:91:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   91 |                 freopen(taskname".inp", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...