Submission #623314

# Submission time Handle Problem Language Result Execution time Memory
623314 2022-08-05T12:43:46 Z Awerar Last supper (IOI12_supper) C++14
Compilation error
0 ms 0 KB
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <limits.h>
#include <math.h>
#include <chrono>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define p2 pair<ll, ll>
#define p3 tuple<ll,ll,ll>
#define p4 vi
#define ip3 tuple<int,int,int>
#define ip4 tuple<int,int,int,int>
#define vp2 vector<p2>
#define vp3 vector<p3>
#define inf 2e9
#define linf 1e17

#define read(a) cin >> a
#define write(a) cout << (a) << "\n"
#define dread(type, a) type a; cin >> a
#define dread2(type, a, b) dread(type, a); dread(type, b)
#define dread3(type, a, b, c) dread2(type, a, b); dread(type, c)
#define dread4(type, a, b, c, d) dread3(type, a, b, c); dread(type, d)
#define dread5(type, a, b, c, d, e) dread4(type, a, b, c, d); dread(type, e)
#ifdef _DEBUG
#define deb __debugbreak();
#else
#define deb ;
#endif

#define rep(i, high) for (ll i = 0; i < high; i++)
#define repp(i, low, high) for (ll i = low; i < high; i++)
#define repe(i, container) for (auto& i : container)
#define per(i, high) for (ll i = high; i >= 0; i--)

#define readpush(type,vect) type temp; read(temp); vect.push_back(temp);
#define readvector(type, name, size) vector<type> name(size); rep(i,size) {dread(type,temp); name[i]=temp;}
#define readinsert(type,a) {type temp; read(temp); a.insert(temp);}
#define all(a) begin(a),end(a)
#define setcontains(set, x) (set.find(x) != set.end())
#define stringcontains(str, x) (str.find(x) != string::npos)
#define within(a, b, c, d) (a >= 0 && a < b && c >= 0 && c < d)

#define ceildiv(x,y) ((x + y - 1) / y)
#define fract(a) (a-floor(a))
#define sign(a) ((a>0) ? 1 : -1)

#pragma region Advisor
void WriteAdvice(unsigned char a);

void ComputeAdvice(int *C, int N, int K, int M) {
    vector<set<int>> used_times(N);
    for(int i = 0; i < N; i++) used_times[C[i]].insert(i);
    for(int i = 0; i < N; i++) used_times[i].insert(inf + 1);

    set<int> scaffold;
    set<pair<int, int>> scaffold_use_times;
    for(int i = 0; i < K; i++) {
        scaffold.insert(scaffold.end(), i);
        scaffold_use_times.insert({*used_times[i].begin(), i});
    }

    vector<set<int>> removed_times(N);
    for(int i = 0; i < N; i++) removed_times[i].insert(inf);
    for(int i = 0; i < N; i++) {
        int curr = C[i];

        if(setcontains(scaffold, curr)) continue;

        int worst = (--scaffold_use_times.end())->second;
        scaffold_use_times.erase(--scaffold_use_times.end());
        scaffold.erase(worst);

        scaffold.insert(curr);
        scaffold_use_times.insert({*used_times[curr].upper_bound(i), curr});

        removed_times[worst].insert(i);
    }

    vector<bool> bits(N + K);
    for(int i = 0; i < K; i++) {
        int next_use = *used_times[i].begin();
        int next_remove = *removed_times[i].begin();

        bits[i] = next_remove < next_use;
    }

    for(int i = 0; i < N; i++) {
        int next_use = *used_times[C[i]].upper_bound(i);
        int next_remove = *removed_times[C[i]].upper_bound(i);

        bits[K + i] = next_remove < next_use;
    }

    for(bool b : bits) WriteAdvice(b);
}
#pragma endregion
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <limits.h>
#include <math.h>
#include <chrono>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define p2 pair<ll, ll>
#define p3 tuple<ll,ll,ll>
#define p4 vi
#define ip3 tuple<int,int,int>
#define ip4 tuple<int,int,int,int>
#define vp2 vector<p2>
#define vp3 vector<p3>
#define inf 2e9
#define linf 1e17

