Submission #15645

# Submission time Handle Problem Language Result Execution time Memory
15645 2015-07-14T02:22:31 Z gs14004 Last supper (IOI12_supper) C++14
Compilation error
0 ms 0 KB
#include "advisor.h"#include <vector>
#include <algorithm>
#include <set>
using namespace std;
typedef pair<int,int> pi;

set<pi> s;
vector<pi> nexts;
int query[100005];
int is_in[100005];

int getnxt(int val, int time){
	auto t = upper_bound(nexts.begin(), nexts.end(), pi(val, time));
	if(t->first != val) return 1e9;
	return t->second;
}

bool PopPrevRequest[100005];
bool PopK[25005];

void ComputeAdvice(int *C, int N, int K, int M) {
	for(int i=0; i<N; i++){
		nexts.push_back(pi(C[i], i));
	}
	sort(nexts.begin(), nexts.end());
	for(int i=0; i<K; i++){
		s.insert(pi(getnxt(i, -1), i));
		is_in[i] = 1;
	}
	for(int i=0; i<N; i++){
		query[i] = N;
		if(is_in[C[i]]){
			if(s.find(pi(i, C[i])) != s.end()) s.erase(pi(i, C[i]));
			s.insert(pi(getnxt(C[i], i), C[i]));	
		}
		else{
			auto t = --s.end();
			query[i] = t->second;
			is_in[t->second] = 0;
			s.erase(t);
			s.insert(pi(getnxt(C[i], i), C[i]));
			is_in[C[i]] = 1;
		}
	}
	for(int i=0; i<N; i++){
		if(query[i] != N){
			auto t = lower_bound(nexts.begin(), nexts.end(), pi(query[i], i));
			if(t == nexts.begin() || (t-1)->first != query[i]){
				PopK[query[i]] = 1;
			}
			else{
				t--;
				PopPrevRequest[t->second] = 1;
			}
			// investigate last use of pop query
		}
	}
	for(int i=0; i<N; i++){
		WriteAdvice(PopPrevRequest[i]);
	}
	for(int i=0; i<K; i++){
		WriteAdvice(PopK[i]);
	}
}
#include "assistant.h"

#include <set>
using namespace std;
set<int> pops, scaffold;

void Assist(unsigned char *A, int N, int K, int R) {
	int prevReq = -1;
	for(int i=0; i<K; i++){
		if(A[i+N]) pops.insert(i), scaffold.insert(i);
	}
	for(int i=0; i<N; i++){
		int curReq = GetRequest();
		if(scaffold.find(curReq) != scaffold.begin()){
			PutBack(*pops.begin());
			scaffold.erase(*pops.begin());
			pops.erase(pops.begin());
			scaffold.insert(curReq);
		}
		if(A[i]){
			pops.insert(curReq);
		}
	}
}

Compilation message

advisor.cpp:1:21: warning: extra tokens at end of #include directive
 #include "advisor.h"#include <vector>
                     ^
advisor.cpp:8:1: error: 'vector' does not name a type; did you mean 'qecvt_r'?
 vector<pi> nexts;
 ^~~~~~
 qecvt_r
advisor.cpp: In function 'int getnxt(int, int)':
advisor.cpp:13:23: error: 'nexts' was not declared in this scope
  auto t = upper_bound(nexts.begin(), nexts.end(), pi(val, time));
                       ^~~~~
advisor.cpp: In function 'void ComputeAdvice(int*, int, int, int)':
advisor.cpp:23:3: error: 'nexts' was not declared in this scope
   nexts.push_back(pi(C[i], i));
   ^~~~~
advisor.cpp:25:7: error: 'nexts' was not declared in this scope
  sort(nexts.begin(), nexts.end());
       ^~~~~

assistant.cpp: In function 'void Assist(unsigned char*, int, int, int)':
assistant.cpp:8:6: warning: unused variable 'prevReq' [-Wunused-variable]
  int prevReq = -1;
      ^~~~~~~