Codeforces 691F Couple Cover violence

Source: Internet
Author: User

Analysis: Open an array of 300w, statistics, and then NLOGN statistics for each value in order to the first occurrence of the number of cases

Time complexity: O (NLOGN) n at 3e6 order of magnitude

#include <cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<iostream>#include<algorithm>using namespaceStd;typedefLong LongLL;Const intN =3e6;ConstLL mod = 1e9+7; LL N,m,sum[n+5],c[n+5];intMain () {scanf ("%i64d",&N); intmx=0;  for(intI=1; i<=n;++i) {    intX;SCANF ("%d", &x); + +C[x]; MX=Max (X,MX); }   for(intI=1; i<=mx;++i) {     for(intj=1; j<=mx;++j) {       if(1ll*i*j>n) Break; if(i==j) sum[i*j]+=c[i]* (c[i]-1); Elsesum[i*j]+=c[i]*C[j]; }  }   for(intI=1; i<=n;++i) sum[i]+=sum[i-1]; scanf ("%i64d",&m);  while(m--){    intp; scanf ("%d",&p); printf ("%i64d\n", N (n1)-sum[p-1]); }  return 0;}
View Code

Codeforces 691F Couple Cover violence

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: info-contact@alibabacloud.com 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.