fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. const int N=1e6+4;
  4. long long a[N],b[N],n,m;
  5. set<long long>s1;
  6. set<long long>s2;
  7. set<long long>s3;
  8. int main()
  9. {
  10. ios_base::sync_with_stdio(false);
  11. cin.tie(0);cout.tie(0);
  12. cin>>n>>m;
  13. for(int i=1;i<=n;i++)
  14. {
  15. cin>>a[i];
  16. s1.insert(a[i]);
  17. s3.insert(a[i]);
  18. }
  19. for(int i=1;i<=m;i++)
  20. {
  21. cin>>b[i];
  22. s2.insert(b[i]);
  23. s3.insert(b[i]);
  24. }
  25. for(long long x : s2)
  26. {
  27. if(s1.count(x)) cout<<x<<" ";
  28. }
  29. cout<<endl;
  30. for(long long x : s3) cout<<x<<" ";
  31. return 0;
  32. }
  33.  
Success #stdin #stdout 0.01s 5448KB
stdin
Standard input is empty
stdout