Submission #1011314

# Submission time Handle Problem Language Result Execution time Memory
1011314 2024-06-30T10:18:28 Z parsadox2 Last supper (IOI12_supper) C++17
43 / 100
224 ms 19728 KB
#include <bits/stdc++.h>
#include "advisor.h"

#define F first
#define S second

using namespace std;

const int N = 1e5 + 10;
int n , m , k , ar[N] , lg;
vector <int> pos[N];

struct SEG{
	int sum[N << 2];
	void Add(int x , int node = 1 , int nl = 0 , int nr = n)
	{
		sum[node]++;
		if(nl + 1 == nr)
			return;
		int mid = (nl + nr) >> 1 , lc = node << 1 , rc = lc | 1;
		if(x < mid)
			Add(x , lc , nl , mid);
		else
			Add(x , rc , mid , nr);
	}
	void Rem(int x , int node = 1 , int nl = 0 , int nr = n)
	{
		sum[node]--;
		if(nl + 1 == nr)
			return;
		int mid = (nl + nr) >> 1 , lc = node << 1 , rc = lc | 1;
		if(x < mid)
			Rem(x , lc , nl , mid);
		else
			Rem(x , rc , mid , nr);
	}
	int Get_val(int x , int node = 1 , int nl = 0 , int nr = n)
	{
		if(nl + 1 == nr)
			return nl;
		int mid = (nl + nr) >> 1 , lc = node << 1 , rc = lc | 1;
		if(x <= sum[lc])
			return Get_val(x , lc , nl , mid);
		else
			return Get_val(x - sum[lc] , rc , mid , nr);
	}
	int Get_id(int x , int node = 1 , int nl = 0 , int nr = n)
	{
		if(nl + 1 == nr)
			return sum[node];
		int mid = (nl + nr) >> 1 , lc = node << 1 , rc = lc | 1;
		if(x < mid)
			return Get_id(x , lc , nl , mid);
		else
			return sum[lc] + Get_id(x , rc , mid , nr);
	}
	bool Ex(int x , int node = 1 , int nl = 0 , int nr = n)
	{
		if(nl + 1 == nr)
			return sum[node];
		int mid = (nl + nr) >> 1 , lc = node << 1 , rc = lc | 1;
		if(x < mid)
			return Ex(x , lc , nl , mid);
		else
			return Ex(x , rc , mid , nr);
	}
} seg;

void Print(int val)
{
	for(int i = 0 ; i < lg ; i++)
	{
		if((val >> i) & 1)
			WriteAdvice(1);
		else
			WriteAdvice(0);
	}
}

void ComputeAdvice(int *C, int nn, int kk, int mm) {
	n = nn;
	k = kk;
	m = mm;
	lg = 1;
	int tmp = 2;
	while(tmp < k)
	{
		lg++;
		tmp *= 2;
	}
	for(int i = 0 ; i < n ; i++)
	{
		ar[i] = C[i];
		pos[i].push_back(n + 1);
	}
	for(int i = n - 1 ; i > -1 ; i--)
	{
		pos[ar[i]].push_back(i);
	}
	set <pair<int , int>> st;
	for(int i = 0 ; i < k ; i++)
	{
		seg.Add(i);
		st.insert(make_pair(pos[i].back() , i));
	}
	for(int i = 0 ; i < n ; i++)  
	{
		if(!seg.Ex(ar[i]))
		{
			pos[ar[i]].pop_back();
			auto it = st.end();  it--;  auto now = *it;
			st.erase(now);
			int id_rem = seg.Get_id(now.S);
			id_rem--;
			seg.Rem(now.S);
			seg.Add(ar[i]);
			st.insert(make_pair(pos[ar[i]].back() , ar[i]));
			Print(id_rem);
		}
		else
		{
			st.erase(make_pair(pos[ar[i]].back() , ar[i]));
			pos[ar[i]].pop_back();
			st.insert(make_pair(pos[ar[i]].back() , ar[i]));
		}
	}
}



//
#include <bits/stdc++.h>
#include "assistant.h"

#define F first
#define S second

using namespace std;

const int N = 1e5 + 10;

int n2 , k2 , r2 , lg2;

