제출 #1245230

#제출 시각아이디문제언어결과실행 시간메모리
1245230shiori_chan도로 건설 사업 (JOI13_construction)C++17
컴파일 에러
0 ms0 KiB
#include <iostream>
#include <vector>
#include <random>
#include <algorithm>
#include <chrono>
#include <set>
#include <queue>
#include <cstring>
#define all(x) x.begin(), x.end()
#define pi pair <int , int> 

using namespace std;
typedef long long ll;
#define int long long

const int nd = 2e6;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
uniform_int_distribution<int> dist(1 , (int)2e9);

struct node{
	bool type;
	int special = 0;
	int yR , x , y , id , id_e = -1;
	node(){}
	node(bool type , int x , int y , int id) : type(type) , x(x) , y(y) , id(id){}

	bool operator<(const node &o)const{
		if(x == o.x) return (y + type) > (o.y + type);
		return x < o.x;
	}
} point[nd];

set <pair <int , int> > st;

struct EDGE{
	int l , r , w;
	bool valid = true;
	EDGE(){}
	EDGE(int l , int r , int w) : l(l) , r(r) , w(w){}

	bool operator <(const EDGE &o){
		return w < o.w;
	}
};
vector <EDGE> edge;
vector <int> nt(nd) , tmp(nd);

void build(int timer){
	bool valid = true;
	int yr = 0;
	queue <pi> q; 
	st.clear();
	int cur = -1;

	for(int i = 1;i <= timer; ++ i){
		auto [type , sp , R , x , y , id , id_e] = point[i];
		
		if(type == false){
			if(sp == 1 || sp == 3){
				auto it = st.lower_bound({y , -1});
				//cout << x << " " << y << " " << R << " " << sp << '\n';
				while(it != st.end() && y <= (*it).first && (*it).first <= R){
					q.push((*it));
					if(point[(*it).second].id_e > -1){
						edge[point[(*it).second].id_e].valid = false;
					}
					++ it;
				}
				while(q.size()) st.erase(q.front()) , q.pop();
			}

			if(cur == y){
				auto it = st.lower_bound({y , -1});
				while(it != st.end() && y <= (*it).first && (*it).first <= yr){
					q.push((*it));
					++ it;
				}
				while(q.size()) st.erase(q.front()) , q.pop();
				cur = -1;
			}
			else{
				if(cur == -1) yr = y , cur = nt[id];
				else cur = min(cur , nt[id]);
				//cout << x << " " << y << " " << id << '\n';
				valid = false;
			}
		}
		else{
			if(valid){
				auto it = st.lower_bound({y , -1});
				if(st.size() && it != st.end() && (*it).first == y){
					point[i].id_e = edge.size();
					edge.push_back(EDGE(point[(*it).second].id , id , x - point[(*it).second].x));
					st.erase(it); 
				}
				st.insert({y , i});
			}
		}
		if(cur == -1) valid = true;
	}
}

int par[nd] , sz[nd];
int acs(int x){
	return (x == par[x] ? x : par[x] = acs(par[x]));
}

bool join(int u , int v){
	u = acs(u) , v = acs(v);
	if(u == v) return false;

	if(sz[u] > sz[v]) swap(u , v);
	par[u] = v;
	sz[v] += sz[u];
	return true;
}

bool comp(const int a , const int b){
	return a > b;
}

vector <int> val;
int pref[nd];