#define read(a) cin >> a
#define write(a) cout << (a) << "\n"
#define dread(type, a) type a; cin >> a
#define dread2(type, a, b) dread(type, a); dread(type, b)
#define dread3(type, a, b, c) dread2(type, a, b); dread(type, c)
#define dread4(type, a, b, c, d) dread3(type, a, b, c); dread(type, d)
#define dread5(type, a, b, c, d, e) dread4(type, a, b, c, d); dread(type, e)
#ifdef _DEBUG
#define deb __debugbreak();
#else
#define deb ;
#endif

#define rep(i, high) for (ll i = 0; i < high; i++)
#define repp(i, low, high) for (ll i = low; i < high; i++)
#define repe(i, container) for (auto& i : container)
#define per(i, high) for (ll i = high; i >= 0; i--)

#define readpush(type,vect) type temp; read(temp); vect.push_back(temp);
#define readvector(type, name, size) vector<type> name(size); rep(i,size) {dread(type,temp); name[i]=temp;}
#define readinsert(type,a) {type temp; read(temp); a.insert(temp);}
#define all(a) begin(a),end(a)
#define setcontains(set, x) (set.find(x) != set.end())
#define stringcontains(str, x) (str.find(x) != string::npos)
#define within(a, b, c, d) (a >= 0 && a < b && c >= 0 && c < d)

#define ceildiv(x,y) ((x + y - 1) / y)
#define fract(a) (a-floor(a))
#define sign(a) ((a>0) ? 1 : -1)

#pragma region Assistant
void PutBack(int T);
int GetRequest();

void Assist(unsigned char *A, int N, int K, int R) {
    int bits = getnumbits(N);

    set<int> scaffold;
    for(int i = 0; i < K; i++) {
        scaffold.insert(scaffold.end(), i);
    }

    stack<int> removable;
    for(int i = 0; i < K; i++) if(A[i]) removable.push(i);

    int q_index = 0;
    for(int i = 0; i < N; i++) {
        int curr = GetRequest();

        if(!setcontains(scaffold, curr)) {
            int old_col = removable.top();
            removable.pop();

            PutBack(old_col);

            scaffold.erase(old_col);
            scaffold.insert(curr);
        }

        if(A[K + q_index]) removable.push(curr);

        q_index++;
    }
}

#pragma endregion

Compilation message

advisor.cpp:18: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
   18 | #pragma GCC optimization ("O3")
      | 
advisor.cpp:19: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
   19 | #pragma GCC optimization ("unroll-loops")
      | 
advisor.cpp:64: warning: ignoring '#pragma region Advisor' [-Wunknown-pragmas]
   64 | #pragma region Advisor
      | 
advisor.cpp:113: warning: ignoring '#pragma endregion ' [-Wunknown-pragmas]
  113 | #pragma endregion
      | 

assistant.cpp:18: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
   18 | #pragma GCC optimization ("O3")
      | 
assistant.cpp:19: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
   19 | #pragma GCC optimization ("unroll-loops")
      | 
assistant.cpp:64: warning: ignoring '#pragma region Assistant' [-Wunknown-pragmas]
   64 | #pragma region Assistant
      | 
assistant.cpp:99: warning: ignoring '#pragma endregion ' [-Wunknown-pragmas]
   99 | #pragma endregion
      | 
assistant.cpp: In function 'void Assist(unsigned char*, int, int, int)':
assistant.cpp:69:16: error: 'getnumbits' was not declared in this scope
   69 |     int bits = getnumbits(N);
      |                ^~~~~~~~~~
assistant.cpp:69:9: warning: unused variable 'bits' [-Wunused-variable]
   69 |     int bits = getnumbits(N);
      |         ^~~~