Submission #363117

# Submission time Handle Problem Language Result Execution time Memory
363117 2021-02-05T05:07:49 Z fhvirus Last supper (IOI12_supper) C++14
29 / 100
543 ms 81920 KB
//Knapsack DP is harder than FFT.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define ff first
#define ss second
#define pb emplace_back
#define FOR(i,n) for(int i = 0; i < (n); ++i)
#define FOO(i,a,b) for(int i = (a); i <= (b); ++i)
#define AI(x) (x).begin(),(x).end()
template<typename I> bool chmax(I &a, I b){ return a < b ? (a = b, true) : false;}
template<typename I> bool chmin(I &a, I b){ return a > b ? (a = b, true) : false;}
#ifdef OWO
#define debug(args...) LKJ("[ " + string(#args) + " ]", args)
void LKJ(){ cerr << endl;}
template<typename I, typename...T> void LKJ(I&&x, T&&...t){ cerr<<x<<", ", LKJ(t...);}
template<typename I> void DE(I a, I b){ while(a < b) cerr << *a << " \n"[next(a) == b], ++a;}
#else
#define debug(...) 0
#define DE(...) 0
#endif
#ifdef OWO
void ComputeAdvice(int *C, int N, int K, int M); void WriteAdvice(unsigned char a);
int32_t main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n, m, k;
	cin >> n >> k >> m;
	int *c = new int[n];
	for(int i = 0; i < n; ++i) cin >> c[i];
	ComputeAdvice(c, n, k, m);
	return 0;
}
void WriteAdvice(unsigned char a){
	putchar(a + '0');
	putchar(' ');
}
#else
#include "advisor.h"
#endif
const int maxn = 1e5 + 225;
queue<int> app[maxn];
struct BIT{
	int val[maxn];
	void modify(int p, int v){
		++p;
		for(; p <= maxn; p += p & -p) val[p] += v;
	}
	void insert(int p){ modify(p, 1);}
	void erase(int p){ modify(p, -1);}
	int query(int p){
		++p;
		int ans = 0;
		for(; p > 0; p -= p & -p) ans += val[p];
		return ans;
	}
	int count(int p){
		return query(p) - query(p - 1);
	}
	int find(int p){
		return query(p);
	}
} s;
void ComputeAdvice(int *C, int N, int K, int M){
	int L = __lg(N - 1);
	
	for(int i = 0; i < N; ++i) app[C[i]].emplace(i);
	for(int i = 0; i < N; ++i) app[i].emplace(8e7);

	priority_queue<pii> pq;
	for(int i = 0; i < K; ++i) s.insert(i);
	for(int i = 0; i < K; ++i) pq.emplace(app[i].front(), i);

	auto wn = [&L](int a){
		for(int i = L; i >= 0; --i){
			WriteAdvice((a >> i & 1));
		}
	};
	for(int i = 0; i < N; ++i){
		int c = C[i]; app[c].pop();
		if(s.count(c) != 0){
			WriteAdvice(0);
			pq.emplace(app[c].front(), c);
			continue;
		}
		int eek;
		pii tp;
		do{
			tp = pq.top(); pq.pop();
			eek = tp.ss;
		} while(s.count(eek) == 0);
		int q = s.query(eek);
		debug(eek, q);
		WriteAdvice(1);
		wn(q);
		s.erase(eek);
		s.insert(c);
		pq.emplace(app[c].front(), c);
	}
}

