Click here to enter the competition
\ (A \) : Killer Queen ( Click here to see the problem surface )
Roughly meaning of the questions: find the lexicographically smallest string.
There is always a game to send sub-themes. . .
#include<bits/stdc++.h>
#define Tp template<typename Ty>
#define Ts template<typename Ty,typename... Ar>
#define Reg register
#define RI Reg int
#define Con const
#define CI Con int&
#define I inline
#define W while
using namespace std;
int n;string s;
int main()
{
RI i;string st;for(cin>>n>>s,i=2;i<=n;++i) cin>>st,st<s&&(s=st,0);//读入,求字典序最小字符串
return cout<<s<<endl,0;//输出
}
\ (B \) : Support City ( Click here to see the problem surface )
Generally meaning of problems: For each \ (X \) , seeking \ (\ sum_. 1} ^ {n-I = (a_i-a_x) 2 ^ \) .
Demolition of the squares:
\ [\ Sum_ {i = 1} ^ n (a_i '2-2a_ia_x a_x + 2) = \ sum_ {i = 1}' 'na_i 2-2a_x \ sum_ {i = 1} ^ + na_i na_x 2 \ ]
Difficult to find, as long as the pretreatment \ (\ sum_ {i = 1 } ^ na_i ^ 2 \) and \ (\ sum_ = {I}. 1 na_i ^ \) , for each \ (X \) can be directly \ (O (1) \) is calculated.
#include<bits/stdc++.h>
#define Tp template<typename Ty>
#define Ts template<typename Ty,typename... Ar>
#define Reg register
#define RI Reg int
#define Con const
#define CI Con int&
#define I inline
#define W while
#define N 100000
#define LL long long
using namespace std;
int n,a[N+5];
int main()
{
RI i;LL s=0,s2=0;for(scanf("%d",&n),i=1;i<=n;++i) scanf("%d",a+i),s+=a[i],s2+=1LL*a[i]*a[i];//预处理和及平方和
for(i=1;i<=n;++i) printf("%lld ",s2-2*s*a[i]+1LL*n*a[i]*a[i]);return 0;//计算答案并输出
}
\ (C \) : Rune energy ( Click here to see surface title )
Generally meaning of the questions: you two arrays \ (A, B \) , the interval period may be selected \ ([L, R & lt] \) , so \ (L \ le i \ le R \) all \ (a_i, b_i \) multiplied by the \ (K \) , seeking \ (\ sum_ {i = 2 } a_i \) ^ nb_ {i-1} is a minimum value.
This can be directly \ (DP \) .
We set \ (F_i \) represents select comprising \ (I \) and \ (I \) the minimum change value is not the end of the period of the section can be obtained.
Transfer time division two cases discussed, one is \ (I \) in the interior region, the other is \ (I \) is the beginning of the interval:
\ [F_i = min (F_ {i-1} + cl {i-1} A_I (q ^ 2-1), cl {i-1} A_I (k-1)) \]
At the same time every time we use to \ (i \) for the end of the case to update the smallest change in value:
\ [Mn = min (n, f_ {i-1} + b_ {i-1} a_i (k-1)) \]
The final answer is the answer to the original value plus the minimum change.
#include<bits/stdc++.h>
#define Tp template<typename Ty>
#define Ts template<typename Ty,typename... Ar>
#define Reg register
#define RI Reg int
#define Con const
#define CI Con int&
#define I inline
#define W while
#define N 100000
#define LL long long
#define min(x,y) ((x)<(y)?(x):(y))
#define Gmin(x,y) (x>(y)&&(x=(y)))
using namespace std;
int n,k,a[N+5],b[N+5];LL f[N+5];
int main()
{
RI i;LL Mn=0,ans=0;for(scanf("%d%d",&n,&k),i=1;i<=n;++i) scanf("%d%d",a+i,b+i);//读入
for(i=1;i<=n+1;++i) Gmin(Mn,f[i-1]+b[i-1]*a[i]*(k-1)),//更新最小变化值
ans+=b[i-1]*a[i],f[i]=min(b[i-1]*a[i]*(k-1),f[i-1]+b[i-1]*a[i]*(k*k-1));//计算原先答案,并动态规划转移f[i]
return printf("%lld",ans+Mn),0;//输出答案
}
\ (D \) : Cai Cai vegetables ( Click here to see the problem surface )
Roughly meaning of the questions: to a directed graph, each time asking a range of values, find the point to no other point interval is directly connected to the right and within this range.
We define \ (L_i \) with the \ (I \) connected points numbering less than \ (I \) the maximum number, \ (r_i \) with the \ (I \) connected points in a number greater than \ (I \) the minimum number.
Set the current query interval \ ([L, R & lt] \) , then a point contributes a query, if and only if it satisfies:
\[l_i<L\le i\le R<r_i\]
which is:
\ [L_i + 1 \ W \ c \ R \ the r_i-1 \]
Then we can consider offline, you are asked to \ (L \) sort.
Then we enumerate \ (L \) , each time for all \ (l_i + 1 = L \ ) is \ (i \) , they meet the conditions, so a maintenance Fenwick tree, the \ (i \ sim r_i- 1 \) location will add \ (a_i \) .
Meanwhile, \ (. 1-L \) This location is not within the interrogation range, so we \ (L-1 \ sim r_ {L-1} -1 \) position subtracted \ (a_ {L-1} \) .
When asked just ask \ (a_R \) value to the position.
#include<bits/stdc++.h>
#define Tp template<typename Ty>
#define Ts template<typename Ty,typename... Ar>
#define Reg register
#define RI Reg int
#define Con const
#define CI Con int&
#define I inline
#define W while
#define N 1000000
#define swap(x,y) (x^=y^=x^=y)
#define Gmin(x,y) (x>(y)&&(x=(y)))
#define Gmax(x,y) (x<(y)&&(x=(y)))
using namespace std;
int n,m,Qt,a[N+5],l[N+5],r[N+5],L[N+5],R[N+5];
vector<int> s[N+5],q[N+5];vector<int>::iterator it;
class FastIO
{
private:
#define FS 100000
#define tc() (A==B&&(B=(A=FI)+fread(FI,1,FS,stdin),A==B)?EOF:*A++)
#define tn (x<<3)+(x<<1)
#define D isdigit(c=tc())
char c,*A,*B,FI[FS];
public:
I FastIO() {A=B=FI;}
Tp I void read(Ty& x) {x=0;W(!D);W(x=tn+(c&15),D);}
Ts I void read(Ty& x,Ar&... y) {read(x),read(y...);}
}F;
class TreeArray//树状数组
{
private:
#define lowbit(x) (x&-x)
int v[N+5];
I void Upt(RI x,CI y) {W(x<=n) v[x]+=y,x+=lowbit(x);}//修改后缀
public:
I void Add(CI l,CI r,CI v) {Upt(l,v),Upt(r+1,-v);}//区间修改,差分
I int Qry(RI x,RI t=0) {W(x) t+=v[x],x-=lowbit(x);return t;}//单点询问
}T;
int main()
{
RI i,x,y;long long ans=0;
for(F.read(n,m,Qt),i=1;i<=n;++i) F.read(a[i]),l[i]=0,r[i]=n+1;//初始化
for(i=1;i<=m;++i) F.read(x,y),x>y?Gmax(l[x],y):Gmin(r[x],y);//预处理l,r
for(i=1;i<=n;++i) s[l[i]].push_back(i);//对于l[i]开桶,方便后面的操作
for(i=1;i<=Qt;++i) F.read(L[i],R[i]),q[L[i]].push_back(i);//读入询问,并桶排
for(i=1;i<=n;++i)//枚举L
{
i^1&&(T.Add(i-1,r[i-1]-1,-a[i-1]),0);//删去L-1的贡献
for(it=s[i-1].begin();it!=s[i-1].end();++it) T.Add(*it,r[*it]-1,a[*it]);//对于所有l[i]+1=L的i,加上其贡献
for(it=q[i].begin();it!=q[i].end();++it) ans^=1LL*(*it)*T.Qry(R[*it]);//枚举R询问
}return printf("%lld",ans),0;
}
\ (E \) : Magic function ( Click here to see the problem surface )
Generally meaning of the questions: \ (D (X) \) of \ (X \) is greater than \ (1 \) minimum factor, \ (F (X) = \ Cases the begin {1} = X & \\ D 1 (X ) F (\ X FRAC {D (X) ^ 2}) & D (X) ^ 2 | X \\ F (\ X FRAC {D (X)}) & Others \ Cases End {} \) , seeking \ (\ sum_ = {I}. 1 ^ NF (I) \) .
We set \ (X = \ sum_ {I =. 1} ^ tp_i ^ {C_i} \) , then \ (f (x) = \ sum_ {i = 1} ^ tp_i ^ {\ lfloor \ frac {c_i} 2 \ } rfloor \) . Certify as follows:
For a \ (P_i \) , if the \ (C_i \ GE 2 \) , by \ (f (x) = d (x) f (\ frac x {d (x) ^ 2}) \ (d (x ) ^ 2 | x) \) will eliminate \ (X \) two \ (P_i \) , to give \ (f (x) \) of \ (1 \) a \ (P_i \) , That \ (C_i \) divided by the number \ (2 \) .
And if \ (. 1 C_i = \) , by \ (f (x) = f (\ frac x {d (x)}) \ others \) will put a \ (P_i \) disappear, i.e., in addition to in the two rounded down.
Then, \ (f (the n-) \) apparently \ (O (\ sqrt n) \) level.
So we can enumerate \ (F (I) \) , provided \ (g (x) \) represents \ (\ n 1 \ sim) the counted number of the square-free, the answer is:
\[\sum_{i=1}^{\sqrt n}i\cdot g(\lfloor\frac n{i^2}\rfloor)\]
Wherein \ (G \) significance is that, if a number containing a square factor \ (K ^ 2 \) , then its \ (F \) value would be \ (IK \) , it should not contain factor squared.
Then consider \ (G \) method for finding the value of inclusion and exclusion that may be used, and the volume coefficient is repellent \ (\ MU \) . and so:
\[g(x)=\sum_{i=1}^{\sqrt x}\mu(i)\lfloor\frac n{i^2}\rfloor\]
For the above answer, and here \ (G \) , we can use to quickly block division evaluated relatively, but it seems to be stuck. . .
So we have to pre-out \ (x \ le10 ^ 7 \ ) of \ (G (the X-) \) , so that we can before.
#include<bits/stdc++.h>
#define Tp template<typename Ty>
#define Ts template<typename Ty,typename... Ar>
#define Reg register
#define RI Reg int
#define Con const
#define CI Con int&
#define I inline
#define W while
#define LS 10000000
#define LL long long
using namespace std;
LL n;
template<int SZ> class LinearSieve//线性筛
{
private:
int Pt,P[SZ+5],mu[SZ+5];
public:
LL smu[SZ+5],smu2[SZ+5];
I LinearSieve()
{
RI i,j;for(mu[1]=1,i=2;i<=LS;++i)
for(!P[i]&&(mu[P[++Pt]=i]=-1),j=1;j<=Pt&&1LL*i*P[j]<=SZ;++j)
if(P[i*P[j]]=1,i%P[j]) mu[i*P[j]]=-mu[i];else break;
for(i=1;i<=LS;++i) smu[i]=smu[i-1]+mu[i],smu2[i]=smu2[i-1]+mu[i]*mu[i];//筛mu和以及平方和
}
};LinearSieve<LS> L;
I LL G(Con LL& x)
{
if(x<=LS) return L.smu2[x];RI l,r,sx=sqrt(x);LL res=0;//x较小时直接返回答案
for(l=1;l<=sx;l=r+1) r=sqrt(x/(x/(1LL*l*l))),res+=x/(1LL*l*l)*(L.smu[r]-L.smu[l-1]);//除法分块
return res;//返回答案
}
int main()
{
RI Tt,l,r,sn;LL ans=0;scanf("%d",&Tt);W(Tt--)
{
scanf("%lld",&n),sn=sqrt(n),ans=0;//读入
for(l=1;l<=sn;l=r+1) r=sqrt(n/(n/(1LL*l*l))),ans+=G(n/(1LL*l*l))*(l+r)*(r-l+1)>>1;//除法分块
printf("%lld\n",ans);//输出答案
}return 0;
}
\ (F \) : Gold Experience ( Click here to see the problem surface )
So difficult topic, I obviously will not do. . .
Leaving the pit to be filled.