Submission #118606

#TimeUsernameProblemLanguageResultExecution timeMemory
118606PlurmLast supper (IOI12_supper)C++11
8 / 100
2559 ms12816 KiB
#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) { const int INF = 1e9; // 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] = INF; }else{ nxt[i] = *it; } } set<int> use; vector<int> raw; for(int i = 0; i < K; i++){ use.insert(i); add(i,1); } for(int i = 0; i < N; i++){ if(use.find(C[i]) != use.end()){ raw.push_back(K); }else{ int curuse = -1; int nxtpos = 0; for(set<int>::iterator it = use.begin(); it != use.end(); ++it){ int col = *it; set<int>::iterator nxt = s[col].upper_bound(i); if(nxt == s[col].end()){ curuse = col; break; } if(*nxt > nxtpos){ nxtpos = *nxt; curuse = col; } } raw.push_back(sum(curuse)); use.erase(curuse); add(curuse, -1); use.insert(C[i]); add(C[i], 1); } } for(int i = 0; i < raw.size(); i++){ for(int j = 0; j < 13; 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 += 13){ int cur = 0; for(int j = 0; j < 13; 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); } for(int i = 0; i < N; i++){ int cur = GetRequest(); if(use.find(cur) != use.end()) continue; int now = dat[i]; int eidx = getidx(now); PutBack(eidx); use.erase(eidx); addS(eidx, -1); use.insert(cur); addS(cur, 1); } }

Compilation message (stderr)

advisor.cpp: In function 'void ComputeAdvice(int*, int, int, int)':
advisor.cpp:70:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < raw.size(); i++){
                    ~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...