//Knapsack DP is harder than FFT.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define ff first
#define ss second
#define pb emplace_back
#define FOR(i,n) for(int i = 0; i < (n); ++i)
#define FOO(i,a,b) for(int i = (a); i <= (b); ++i)
#define AI(x) (x).begin(),(x).end()
template<typename I> bool chmax(I &a, I b){ return a < b ? (a = b, true) : false;}
template<typename I> bool chmin(I &a, I b){ return a > b ? (a = b, true) : false;}
#ifdef OWO
#define debug(args...) LKJ("[ " + string(#args) + " ]", args)
void LKJ(){ cerr << endl;}
template<typename I, typename...T> void LKJ(I&&x, T&&...t){ cerr<<x<<", ", LKJ(t...);}
template<typename I> void DE(I a, I b){ while(a < b) cerr << *a << " \n"[next(a) == b], ++a;}
#else
#define debug(...) 0
#define DE(...) 0
#endif
#ifdef OWO
void Assist(unsigned char *A, int N, int K, int R); void PutBack(int T);
int GetRequest();
int32_t main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n, k, r; cin >> n >> k >> r;
	unsigned char * a = new unsigned char[r];
	for(int i = 0; i < r; ++i) cin >> a[i], a[i] -= '0';
	Assist(a, n, k, r);
	return 0;
}
int GetRequest(){
	const int a[4] = {2, 0, 3, 0};
	static int p = 0;
	return a[p++];
}
void PutBack(int T){
	cout << T << ' ';
}
#else
#include "assistant.h"
#endif
const int maxn = 1e5 + 225;
struct BIT{
	int val[maxn];
	void modify(int p, int v){
		++p;
		for(; p <= maxn; p += p & -p) val[p] += v;
	}
	void insert(int p){ modify(p, 1);}
	void erase(int p){ modify(p, -1);}
	int query(int p){
		++p;
		int ans = 0;
		for(; p > 0; p -= p & -p) ans += val[p];
		return ans;
	}
	int count(int p){
		return query(p) - query(p - 1);
	}
	int find(int p){
		return query(p);
	}
	int findk(int k){
		int l = 0, r = maxn - 1, m;
		while(l < r){
			m = (l + r) / 2;
			//debug(l, r, m, query(m));
			if(query(m) >= k) r = m;
			else l = m + 1;
		}
		return l;
	}
} s;
void Assist(unsigned char *A, int N, int K, int R){
	int L = __lg(N - 1);
	auto GC = [&](){
		static int p = 0;
		return (int)A[p++];
	};

	for(int i = 0; i < K; ++i) s.insert(i);
	for(int i = 0; i < N; ++i){
		int c = GetRequest();
		auto cmd = GC();
		//debug((int) cmd);
		if(cmd == 0) continue;
		int ans = 0;
		for(int i = 0; i <= L; ++i){
			ans = (ans << 1) | (GC());
		}
		int q = s.findk(ans);
		PutBack(q);
		s.erase(q);
		s.insert(c);
	} 
}

Compilation message

advisor.cpp: In function 'void ComputeAdvice(int*, int, int, int)':
advisor.cpp:20:20: warning: statement has no effect [-Wunused-value]
   20 | #define debug(...) 0
      |                    ^
advisor.cpp:93:3: note: in expansion of macro 'debug'
   93 |   debug(eek, q);
      |   ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 52 ms 68384 KB Output is correct
2 Correct 53 ms 68400 KB Output is correct
3 Correct 56 ms 68332 KB Output is correct
4 Correct 61 ms 68524 KB Output is correct
5 Incorrect 55 ms 68464 KB Error - advice is too long
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 78 ms 69048 KB Output is correct
2 Correct 189 ms 72188 KB Output is correct
3 Correct 412 ms 78108 KB Output is correct
4 Correct 543 ms 81920 KB Output is correct
5 Correct 521 ms 81100 KB Output is correct
6 Correct 448 ms 79116 KB Output is correct
7 Correct 377 ms 77252 KB Output is correct
8 Correct 404 ms 77852 KB Output is correct
9 Correct 515 ms 81516 KB Output is correct
10 Correct 341 ms 76452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 304 ms 75184 KB Output is correct
2 Correct 359 ms 76936 KB Output is correct
3 Correct 354 ms 76652 KB Output is correct
4 Correct 336 ms 76528 KB Output is correct
5 Correct 284 ms 75096 KB Output is correct
6 Correct 357 ms 77032 KB Output is correct
7 Correct 345 ms 76656 KB Output is correct
8 Correct 471 ms 79720 KB Output is correct
9 Correct 263 ms 74492 KB Output is correct
10 Correct 353 ms 76788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 54 ms 68196 KB Error - advice is too long
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 367 ms 77244 KB Output is partially correct - 975347 bits used
2 Correct 370 ms 76952 KB Output is partially correct - 941041 bits used
3 Correct 357 ms 77040 KB Output is partially correct - 907466 bits used
4 Correct 356 ms 76660 KB Output is partially correct - 906939 bits used
5 Correct 358 ms 77092 KB Output is partially correct - 905358 bits used
6 Correct 368 ms 77256 KB Output is partially correct - 907109 bits used
7 Correct 360 ms 77020 KB Output is partially correct - 905741 bits used
8 Correct 358 ms 76824 KB Output is partially correct - 908452 bits used
9 Correct 363 ms 76916 KB Output is partially correct - 907874 bits used
10 Correct 507 ms 79352 KB Output is partially correct - 1366636 bits used