fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. const int MAX_SIZE = 900000;
  5.  
  6. int main() {
  7. int n, m, v[MAX_SIZE + 1], front = 1; // Variabilă pentru a ține evidența primului element
  8. cin >> n >> m;
  9.  
  10. for (int i = 1; i <= n; ++i) {
  11. cin >> v[i];
  12. }
  13.  
  14. for (int j = 1; j <= m; ++j) {
  15. int k;
  16. cin >> k;
  17.  
  18. if (k == 1) { // Elimină primul element
  19. if (front <= n) {
  20. front++; // Simplu, mutăm indexul "front" cu 1
  21. }
  22. } else if (k == 2) { // Adaugă un element
  23. if (n < MAX_SIZE) {
  24. int x;
  25. cin >> x;
  26. n++;
  27. v[n] = x; // Adaugă la sfârșit
  28. }
  29. }
  30. }
  31.  
  32. // Calculăm dimensiunea efectivă a cozii
  33. int effectiveSize = n - front + 1;
  34. cout << effectiveSize << "\n";
  35.  
  36. // Afișăm elementele rămase în coadă
  37. for (int i = front; i <= n; ++i) {
  38. cout << v[i] << " ";
  39. }
  40. return 0;
  41. }
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
0