void solve(){
	int n , m , c; cin >> n >> m >> c;
	int timer = n;

	for(int i = 1;i <= n; ++ i) 
		cin >> point[i].x >> point[i].y , point[i].id = i , point[i].type = true;

	sort(point + 1 , point + 1 + n);

	for(int i = 1;i <= m; ++ i){
		int s , t , a , b; cin >> s >> t >> a >> b;
		
		point[++ timer] = node(false , s , t , timer + 1);
		point[++ timer] = node(false , s , b , timer + 1);
		nt[timer] = t; point[timer].special = 4;
		point[timer].yR = a;
		point[++ timer] = node(false , a , b , timer + 1);
		nt[timer] = t; tmp[timer] = s;
		point[++ timer] = node(false , a , t , timer + 1);
		tmp[timer] = s; point[timer].special = 1;
		point[timer].yR = b;
	}

	sort(point + 1 , point + 1 + timer);
	build(timer);

	for(int i = 1;i <= timer; ++ i) 
		swap(point[i].x , point[i].y) , point[i].special -= bool(point[i].special);
		//cout << point[i].type << " " << point[i].id << " " << point[i].x << " " << point[i].y << '\n';
	nt = tmp;
	sort(point + 1 , point + 1 + timer);
	build(timer);

	sort(all(edge));
	int timer2 = timer;
	timer = 0;
	val.push_back(1e18);
	
	int cost_road = 0;
	for(int i = 1; i <= n; ++ i) par[i] = i , sz[i] = 1;

	for(auto e : edge) if(e.valid){
		//cout << e.l << " " << e.r << " " << e.w << '\n';
		if(join(e.l , e.r)) val.push_back(e.w) , ++ timer , cost_road += e.w;
	}

	sort(all(val) , comp); 
	for(int i = 1;i <= timer; ++ i) 
		pref[i] = pref[i - 1] + val[i];
		//cout << pref[i].first << " " << pref[i].second << '\n';
	int cnt = 0;
	for(int i = 1;i <= n; ++ i) cnt += (i == par[i]);
	//cout << cnt << '\n';
	//cout << cost_road << '\n';
	//cout << val.size() << '\n';

	while(c --){
		int h , b; cin >> b >> h;

		if(h < cnt) cout << -1 << '\n';
		else{
			int delta = h - cnt;
			int cost = cost_road + b * cnt;
			//cout << cost << '\n';
			if(val.size() == 1){
				cout << cost << '\n';
				continue;
			}
			//cout << cost << " ";
			auto it = upper_bound(all(val) , b , comp);
			-- it;
			delta = min(delta , it - val.begin());
			cost += delta * b - pref[delta];

			cout << cost << '\n';
		}
	}
}

signed main() {
   ios_base::sync_with_stdio(false);
   cin.tie(0);

	#define task "task" 
	if(fopen(task".inp", "r")) {
		freopen(task".inp", "r", stdin);
		freopen(task".out", "w", stdout);
	}
	solve();

	return 0;
}

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

construction.cpp: In function 'void solve()':
construction.cpp:196:36: error: no matching function for call to 'min(long long int&, __gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >::difference_type)'
  196 |                         delta = min(delta , it - val.begin());
      |                                 ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/bits/char_traits.h:39,
                 from /usr/include/c++/11/ios:40,
                 from /usr/include/c++/11/ostream:38,
                 from /usr/include/c++/11/iostream:39,
                 from construction.cpp:1:
/usr/include/c++/11/bits/stl_algobase.h:230:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  230 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/11/bits/stl_algobase.h:230:5: note:   template argument deduction/substitution failed:
construction.cpp:196:36: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and '__gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >::difference_type' {aka 'long int'})
  196 |                         delta = min(delta , it - val.begin());
      |                                 ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/bits/char_traits.h:39,
                 from /usr/include/c++/11/ios:40,
                 from /usr/include/c++/11/ostream:38,
                 from /usr/include/c++/11/iostream:39,
                 from construction.cpp:1:
/usr/include/c++/11/bits/stl_algobase.h:278:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  278 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/11/bits/stl_algobase.h:278:5: note:   template argument deduction/substitution failed:
construction.cpp:196:36: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and '__gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >::difference_type' {aka 'long int'})
  196 |                         delta = min(delta , it - val.begin());
      |                                 ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/algorithm:62,
                 from construction.cpp:4:
/usr/include/c++/11/bits/stl_algo.h:3449:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)'
 3449 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/11/bits/stl_algo.h:3449:5: note:   template argument deduction/substitution failed:
construction.cpp:196:36: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
  196 |                         delta = min(delta , it - val.begin());
      |                                 ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/algorithm:62,
                 from construction.cpp:4:
/usr/include/c++/11/bits/stl_algo.h:3455:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)'
 3455 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/11/bits/stl_algo.h:3455:5: note:   template argument deduction/substitution failed:
construction.cpp:196:36: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
  196 |                         delta = min(delta , it - val.begin());
      |                                 ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
construction.cpp: In function 'int main()':
construction.cpp:210:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  210 |                 freopen(task".inp", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
construction.cpp:211:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  211 |                 freopen(task".out", "w", stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~