fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n, v[10000], m, k, x;
  6. cin >> n;
  7. for (int i = 1; i <= n; ++i) {
  8. cin >> v[i];
  9. }
  10. cin >> m;
  11. for (int j = 1; j <= m; ++j) {
  12. cin >> k;
  13. for (int i = 1; i <= n; ++i) {
  14. if (k == 1) {
  15. cin >> x;
  16. ++n;
  17. v[n] = x;
  18. }
  19. if (k == 2 ) {
  20. --n;
  21. }}
  22.  
  23. }
  24. cout << n << "\n ";
  25. for (int i = 1; i <= n; ++i) {
  26. cout << v[i] << " ";
  27. }
  28. return 0;
  29. }
Success #stdin #stdout 0.01s 5288KB
stdin
3
1 2 3 
4
2
2
2
1 9
-1
9


3
1 2 3
3
1 9
1 6
1 0
-6
1 2 3 9 6 0

3
1 2 3
4 
2
2
1 9
2
-1
1

3
1 2 3 
3
2
2
1 9
-2
1 9

3
1 2 3
4
2
2
2
1 0
-1
0


3
1 2 3
5
2
2
2
1 9
2
-0

3
1 2 3 
3
2
2
2
-0

7
5 -4 0 -7 7 7 2
5
2
1 100
2
1 0
1 3
-8
5 -4 0 -7 7 7 0 3

3
1 2 3 
6
1 9
1 9
1 9
1 9
1 9
1 9
-9
1 2 3 9 9 9 9 9 9
stdout
0