CSES - Datatähti Open 2017 - Results
Submission details
Task:Mex value
Sender:herkar
Submission time:2017-01-22 13:23:26 +0200
Language:C++
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:45:2: error: inconsistent deduction for 'auto': 'main()::__lambda0' and then 'main()::__lambda1'
  };
  ^
input/code.cpp:50:75: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    while(m+j < k && !(T.find(m+j) == T.end()) && T.order_of_key(m+j) == m+j)
                                                                           ^

Code

#include <functional>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <class T>
using Tree = tree<T, null_type, less<T>, rb_tree_tag,
	  tree_order_statistics_node_update>;

#define rep(i,a,b) for(int i = (a); i < int(b); ++i)
#define rrep(i,a,b) for(int i = (b); i --> int(a); )
#define trav(i,v) for(auto&i:v)
#define all(c) (c).begin(), (c).end()
#define sz(c) int((c).size())
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
int main(){
	cin.tie(0);
	cin.sync_with_stdio(0);
	cin.tie(0);
	cin.sync_with_stdio(0);
	int n,k;
	cin >> n >> k;
	vi v(n);
	trav(i,v) cin >> i;
	map<int,int> C;
	Tree<int> T;
	auto add = [&](int a){
		if(C[a]++) return;
		T.insert(a);
	}, rem = [&](int a){
		if(--C[a]) return;
		T.erase(T.find(a));
	};
	rep(i,0,k) add(v[i]);
	rep(i,k,n+1){
		int m = 0;
		for(int j = k/2; j > 0; j >>= 1)
			while(m+j < k && !(T.find(m+j) == T.end()) && T.order_of_key(m+j) == m+j)
				m += j;
		cout << m+1 << " ";
		if(i < n){
			add(v[i]);
			rem(v[i-k]);
		}
	}
	cout << endl;
}