Codeforces edu Round3

Source: Internet
Author: User

B. the best Gift

Emily ' s birthday is next week and Jack have decided to buy a present for her. He knows she loves books so he goes to the local bookshop, where there is n books on sale from one of m genres.

In the bookshop, Jack decides to buy both books of different genres.

Based on the genre of books on sale in the shop, find the number of options available to Jack for choosing both books of Di Fferent genres for Emily. Options is considered different if they differ in for least one book.

The books is given by indices of their genres. The genres is numbered from 1 to M.


The first line contains the positive integers n and m (2≤ n ≤2 105, 2≤ m ≤10)-the number of books in the bookstore and the number of genres.

The second line contains a sequence a1, a2, ..., an, where a< /c9>i (1≤ aim) equals the genre of the I-t H book.

It is guaranteed the for each genre there are at least one book of the that genre.


Print the only integer-the number of ways in which Jack can choose books.

It is guaranteed that the answer doesn ' t exceed the value 2 109.

Sample Test (s)Input
4 3
2 1 3 1

7 4
4 2 3 1 2 4 3

The answer to the first Test sample equals 5 as Sasha can choose:

    1. The first and second books,
    2. The first and third books,
    3. The first and fourth books,
    4. The second and third books,
    5. The third and fourth books.

Yes, I'm out of time ... Test19 must be a big data, but there's no way to optimize it at the moment. Take the pit and save it later.

1#include <stdio.h>2#include <stdlib.h>3 intbooks[20000];4 intMainintargcChar*argv[])5 {6     intn,m;7 __int64 ways;8      while(SCANF ("%d%d", &n,&m)! =EOF)9     {Tenways=0; One         inti,j; A         //For (i=0;i<n;i++) -             //scanf ("%d", &books[i]); -scanf"%d", &books[0]); the          for(i=1; i<n;i++) -         { -scanf"%d",&books[i]); -              for(j=0; j<i;j++) +             { -                 if(books[i]!=Books[j]) +ways++; A             } at         } -printf"%i64d\n", ways); -     } -     return 0; -}

Codeforces edu Round3

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.