fork download
  1. #include "assistant.h"
  2. #include <queue>
  3. using namespace std;
  4.  
  5. #define MAXN 100005
  6.  
  7. static int in_scaffold[MAXN],first_active[MAXN],request_active[MAXN];
  8. static bool in_que[MAXN];
  9. static queue<int> que;
  10.  
  11. void Assist(unsigned char *A, int N, int K, int R)
  12. {
  13. int i,j,k,p=0;
  14. for (i=1;i<=K;i++) in_scaffold[i] = 1;
  15. for (i=1;i<=K;i++){
  16. first_active[i] = A[p++];
  17. if (!first_active[i]) in_que[i] = 1, que.push(i);
  18. }
  19. for (i=1;i<=N;i++) request_active[i] = A[p++];
  20. for (i=1;i<=N;i++){
  21. int req=GetRequest()+1;
  22. if (request_active[i]) in_que[req] = 0;
  23. if (!request_active[i] && !in_que[req]) in_que[req] = 1, que.push(req);
  24. if (in_scaffold[req]) continue;
  25. for (;;){
  26. k = que.front(); que.pop();
  27. if (in_que[k]) break;
  28. }
  29. in_que[k] = 0;
  30. in_scaffold[req] = 1;
  31. in_scaffold[k] = 0;
  32. PutBack(--k);
  33. }
  34. }
  35.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty