fork download
  1. #include <bits/stdc++.h>
  2. #define f(i,a,b) for(int i = (a); i <= (b); i++)
  3. #define pb push_back
  4.  
  5. using namespace std;
  6.  
  7. int C[1000005], N, M;
  8. unordered_map<int,int> Cnt;
  9. vector<int> IDS[1000005];
  10.  
  11. int main()
  12. {
  13. cin >> N >> M;
  14.  
  15. int low = 1;
  16.  
  17. f(i,1,N)
  18. {
  19. f(j,1,M)
  20. {
  21. int id;
  22. scanf("%d", &id);
  23. int curr = Cnt[id];
  24. Cnt[id] = curr+1;
  25. C[curr]--, C[curr+1]++;
  26. IDS[curr+1].pb(id);
  27. low = min(low, curr+1);
  28. }
  29.  
  30. while(!C[low]) low++;
  31. while(Cnt[IDS[low].back()] != low) IDS[low].pop_back();
  32. printf("%d\n", IDS[low].back());
  33. }
  34. }
  35.  
Success #stdin #stdout 0.01s 19088KB
stdin
Standard input is empty
stdout
Standard output is empty