Codeforces 547C Mike and Foam

Source: Internet
Author: User

Codeforces 547C Mike and Foam

 

Question:

Number of n and q operations

N number a1-an below

 

There is an empty set at the beginning.

Each operation has a number u (1 <= u <= n), which means to insert a [u] into the Set (if there is no a [u] in the set). otherwise, a [u] will be deleted from the set.

After each operation is completed, the number of logarithm numbers in the current set is output to each other.

 

Ideas:

Break down the quality factor, and then let us look at the number of non-mutual quality with a [u]. Just make a difference.

 

PS: cf ~

 

 

# Include
 
  
# Include
  
   
# Include
   
    
# Include
    
     
# Include
     
      
# Include
      # Include
       
         # Include
        
          # Include
         
           # Include
          
            # Include
           
             Using namespace std; template
            
              Inline bool rd (T & ret) {char c; int sgn; if (c = getchar (), c = EOF) return 0; while (c! = '-' & (C <'0' | c> '9') c = getchar (); sgn = (c = '-')? -1: 1; ret = (c = '-')? 0: (c-'0'); while (c = getchar (), c> = '0' & c <= '9 ') ret = ret * 10 + (c-'0'); ret * = sgn; return 1;} template
             
               Inline void pt (T x) {if (x <0) {putchar ('-'); x =-x;} if (x> 9) pt (x/10); putchar (x % 10 + '0');} typedef long ll; const int N = 5e5 + 10; int prime [N], primenum; // math has primenum prime numbers. h void PRIME (ll Max_Prime) {primenum = 0; prime [primenum ++] = 2; for (ll I = 3; I <= Max_Prime; I + = 2) for (ll j = 0; j
              
                Sqrt (double) I) | j = primenum-1) {prime [primenum ++] = I; break ;}} int n, q; int a [N]; vector
               
                 G [N]; ll ans; void pre (int u, int x) {for (int I = 0; prime [I] * prime [I] <= x; I ++) {if (x % prime [I] = 0) {while (x % prime [I] = 0) x/= prime [I]; G [u]. push_back (prime [I]) ;}} if (x! = 1) G [u]. push_back (x);} set
                
                  S; int f [N]; int c [N], top; void dfs (int t, int x, int cnt, int flag, int val) {if (t> = (int) G [x]. size () {if (cnt = 0) return; ans + = f [val] * flag; c [top ++] = val; return ;} dfs (t + 1, x, cnt, flag, val); dfs (t + 1, x, cnt + 1, flag *-1, val * G [x] [t]);} void p () {printf (set :); for (auto it: s) {printf (% d, it );} puts () ;}int one; int main () {PRIME (N); rd (n); rd (q); for (int I = 1; I <= n; I ++) {rd (a [I]); pre (I, a [I]);} ans = 0; one = 0; while (q --) {int u; rd (u); if (a [u] = 1) {if (s. count (u) {one --; s. erase (u); ans-= s. size ();} else {ans + = s. size (); one ++; s. insert (u) ;}} else {// printf (ans: % d, one: % d); p (); if (s. count (u) {s. erase (u); ans-= s. size (); top = 0; dfs (0, u, 0,-1, 1); ans --; // Delete the combination of yourself and yourself for (int I = 0; I <top; I ++) f [c [I] --;} else {ans + = s. size (); s. insert (u); top = 0; dfs (0, u, 0, 1, 1); for (int I = 0; I <top; I ++) f [c [I] ++ ;}} cout <; pt (ans); puts () ;}return 0 ;}
                
               
              
             
            
           
          
         
        
       
     
    
   
  
 


 

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.