This is actually the smallest spanning tree. Crying blind.
Remember that the parity of the prefix and pre[], to determine the parity of a point, it must be known pre[i] and pre[i-1], or pre[i+1] and pre[i] (not necessarily directly asked, in short, definitely know Pre[i]
If the parity of the sum of the query interval [l,r] is treated as an edge (L-1,r) (because it is pre[r]-pre[l-1]),
To know all the pre values, that is, by connecting the edges, all the points are connected to 0.
And then it becomes MST ...
1#include <cstdio>2#include <iostream>3#include <cstring>4#include <algorithm>5 #definell Long Long6 using namespacestd;7 Const intmaxn=2023;8 intDIS[MAXN],C[MAXN][MAXN];9 BOOLU[MAXN];Ten ll ans; One inti,j,k,n,m; A - intRaCharRx; -InlineintRead () { theRx=getchar (), ra=0; - while(rx<'0'|| Rx>'9') rx=GetChar (); - while(rx>='0'&&rx<='9') ra*=Ten, ra+=rx- -, Rx=getchar ();returnRA; - } +InlinevoidPrim () { - intMx;registerinti; +dis[0]=1e9; A for(i=1; i<=n;i++) dis[i]=c[0][i]; at for(intj=1; j<=n;j++){ -mx=0; for(i=1; i<=n;i++)if(!u[i]&&dis[i]<dis[mx]) mx=i; - //printf ("mx:%d dis:%d\n", mx,dis[mx]); -ans+=dis[mx],u[mx]=1; - for(i=1; i<=n;i++)if(!u[i]&&c[mx][i]<dis[i]) dis[i]=C[mx][i]; - } in } - intMain () { ton=read (); + for(i=1; i<=n;i++) for(j=i;j<=n;j++) c[i-1][j]=c[j][i-1]=read (); - Prim (); theprintf"%lld\n", ans); * } $ View Code
[bzoj3714] [PA2014] Kuglarz