Số Đặc Biệt

View as PDF

Submit solution

Points: 0.01
Time limit: 1.0s
Memory limit: 256M
Input: SDB.INP
Output: SDB.OUT

Author:
Problem types
Allowed languages
C, C++, Go, Java, Kotlin, Pascal, PyPy, Python, Rust, Scratch

Cho một dãy gồm ~N~ số nguyên ~A_1, A_2, ..., A_N~. Hãy đếm và đưa ra số lượng số đặc biệt trong dãy ~A~.

(Số đặc biệt là số chỉ xuất hiện đúng một lần trong dãy số)

Input

Dữ liệu vào từ tệp SDB.INP có cấu trúc:

  • Dòng đầu là số nguyên ~N~ (~0 < N \leq 10^6~).

  • ~N~ dòng tiếp theo, dòng thứ ~i~ chứa số nguyên ~A_i~ (~0 < i \leq N~, ~|A_i| \leq 10^9~).

Output

Ghi ra tệp SDB.OUT có cấu trúc:

  • Dòng đầu tiên ghi số lượng số đặc biệt.

  • Các dòng tiếp theo, mỗi dòng ghi một số đặc biệt (theo thứ tự tính từ đầu dãy ~A~).

Sample Input 1

8
9
9
7
7
6
11
9
5

Sample Output 1

3
6
11
5

Comments

Please read the guidelines before commenting.



  • 0
    kevinknguyen  commented on Feb. 5, 2026, 2:42 a.m.

    NHIỀU BÁC BỊ TLE THÌ NHỚ KHAI BÁO TRƯỚC SỐ LƯỢNG PHẦN TỬ CHO MAP NHÉ


  • 0
    pdinhvinh815  commented on Jan. 13, 2026, 12:42 a.m.

    dùng unordered_map tốt hơn code : https://ideone.com/E4t7kj


  • 2
    duongoi281012  commented on Dec. 7, 2025, 4:52 p.m.

    không biết unordered_map thì phải làm gì

    #include <bits/stdc++.h>
    #define ll long long
    using namespace std;
    const int maxn = 1000009;
    bool binary(int n, int a[], int x)
    {
        int l = 1, r = n;
        while(l <= r)
        {
            int mid = l + (r - l) / 2;
            if(a[mid] == x) return 1;
            else if(a[mid] < x) l = mid + 1;
            else r = mid - 1;
        }
        return 0;
    }
    int a[maxn], b[maxn], c[maxn];
    int main()
    {
        freopen("SDB.INP", "r", stdin);
        freopen("SDB.OUT", "w", stdout);
        ios_base :: sync_with_stdio(0);
        cin.tie(NULL);
        int n;
        cin >> n;
        for(int i = 1; i <= n; i++) {cin >> a[i]; b[i] = a[i];}
        sort(b + 1, b + 1+ n);
        int dem = 1;
        for(int i = 1; i <= n; i++)
        {
            int j = i + 1;
            while(j <= n && b[j] == b[i]) j++;
            if(j - i == 1) c[dem++] = b[i];
            i = j - 1;
        }
        cout << dem - 1 << '\n';
        for(int i = 1; i <= n; i++)
        {
            if(binary(dem, c, a[i])) cout << a[i] << '\n';
        }
    }
    

  • 0
    tranhongminh21082007  commented on Nov. 21, 2025, 1:33 a.m.
    #include <bits/stdc++.h>
    using namespace std;
    #define ll long long
    unordered_map<ll,int> m;
    const ll N = 1e6+1;
    ll a[N];
    vector<ll> v;
    int main() {
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        // freopen("SDB.INP","r",stdin);
        // freopen("SBD.OUT","w",stdout);
        int n;cin>>n;
        for(int i=0;i&lt;n;i++) {
            cin>>a[i];
            m[a[i]]++;
        }
        for(int i=0;i&lt;n;i++) {
            if(m[a[i]] == 1) {
                v.push_back(a[i]);
            }
        }
        cout << v.size()<<"\n";
        for(int i:v) cout << i << "\n";
        return 0;
    }
    

  • -4
    lvnphong12qb  commented on Aug. 24, 2025, 7:18 a.m.

    finalllllllllllllllllllllllllllllllllllllllyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy im correct :sob:

    include<bits/stdc++.h>

    using namespace std; int main() { iosbase::syncwithstdio(false); cin.tie(NULL); cout.tie(NULL); freopen("SDB.inp","r",stdin); freopen("SDB.out","w",stdout); long long n,inp; cin>>n; vector<long long> order; unorderedmap<long long,int> mp ((int) 1e7); for (long long i = 0; i < n; i++) { cin>>inp; mp[inp]++; if (mp[inp] == 1) order.pushback(inp); // record first appearance } vector<long long> b; for (auto i : order) if (mp[i] == 1) b.pushback(i); cout<<b.size()<<endl; for (auto i : b) cout<<i<<endl; } <

    pre-alloc den 1e7 moi dung :broken-heart:


  • -7
    hohoanghai5042011  commented on July 14, 2025, 1:55 a.m.

    This comment is hidden due to too much negative feedback. Show it anyway.


  • 6
    lamboylom  commented on July 13, 2025, 6:39 a.m. edited

    NHIỀU BÁC BỊ TLE THÌ NHỚ KHAI BÁO TRƯỚC SỐ LƯỢNG PHẦN TỬ CHO MAP NHÉ


  • 2
    hailomathepuck  commented on May 15, 2025, 8:26 a.m.

    include <bits/stdc++.h>

    define ll long long

    using namespace std;

    vector<ll> res; unordered_map<ll, int> mp; const ll N = 1e6 + 1; ll n, a[N];

    int main() { freopen("SDB.INP", "r", stdin); freopen("SDB.OUT", "w", stdout); ios::syncwithstdio(NULL); cin.tie(NULL); cout.tie(NULL);

    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        mp[a[i]]++;
    }
    for (int i = 1; i <= n; i++) {
        if (mp[a[i]] == 1) res.push_back(i);
    }
    cout << res.size() << '\n';
    for (int i : res) cout << a[i] << '\n';
    

    }


  • -1
    giaphudthw123  commented on May 6, 2025, 2:13 a.m.

    code full cho anh em

    include <bits/stdc++.h>

    using namespace std; unorderedmap<long long,int>m; vector<long long>a,b; long long n,temp; int main(){ iosbase::syncwithstdio(false); cin.tie(NULL); cout.tie(NULL); freopen("SDB.INP","r",stdin); freopen("SDB.OUT","w",stdout); cin>>n; while(n--){ cin>>temp; m[temp]++; a.pushback(temp); } for(int i=0;i<a.size();i++) if(m[a[i]]==1)b.pushback(i); cout<<b.size()<<"\n"; for(int i:b)cout<<a[i]<<"\n"; }


  • 0
    longlph23it  commented on May 5, 2025, 8:06 a.m.

    cần code C++ giải full test case, được có 15 test mấy


  • 1
    Nam_Khuong2312  commented on April 23, 2025, 1:31 a.m. edited

    Py ko nổi ,đc 9 test:)


  • -5
    trungdzvcb  commented on April 12, 2025, 3:34 p.m.

    This comment is hidden due to too much negative feedback. Show it anyway.


  • -6
    hungnguyen123  commented on April 7, 2025, 6:12 a.m.

    This comment is hidden due to too much negative feedback. Show it anyway.


    • -3
      HoangQuan_123  commented on April 12, 2025, 2:19 p.m.

      dùng unordered_map thì ko bị TLE á


    • -22
      75259Nguyen  commented on April 7, 2025, 6:23 a.m.

      This comment is hidden due to too much negative feedback. Show it anyway.