fork download
  1. #include <bits/stdc++.h>
  2. #define rep(_i, _j) for(int _i = 1; _i <= _j; ++_i)
  3. const int inf = 0x3f3f3f3f;
  4. typedef long long LL;
  5. typedef double DB;
  6. using namespace std;
  7. const int maxn = 10000 + 1000 + 100;
  8. int n, m, v[maxn];
  9. set<int> s0, s2;
  10. set<int>::iterator iter0, iter2;
  11. void change(int p, int d) {
  12. if(v[p] == 0) s0.erase(p);
  13. if(v[p] == 2) s2.erase(p);
  14. v[p] += d;
  15. printf("%d %d ", p, v[p]);
  16. if(v[p] == 0) s0.insert(p);
  17. if(v[p] == 2) s2.insert(p);
  18. }
  19. int main() {
  20. scanf("%d%d", &n, &m);
  21. ++n;
  22. for(int i = 0; i < n + m; ++i) {
  23. s0.insert(i);
  24. v[i] = 0;
  25. }
  26. s2.insert(n + m);
  27. for(int i = 1, p; i <= m; ++i) {
  28. scanf("%d", &p);
  29. iter2 = s2.upper_bound(p);
  30. iter0 = s0.upper_bound(*iter2);
  31. --iter0;
  32. if(*iter0 <= p) {
  33. printf("3 ");
  34. change(p, 1);
  35. change(*iter2, -2);
  36. change(*iter2 + 1, +1);
  37. } else if(v[p] > 0) {
  38. printf("2 ");
  39. change(p, -1);
  40. change(p + 1, 1);
  41. } else {
  42. printf("1 ");
  43. change(p, 1);
  44. }
  45. puts("");
  46. }
  47.  
  48. return 0;
  49. }
  50.  
Success #stdin #stdout 0s 3524KB
stdin
5 
6 
0 0 0 1 0 0 
stdout
1 0 1 
2 0 0 1 1 
1 0 1 
2 1 0 2 1 
2 0 0 1 1 
1 0 1