Codeforces Round #470 (Div 2) B Math C two min + Tree array D dictionary tree

Source: Internet
Author: User

Codeforces Round #470

B. Primal Sport

Mathematical problems, X2 and X1 decomposition of the quality factor can be.

#include <bits/stdc++.h>using namespacestd;#pragmaComment (linker, "/stack:102400000,102400000")#defineRep (i,a,b) for (int i=a; i<=b; ++i)#definePer (i,b,a) for (int i=b; i>=a;-I.)#defineMes (A, b) memset (A,b,sizeof (a))#defineINF 0x3f3f3f3f#defineMP Make_pair#definePB push_back#defineFi first#defineSe SecondtypedefLong Longll;Const intN =200005;intP1[n], cnt1;void Get(intXint* p,int&num) {num=0;  for(intI=2; I&LT;=SQRT (x); ++i)if(x%i==0) {p[++num] =i;  while(x%i==0) x/=i; }    if(X >1) P[++num] =x;}intP2[n], Cnt2;intx2;intMain () {scanf ("%d", &x2); Get(x2, p1, cnt1); intAns =INF; Rep (I,1, Cnt1) {Rep (x1, x2-p1[i]+1, x2) {            Get(x1, p2, cnt2); Rep (L,1, Cnt2) {                if(x1-p2[l]+1>=3) ans= min (ans, x1-p2[l]+1); }}} printf ("%d\n", ans); return 0;}
View Code

C. Producing Snow

binary + Tree array, for v[i] look at the last day it consumes. Then the tree array interval is updated with a single point query.

#include <bits/stdc++.h>using namespacestd;#pragmaComment (linker, "/stack:102400000,102400000")#defineRep (i,a,b) for (int i=a; i<=b; ++i)#definePer (i,b,a) for (int i=b; i>=a;-I.)#defineMes (A, b) memset (A,b,sizeof (a))#defineINF 0x3f3f3f3f#defineMP Make_pair#definePB push_back#defineFi first#defineSe SecondtypedefLong Longll;Const intN =200005;intn;ll V[n], t[n], bit[n], sum[n], ans[n];voidADD (intx, ll y) {     for(; x<n; x+=x&-x) bit[x] + =y;} ll Sum (intx) {LL ret=0; for(; x; x-=x&-x) ret + = bit[x];returnret;}intMain () {scanf ("%d", &N); Rep (I,1, N) scanf ("%lld", &V[i]); Rep (I,1, N) scanf ("%lld", &t[i]), sum[i]=sum[i-1]+T[i]; Sum[n+1] =1e18; Rep (I,1, N) {        intpos = Upper_bound (sum+1, sum+n+2, sum[i-1]+v[i])-sum; Ans[pos]+ = V[i]-(sum[pos-1]-sum[i-1]); ADD (i,1), ADD (POS,-1); Ans[i]+ = Sum (i) *T[i]; } Rep (I,1, N) printf ("%lld%c", Ans[i],"\ n"[i==n]); return 0;}
View Code

D. Perfect Security

Dictionary Tree

Split into binary, first insert the second array into the trie tree, and then run the number in the first array in the Trie tree. Have the same bit on the same, not on the opposite.

#include <bits/stdc++.h>using namespacestd;#pragmaComment (linker, "/stack:102400000,102400000")#defineRep (i,a,b) for (int i=a; i<=b; ++i)#definePer (i,b,a) for (int i=b; i>=a;-I.)#defineMes (A, b) memset (A,b,sizeof (a))#defineINF 0x3f3f3f3f#defineMP Make_pair#definePB push_back#defineFi first#defineSe SecondtypedefLong Longll;Const intN =300005, M =5e6;void Get(int* Num,intx) {Rep (I,0, +) Num[i] =0;  for(intlen=1; X x>>=1, ++Len) {        if(x&1) Num[len] =1; }}intN, A[n], Pi;intnum[ *], tr[m][2], val[m], tot;voidInsert (intx) {    Get(num, x);  for(intu=0, i= +; I>0; --i) {if(Tr[u][num[i]] = =0) Tr[u][num[i]] = + +tot; ++Val[tr[u][num[i]]; U=Tr[u][num[i]]; }}intQueryintx) {    intRET =0; Get(num, x);  for(intu=0, i= +; I>0; --i) {intTMP = num[i]^1; if(Val[tr[u][num[i]] >0) {            --Val[tr[u][num[i]]; U=Tr[u][num[i]]; RET<<=1, ret + =Num[i]; }        Else {            --Val[tr[u][tmp]]; U=Tr[u][tmp]; RET<<=1, ret + =tmp; }    }    returnret;}intMain () {scanf ("%d", &N); Rep (I,1, N) scanf ("%d", &A[i]); Rep (I,1, N) scanf ("%d", &pi), Insert (PI); Rep (I,1, N) printf ("%d%c", query (A[i]) ^a[i],"\ n"[i==n]); return 0;}
View Code

Codeforces Round #470 (Div 2) B Math C two min + Tree array D dictionary tree

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.