fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define fst first
  5. #define snd second
  6.  
  7. typedef long long ll;
  8. typedef pair<int, int> ii;
  9.  
  10. const ll LINF = (ll)1e18;
  11. const int INF = (int)1e9;
  12.  
  13. const int N = (int)1e5 + 5;
  14. const int MAX_A = (int)1e9 + 5;
  15.  
  16. // In ra các giá trị có trong mảng a và số lần xuất hiện của nó
  17. // với 0 <= a[i] <= 10^9
  18.  
  19. int n;
  20. int a[N];
  21. // int cnt[MAX_A];
  22.  
  23. map<int, int> cnt;
  24. // bản chất là một mảng các <key, value>
  25. // key, value: kiểu dữ liệu gì cũng được!
  26. // tự động sắp xếp tăng dần theo key
  27. // truy cập tốn O(log) (hy sinh một chút so với vector (O(1)))
  28.  
  29. // cnt = {{2, 1}, {3, 2}, {1, 5}}
  30. //--> cnt = {{1, 5}, {2, 1}, {3, 2}}
  31.  
  32. int main() {
  33. ios::sync_with_stdio(0);
  34. cin.tie(0);
  35. cin >> n;
  36. for (int i = 0; i < n; i++) cin >> a[i], cnt[a[i]]++;
  37.  
  38. for (auto it : cnt) {
  39. cout << it.first << ' ' << it.second << '\n';
  40. }
  41. }
Success #stdin #stdout 0s 5296KB
stdin
Standard input is empty
stdout
Standard output is empty