Submission #45442

#TimeUsernameProblemLanguageResultExecution timeMemory
45442tjd229Last supper (IOI12_supper)C++11
0 / 100
127 ms7136 KiB
#include "advisor.h" int sz=1; struct NUse{ int ix; int nxt; bool operator<(NUse &nu) const{ return nxt < nu.nxt; } }q[125001]; void swap(int &a, int &b){ a ^= b ^= a ^= b; } void push(NUse nu){ q[sz] = nu; int curr = sz++; while (curr != 1){ if (q[curr>>1] < q[curr]){ swap(q[curr].ix, q[curr >> 1].ix); swap(q[curr].nxt, q[curr >> 1].nxt); } else break; curr >>= 1; } } void pop(){ q[1] = q[--sz]; int curr = 1; int nxt = 2; while (nxt < sz){ if (nxt + 1 < sz && q[nxt] < q[1+nxt]) nxt++; if (q[curr] < q[nxt]){ swap(q[curr].ix, q[nxt].ix); swap(q[curr].nxt, q[nxt].nxt); curr = nxt; nxt += nxt; } else break; } } void ComputeAdvice(int *C, int N, int K, int M) { int nxt[100000] = { 0 }; bool inq[100000] = { 0 }; int right[100000]; int future=0; int i; for (i = 0; i < N; i++) right[i] = 100001; for (i = N - 1; i >= 0; --i){ nxt[i] = right[C[i]]; right[C[i]] = i; } for (i = 0; i < K; i++) push({ i, right[i] }), inq[i] = 1; future = q[1].nxt; for (i = 0; i < K; i++) WriteAdvice(right[i]!=future); for (i = 0; i < N; i++){ while (!inq[q[1].ix]) pop(); if (!inq[C[i]]){ inq[q[1].ix] = 0; pop(); } push({ C[i], nxt[i] }); inq[C[i]] = 1; WriteAdvice(q[1].ix != C[i]); } /*WriteAdvice(0); WriteAdvice(1); WriteAdvice(2);*/ }
#include "assistant.h" struct Heap{ int sz = 1; int p[125001]; int ix[125001]; void swap(int &a, int &b){ a ^= b ^= a ^= b; } void push(int _p, int _ix){ p[sz] = _p; ix[sz] = _ix; int curr = sz++; while (curr != 1 && p[curr] < p[curr >> 1]){ swap(p[curr], p[curr >> 1]); swap(ix[curr], ix[curr >> 1]); curr >>= 1; } } void pop(){ p[1] = p[--sz]; ix[1] = ix[sz]; int curr = 1; int nxt = 2; while (nxt < sz){ if (nxt + 1 < sz&&p[nxt] > p[nxt + 1]) nxt++; if (p[curr]>p[nxt]){ swap(p[nxt], p[curr]); swap(ix[nxt], ix[curr]); curr = nxt; nxt += nxt; } else break; } } }pq; void Assist(unsigned char *A, int N, int K, int R) { int i; int a_ix = 0; bool inq[100000] = { 0 }; for (i = 0; i < K; i++){ pq.push(A[a_ix++],i); inq[i] = 1; } for (i = 0; i < N; i++){ int req = GetRequest(); while (!inq[pq.ix[1]]) pq.pop(); if (!inq[req]){ PutBack(pq.ix[1]); inq[pq.ix[1]] = 0; pq.pop(); } pq.push(A[a_ix++],req); inq[req] = 1; } }
#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...