Số lần xuất hiện 2

View as PDF



Author:
Problem type
Points: 100 (p) Time limit: 1.0s Memory limit: 256M Input: stdin Output: stdout

Cho một dãy gồm \(n\) số nguyên dương \(A_1,A_2,\ldots,A_n\)..

Yêu cầu: Hãy in ra các phần tử của mảng theo thứ tự tăng dần cùng với số lần xuất hiện của chúng, các số trùng nhau thì chỉ ghi một lần.

Input

  • Dòng đầu chứa số \(n\) (\(n\leq 10^5\)).
  • Dòng thứ hai chứa n số nguyên dương \(A_1,A_2,\ldots,A_n\) (\(A_i\leq 10^6\)).

Output

  • Gồm \(n\) dòng, mỗi dòng ghi số hạng thứ \(A_i\) và số lần xuất hiện của chúng.

Example

Test 1

Input
9
2 3 1 2 3 4 5 4 3
Output
1 1
2 2
3 3
4 2
5 1

Comments

  • luonghuuhung16132013 8:17 a.m. 5 jan, 2025

    có ai biết cách làm bài này mà không bị tle không?

    • c2a3DuongNguyenNamHai 8:22 p.m. 20 dec, 2024

      from collections import Counter

      n = int(input())
      A = sorted(map(int, input().split()))

      x = Counter(A)
      for key, value in x.items():
      print(key, value)

      code auto đúm

      • tuan8cnc 9:47 p.m. 29 nov, 2024

        This comment is hidden due to too much negative feedback. Click here to view it.

        • duclong0090 8:18 p.m. 7 aug, 2024

          dùng set kết hợp với map

          • VMS_NC 10:56 a.m. 7 nov, 2023

            Py thì phải 3s chứ 1s sao đc cô ???

            • dejun 9:26 p.m. 5 oct, 2023 edited

              include <iostream>

              include <map>

              using namespace std;

              define X first

              define Y second

              int n, x;
              map<int, int> mp;

              int main() {
              cin >> n;
              for(int i = 0; i < n; cin >> x, ++mp[x], ++i);
              for(auto it : mp) cout << it.X << " " << it.Y << "\n";
              }

              • Cao_Duy_Anh 10:03 p.m. 16 aug, 2023

                hmmm mảng đánh dấu,tỉa vs sort :))

                • tupham 11:02 p.m. 20 jul, 2023

                  This comment is hidden due to too much negative feedback. Click here to view it.

                  • UserName 10:29 p.m. 26 may, 2023

                    cho hết vào map, xong việc :v

                    • khaidadao 9:31 p.m. 18 apr, 2023

                      mảng đánh dấu:vv

                      • 4 more comments