struct SEG{
	int sum[N << 2];
	void Add(int x , int node = 1 , int nl = 0 , int nr = n2)
	{
		sum[node]++;
		if(nl + 1 == nr)
			return;
		int mid = (nl + nr) >> 1 , lc = node << 1 , rc = lc | 1;
		if(x < mid)
			Add(x , lc , nl , mid);
		else
			Add(x , rc , mid , nr);
	}
	void Rem(int x , int node = 1 , int nl = 0 , int nr = n2)
	{
		sum[node]--;
		if(nl + 1 == nr)
			return;
		int mid = (nl + nr) >> 1 , lc = node << 1 , rc = lc | 1;
		if(x < mid)
			Rem(x , lc , nl , mid);
		else
			Rem(x , rc , mid , nr);
	}
	int Get_val(int x , int node = 1 , int nl = 0 , int nr = n2)
	{
		if(nl + 1 == nr)
			return nl;
		int mid = (nl + nr) >> 1 , lc = node << 1 , rc = lc | 1;
		if(x <= sum[lc])
			return Get_val(x , lc , nl , mid);
		else
			return Get_val(x - sum[lc] , rc , mid , nr);
	}
	int Get_id(int x , int node = 1 , int nl = 0 , int nr = n2)
	{
		if(nl + 1 == nr)
			return sum[node];
		int mid = (nl + nr) >> 1 , lc = node << 1 , rc = lc | 1;
		if(x < mid)
			return Get_id(x , lc , nl , mid);
		else
			return sum[lc] + Get_id(x , rc , mid , nr);
	}
	bool Ex(int x , int node = 1 , int nl = 0 , int nr = n2)
	{
		if(nl + 1 == nr)
			return sum[node];
		int mid = (nl + nr) >> 1 , lc = node << 1 , rc = lc | 1;
		if(x < mid)
			return Ex(x , lc , nl , mid);
		else
			return Ex(x , rc , mid , nr);
	}
} seg2;

void Assist(unsigned char *ar, int nn, int kk, int rr) {
	n2 = nn;
	k2 = kk;
	r2 = rr;
	lg2 = 1;
	int tmp = 2;
	while(tmp < k2)
	{
		lg2++;
		tmp *= 2;
	}
	//cout << lg2 << endl;
	for(int i = 0 ; i < k2 ; i++)
		seg2.Add(i);
	int pos = 0;
	for(int i = 0 ; i < n2 ; i++)
	{
		int now = GetRequest();
		if(seg2.Ex(now))
			continue;
		int id = 0;
		for(int j = 0 ; j < lg2 ; j++)
		{
			if(ar[pos] == 1)
			{
				id |= (1 << j);
			}
			pos++;
		}
		id++;
		int bd = seg2.Get_val(id);
		PutBack(bd);
		seg2.Rem(bd);
		seg2.Add(now);
	}
}


//
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3100 KB Output is correct
2 Correct 1 ms 3112 KB Output is correct
3 Correct 2 ms 3100 KB Output is correct
4 Correct 3 ms 3304 KB Output is correct
5 Correct 6 ms 3412 KB Output is correct
6 Correct 8 ms 3644 KB Output is correct
7 Correct 4 ms 3672 KB Output is correct
8 Correct 9 ms 3748 KB Output is correct
9 Correct 10 ms 3732 KB Output is correct
10 Correct 7 ms 3700 KB Output is correct
11 Correct 8 ms 3708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 4600 KB Output is correct
2 Correct 74 ms 9480 KB Output is correct
3 Correct 200 ms 19088 KB Output is correct
4 Correct 155 ms 15312 KB Output is correct
5 Correct 182 ms 17240 KB Output is correct
6 Correct 216 ms 17560 KB Output is correct
7 Correct 175 ms 17672 KB Output is correct
8 Correct 168 ms 17340 KB Output is correct
9 Correct 122 ms 14620 KB Output is correct
10 Correct 166 ms 17268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 137 ms 14976 KB Output is correct
2 Correct 175 ms 17484 KB Output is correct
3 Correct 168 ms 17300 KB Output is correct
4 Correct 155 ms 16832 KB Output is correct
5 Correct 138 ms 15864 KB Output is correct
6 Correct 153 ms 17304 KB Output is correct
7 Correct 161 ms 17024 KB Output is correct
8 Correct 195 ms 19728 KB Output is correct
9 Correct 103 ms 15784 KB Output is correct
10 Correct 158 ms 17368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 3380 KB Error - advice is too long
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 176 ms 17484 KB Output is partially correct - 772365 bits used
2 Correct 184 ms 17420 KB Output is partially correct - 742095 bits used
3 Correct 160 ms 17388 KB Output is partially correct - 712470 bits used
4 Correct 188 ms 17368 KB Output is partially correct - 712005 bits used
5 Correct 166 ms 17344 KB Output is partially correct - 710610 bits used
6 Correct 174 ms 17392 KB Output is partially correct - 712155 bits used
7 Correct 166 ms 17360 KB Output is partially correct - 711090 bits used
8 Correct 177 ms 17368 KB Output is partially correct - 713340 bits used
9 Correct 175 ms 17152 KB Output is partially correct - 712830 bits used
10 Correct 224 ms 19564 KB Output is partially correct - 1117620 bits used