Submission #1351803

#TimeUsernameProblemLanguageResultExecution timeMemory
1351803MatjazNew Home (APIO18_new_home)C++20
Compilation error
0 ms0 KiB
#include<iostream>
#include<vector>
#include<set>
#include<queue> 

using namespace std;

int main(){

	int n,q,k;

	cin >> n >> k >> q; 

	vector<int> x(n);
	vector<int> t(n);
	vector<int> a(n);
	vector<int> b(n);

	multiset<int> store;

	vector<pair<int,pair<int,pair<int,int> > events;

	// Store of type t[i] opens at location x
	// Store of type t[i] closes at location x
	// We want to know the quality of living at location y
	// (time, query type (openings come before queries, come before closings), location, type/query index)


	for (int i=0;i<n;i++){
		cin >> x[i] >> t[i] >> a[i] >> b[i];
		events.push_back({a[i], {-1, {x[i], t[i]}}}); 
		events.push_back({b[i], { 1, {x[i], t[i]}}}); 
	}

	vector<int> answer(q, -1);

	for (int i=0;i<q;i++){
		int l,y;
		cin >> l >> y;
		events.push_back({y, { 0, {l, i}}});

	}

	sort(events.begin(), events.end());
	vector<multiset<int> > store(k);

	for (int i=0;i<events.size();i++){
		int event_type = events[i].second.first;
		if (event_type == -1){
			int store_type = events[i].second.second.second;
			int l = events[i].second.second.first;
			store[store_type].insert(l);
		}

		if (event_type == 1){
			int store_type = events[i].second.second.second;
			int l = events[i].second.second.first;
			auto it = store[store_type].find(l);
			store[store_type].erase(it);
		}

		if (event_type == 0){
			int index = events[i].second.second.second;
			int l = events[i].second.second.first;

			answer[index] = 0;

			for (int j=0;j<k;j++){
				int nearest = 100000001;
				auto it = store[j].upper_bound(l);
				if (it != store[j].end()) nearest = abs(*it - l);
				it = store[j].lower_bound(l);
				if (it != store[j].begin()){
					it = prev(it);
					nearest = min(nearest, abs(l - *it));
				} 

				answer[index] = max(answer[index], nearest);
			}

			if (answer[index] == 100000001) answer[index] = -1;
		}
	}

	for (int i=0;i<q;i++) cout << answer[i] << endl;

	return 0;
}

Compilation message (stderr)

new_home.cpp: In function 'int main()':
new_home.cpp:21:50: error: template argument 2 is invalid
   21 |         vector<pair<int,pair<int,pair<int,int> > events;
      |                                                  ^~~~~~
new_home.cpp:21:16: error: template argument 1 is invalid
   21 |         vector<pair<int,pair<int,pair<int,int> > events;
      |                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
new_home.cpp:21:16: error: template argument 2 is invalid
new_home.cpp:31:17: error: 'events' was not declared in this scope
   31 |                 events.push_back({a[i], {-1, {x[i], t[i]}}});
      |                 ^~~~~~
new_home.cpp:40:17: error: 'events' was not declared in this scope
   40 |                 events.push_back({y, { 0, {l, i}}});
      |                 ^~~~~~
new_home.cpp:44:14: error: 'events' was not declared in this scope
   44 |         sort(events.begin(), events.end());
      |              ^~~~~~
new_home.cpp:44:9: error: 'sort' was not declared in this scope; did you mean 'short'?
   44 |         sort(events.begin(), events.end());
      |         ^~~~
      |         short
new_home.cpp:45:32: error: conflicting declaration 'std::vector<std::multiset<int> > store'
   45 |         vector<multiset<int> > store(k);
      |                                ^~~~~
new_home.cpp:19:23: note: previous declaration as 'std::multiset<int> store'
   19 |         multiset<int> store;
      |                       ^~~~~
new_home.cpp:52:30: error: no match for 'operator[]' (operand types are 'std::multiset<int>' and 'int')
   52 |                         store[store_type].insert(l);
      |                              ^
new_home.cpp:58:40: error: no match for 'operator[]' (operand types are 'std::multiset<int>' and 'int')
   58 |                         auto it = store[store_type].find(l);
      |                                        ^
new_home.cpp:59:30: error: no match for 'operator[]' (operand types are 'std::multiset<int>' and 'int')
   59 |                         store[store_type].erase(it);
      |                              ^
new_home.cpp:70:48: error: no match for 'operator[]' (operand types are 'std::multiset<int>' and 'int')
   70 |                                 auto it = store[j].upper_bound(l);
      |                                                ^
new_home.cpp:71:48: error: no match for 'operator[]' (operand types are 'std::multiset<int>' and 'int')
   71 |                                 if (it != store[j].end()) nearest = abs(*it - l);
      |                                                ^
new_home.cpp:72:43: error: no match for 'operator[]' (operand types are 'std::multiset<int>' and 'int')
   72 |                                 it = store[j].lower_bound(l);
      |                                           ^
new_home.cpp:73:48: error: no match for 'operator[]' (operand types are 'std::multiset<int>' and 'int')
   73 |                                 if (it != store[j].begin()){
      |                                                ^