# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
269564 | PeppaPig | Last supper (IOI12_supper) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "advisor.h"
#include <bits/stdc++.h>
#define pii pair<int, int>
#define x first
#define y second
using namespace std;
static const int N = 1e5 + 5;
static int t[N];
static void update(int x, int k) {
for(int i = x + 1; i < N; i += i & -i)
t[i] += k;
}
static int query(int x, int ret = 0) {
for(int i = x + 1; i; i -= i & -i)
ret += t[i];
return ret;
}
static int col[N];
void ComputeAdvice(int *C, int n, int k, int M) {
for(int i = 0; i < n; i++) col[i] = lower_bound(C, C + n, i) - C;
priority_queue<pii> Q;
for(int i = 0; i < k; i++) update(i, 1), Q.emplace(col[i], i);
for(int i = 0; i < n; i++) {
if(query(C[i]) - query(C[i] - 1) == 1)
for(int j = 0; j < 15; j++) WriteAdvice(0);
else {
pii now = Q.top(); Q.pop();
col[now.y] = lower_bound(C + i + 1, C + n, now.y) - C;
int idx = query(now.y);
for(int j = 0; j < 15; j++) WriteAdvice(idx >> j & 1);
col[C[i]] = lower_bound(C + i + 1, C + n, C[i]) - C;
Q.emplace(col[C[i]], C[i]);
}
}
}
#include "advisor.h"
#include <bits/stdc++.h>
#define pii pair<int, int>
#define x first
#define y second
using namespace std;
static const int N = 1e5 + 5;
static int t[N];
static void update(int x, int k) {
for(int i = x + 1; i < N; i += i & -i)
t[i] += k;
}
static int query(int x, int ret = 0) {
for(int i = x + 1; i; i -= i & -i)
ret += t[i];
return ret;
}
static int col[N];
void ComputeAdvice(int *C, int n, int k, int M) {
for(int i = 0; i < n; i++) col[i] = lower_bound(C, C + n, i) - C;
priority_queue<pii> Q;
for(int i = 0; i < k; i++) update(i, 1), Q.emplace(col[i], i);
for(int i = 0; i < n; i++) {
if(query(C[i]) - query(C[i] - 1) == 1)
for(int j = 0; j < 15; j++) WriteAdvice(0);
else {
pii now = Q.top(); Q.pop();
col[now.y] = lower_bound(C + i + 1, C + n, now.y) - C;
int idx = query(now.y);
for(int j = 0; j < 15; j++) WriteAdvice(idx >> j & 1);
col[C[i]] = lower_bound(C + i + 1, C + n, C[i]) - C;
Q.emplace(col[C[i]], C[i]);
}
}
}