#include "advisor.h"
#include <bits/stdc++.h>
using namespace std;
int FT[100005];
void add(int idx, int amt){
idx++;
while(idx < 100005){
FT[idx] += amt;
idx += idx & -idx;
}
}
int sum(int idx){
idx++;
int ret = 0;
while(idx > 0){
ret += FT[idx];
idx -= idx & -idx;
}
return ret;
}
int nxt[100005];
set<int> s[100005];
void ComputeAdvice(int *C, int N, int K, int M) {
// Compute everything in the morning.
// Remember only ordering of the removals.
for(int i = 0; i < N; i++){
s[C[i]].insert(i);
}
for(int i = 0; i < N; i++){
set<int>::iterator it = s[C[i]].upper_bound(i);
if(it == s[C[i]].end()){
nxt[i] = N;
}else{
nxt[i] = *it;
}
}
priority_queue<pair<int,int> > pq;
set<int> use;
vector<int> raw;
for(int i = 0; i < K; i++){
use.insert(i);
add(i,1);
if(s[i].empty())
pq.push(make_pair(N, i));
else
pq.push(make_pair(*s[i].begin(), i));
}
for(int i = 0; i < N; i++){
if(use.find(C[i]) != use.end()){
;
}else{
pair<int,int> cur = pq.top();
pq.pop();
raw.push_back(sum(cur.second));
use.erase(cur.second);
add(cur.second, -1);
use.insert(C[i]);
add(C[i], 1);
pq.push(make_pair(nxt[i], C[i]));
}
}
for(int i = 0; i < raw.size(); i++){
for(int j = 0; j < 15; j++){
if(raw[i] & (1 << j)){
WriteAdvice(1);
}else{
WriteAdvice(0);
}
}
}
}
#include "assistant.h"
#include <bits/stdc++.h>
using namespace std;
int FTS[100005];
void addS(int idx, int amt){
idx++;
while(idx < 100005){
FTS[idx] += amt;
idx += idx & -idx;
}
}
int sumS(int idx){
idx++;
int ret = 0;
while(idx > 0){
ret += FTS[idx];
idx -= idx & -idx;
}
return ret;
}
int getidx(int num){
int lo = 0;
int hi = 100003;
int mid;
while(lo < hi){
mid = (lo + hi)/2;
if(sumS(mid) < num){
lo = mid+1;
}else{
hi = mid;
}
}
return lo;
}
void Assist(unsigned char *A, int N, int K, int R) {
vector<int> dat;
for(int i = 0; i < R; i += 15){
int cur = 0;
for(int j = 0; j < 15; j++){
if(A[i+j]){
cur += 1 << j;
}
}
dat.push_back(cur);
}
set<int> use;
for(int i = 0; i < K; i++){
use.insert(i);
addS(i,1);
}
int idx = 0;
for(int i = 0; i < N; i++){
int cur = GetRequest();
if(use.find(cur) != use.end()) continue;
int now = dat[idx++];
int eidx = getidx(now);
PutBack(eidx);
use.erase(eidx);
addS(eidx, -1);
use.insert(cur);
addS(cur, 1);
}
}
Compilation message
advisor.cpp: In function 'void ComputeAdvice(int*, int, int, int)':
advisor.cpp:63:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < raw.size(); i++){
~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
9984 KB |
Output is correct |
2 |
Incorrect |
8 ms |
10240 KB |
Output isn't correct - not an optimal way |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
37 ms |
12272 KB |
Output isn't correct - not an optimal way |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
292 ms |
27424 KB |
Output isn't correct - not an optimal way |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
11 ms |
10752 KB |
Error - advice is too long |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
386 ms |
31280 KB |
Output isn't correct - not an optimal way |
2 |
Incorrect |
363 ms |
31376 KB |
Output isn't correct - not an optimal way |
3 |
Incorrect |
354 ms |
31176 KB |
Output isn't correct - not an optimal way |
4 |
Incorrect |
349 ms |
31112 KB |
Output isn't correct - not an optimal way |
5 |
Incorrect |
368 ms |
31112 KB |
Output isn't correct - not an optimal way |
6 |
Incorrect |
373 ms |
31104 KB |
Output isn't correct - not an optimal way |
7 |
Incorrect |
369 ms |
31136 KB |
Output isn't correct - not an optimal way |
8 |
Incorrect |
372 ms |
31416 KB |
Output isn't correct - not an optimal way |
9 |
Incorrect |
360 ms |
31104 KB |
Output isn't correct - not an optimal way |
10 |
Partially correct |
364 ms |
32208 KB |
Output is partially correct - 1117620 bits used |