A:留坑

B:二维sg函数,特判边界情况

//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
//#pragma GCC optimize(4)
//#pragma GCC optimize("unroll-loops")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define fi first
#define se second
#define db double
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define ll long long
#define vi vector<int>
#define mod 1000000007
#define ld long double
//#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
//#define cd complex<double>
#define ull unsigned long long
//#define base 1000000000000000000
#define fin freopen("a.txt","r",stdin)
#define fout freopen("a.txt","w",stdout)
#define fio ios::sync_with_stdio(false);cin.tie(0)
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;}
inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}
template<typename T>inline T const& MAX(T const &a,T const &b){return a>b?a:b;}
template<typename T>inline T const& MIN(T const &a,T const &b){return a<b?a:b;}
inline ll qp(ll a,ll b){ll ans=1;while(b){if(b&1)ans=ans*a%mod;a=a*a%mod,b>>=1;}return ans;}
inline ll qp(ll a,ll b,ll c){ll ans=1;while(b){if(b&1)ans=ans*a%c;a=a*a%c,b>>=1;}return ans;} using namespace std; const double eps=1e-8;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int N=100+10,maxn=200000+10,inf=0x3f3f3f3f; int sg[N][N],Hash[200];
int main()
{
for(int i=1;i<=100;i++)
{
for(int j=1;j<=100;j++)
{
if(i==j)continue;
memset(Hash,0,sizeof Hash);
for(int k=1;k<i;k++)if(i-k!=j)Hash[sg[i-k][j]]=1;
for(int k=1;k<j;k++)if(i!=j-k)Hash[sg[i][j-k]]=1;
for(int k=1;k<min(i,j);k++)if(i-k!=j-k)Hash[sg[i-k][j-k]]=1;
for(int k=0;;k++)
{
if(!Hash[k])
{
sg[i][j]=k;
break;
}
}
// printf("%d ",sg[i][j]);
}
// puts("");
}
int n,ans=0;scanf("%d",&n);
while(n--)
{
int x,y;scanf("%d%d",&x,&y);
if(x==y)return 0*puts("Y");
ans^=sg[x][y];
}
puts(ans?"Y":"N");
return 0;
}
/******************** ********************/

C:bit维护逆序对即可

//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
//#pragma GCC optimize(4)
//#pragma GCC optimize("unroll-loops")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define fi first
#define se second
#define db double
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define ll long long
#define vi vector<int>
#define mod 1000000007
#define ld long double
//#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
//#define cd complex<double>
#define ull unsigned long long
#define base 1000000000000000000
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
#define fin freopen("a.txt","r",stdin)
#define fout freopen("a.txt","w",stdout)
#define fio ios::sync_with_stdio(false);cin.tie(0)
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;}
inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}
template<typename T>inline T const& MAX(T const &a,T const &b){return a>b?a:b;}
template<typename T>inline T const& MIN(T const &a,T const &b){return a<b?a:b;}
inline ll qp(ll a,ll b){ll ans=1;while(b){if(b&1)ans=ans*a%mod;a=a*a%mod,b>>=1;}return ans;}
inline ll qp(ll a,ll b,ll c){ll ans=1;while(b){if(b&1)ans=ans*a%c;a=a*a%c,b>>=1;}return ans;} using namespace std; const double eps=1e-8;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int N=4e5+10,maxn=1000000+10,inf=0x3f3f3f3f; struct bit{
int sum[N];
void init(){memset(sum,0,sizeof sum);}
void update(int i)
{
for(;i<N;i+=i&(-i))sum[i]++;
}
int query(int i)
{
int ans=0;
for(;i;i-=i&(-i))ans+=sum[i];
return ans;
}
}b;
pii x[N],y[N];
int Hash[N],cnt;
int main()
{
int xx,yy,h,v;scanf("%d%d%d%d",&xx,&yy,&h,&v);
for(int i=1;i<=h;i++)scanf("%d%d",&x[i].fi,&x[i].se),Hash[cnt++]=x[i].fi,Hash[cnt++]=x[i].se;
sort(x+1,x+1+h);sort(Hash,Hash+cnt);cnt=unique(Hash,Hash+cnt)-Hash;
for(int i=1;i<=h;i++)
{
x[i].fi=lower_bound(Hash,Hash+cnt,x[i].fi)-Hash+1;
x[i].se=lower_bound(Hash,Hash+cnt,x[i].se)-Hash+1;
}
cnt=0;
for(int i=1;i<=v;i++)scanf("%d%d",&y[i].fi,&y[i].se),Hash[cnt++]=y[i].fi,Hash[cnt++]=y[i].se;
sort(y+1,y+1+v);sort(Hash,Hash+cnt);cnt=unique(Hash,Hash+cnt)-Hash;
for(int i=1;i<=v;i++)
{
y[i].fi=lower_bound(Hash,Hash+cnt,y[i].fi)-Hash+1;
y[i].se=lower_bound(Hash,Hash+cnt,y[i].se)-Hash+1;
}
ll c=0,d=0;
for(int i=1;i<=h;i++)
{
c+=b.query(N-1)-b.query(x[i].se);
b.update(x[i].se);
}
b.init();
for(int i=1;i<=v;i++)
{
d+=b.query(N-1)-b.query(y[i].se);
b.update(y[i].se);
}
printf("%lld\n",1ll*(h+1)*(v+1)+c+d);
return 0;
}
/******************** ********************/

D:签到

//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
//#pragma GCC optimize(4)
//#pragma GCC optimize("unroll-loops")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define fi first
#define se second
#define db double
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define ll long long
#define vi vector<int>
#define mod 1000000007
#define ld long double
#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
//#define cd complex<double>
#define ull unsigned long long
//#define base 1000000000000000000
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
#define fin freopen("a.txt","r",stdin)
#define fout freopen("a.txt","w",stdout)
#define fio ios::sync_with_stdio(false);cin.tie(0)
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;}
inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}
template<typename T>inline T const& MAX(T const &a,T const &b){return a>b?a:b;}
template<typename T>inline T const& MIN(T const &a,T const &b){return a<b?a:b;}
inline ll qp(ll a,ll b){ll ans=1;while(b){if(b&1)ans=ans*a%mod;a=a*a%mod,b>>=1;}return ans;}
inline ll qp(ll a,ll b,ll c){ll ans=1;while(b){if(b&1)ans=ans*a%c;a=a*a%c,b>>=1;}return ans;} using namespace std; const double eps=1e-8;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int N=20200+10,maxn=200000+10,inf=0x3f3f3f3f; int main()
{
int _,x,ans=0;
for(scanf("%d",&_);_;_--)
{
scanf("%d",&x);
if(x!=1)ans++;
}
printf("%d\n",ans);
return 0;
}
/******************** ********************/

E:签到

//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
//#pragma GCC optimize(4)
//#pragma GCC optimize("unroll-loops")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define fi first
#define se second
#define db double
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define ll long long
#define vi vector<int>
#define mod 1000000007
#define ld long double
#define C 0.5772156649
//#define ls l,m,rt<<1
//#define rs m+1,r,rt<<1|1
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
//#define cd complex<double>
#define ull unsigned long long
//#define base 1000000000000000000
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
#define fin freopen("a.txt","r",stdin)
#define fout freopen("a.txt","w",stdout)
#define fio ios::sync_with_stdio(false);cin.tie(0)
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;}
inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}
template<typename T>inline T const& MAX(T const &a,T const &b){return a>b?a:b;}
template<typename T>inline T const& MIN(T const &a,T const &b){return a<b?a:b;}
inline ll qp(ll a,ll b){ll ans=1;while(b){if(b&1)ans=ans*a%mod;a=a*a%mod,b>>=1;}return ans;}
inline ll qp(ll a,ll b,ll c){ll ans=1;while(b){if(b&1)ans=ans*a%c;a=a*a%c,b>>=1;}return ans;} using namespace std; const double eps=1e-8;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int N=10000+10,maxn=200000+10,inf=0x3f3f3f3f; char s[N],p[N];
int main()
{
scanf("%s%s",s,p);
int ls=strlen(s),ps=strlen(p),ans=0;
for(int i=0;i+ps-1<ls;i++)
{
bool f=0;
for(int j=0;j<ps;j++)if(s[i+j]==p[j]){f=1;break;}
if(!f)ans++;
}
printf("%d\n",ans);
return 0;
}
/******************** ********************/

F:注意到n很小,开(1<<n)个bit,把区间离散化后按左端点排序,bit维护区间最小值更新即可

//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
//#pragma GCC optimize(4)
//#pragma GCC optimize("unroll-loops")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define fi first
#define se second
#define db double
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define ll long long
#define vi vector<int>
#define mod 1000000007
#define ld long double
#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
//#define cd complex<double>
#define ull unsigned long long
//#define base 1000000000000000000
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
#define fin freopen("a.txt","r",stdin)
#define fout freopen("a.txt","w",stdout)
#define fio ios::sync_with_stdio(false);cin.tie(0)
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;}
inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}
template<typename T>inline T const& MAX(T const &a,T const &b){return a>b?a:b;}
template<typename T>inline T const& MIN(T const &a,T const &b){return a<b?a:b;}
inline ll qp(ll a,ll b){ll ans=1;while(b){if(b&1)ans=ans*a%mod;a=a*a%mod,b>>=1;}return ans;}
inline ll qp(ll a,ll b,ll c){ll ans=1;while(b){if(b&1)ans=ans*a%c;a=a*a%c,b>>=1;}return ans;} using namespace std; const double eps=1e-8;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int N=2000+10,maxn=100000+10,inf=0x3f3f3f3f; struct bit{
int sum[N];
bit(){memset(sum,-1,sizeof sum);}
void update(int i,int x)
{
for(;i<N;i+=i&(-i))sum[i]=max(sum[i],x);
}
int query(int i)
{
int ma=-1;
for(;i;i-=i&(-i))ma=max(ma,sum[i]);
return ma;
}
}b[N];
struct node{
int s,t,v,id;
bool operator <(const node&rhs)const
{
return s<rhs.s || s==rhs.s&&t<rhs.t;
}
}p;
vector<node>v;
int Hash[N],cnt;
int main()
{
b[0].update(1,0);
int n;scanf("%d",&n);
for(int i=0,k;i<n;i++)for(scanf("%d",&k);k;k--)
{
scanf("%d%d%d",&p.s,&p.t,&p.v),p.id=i,v.pb(p);
Hash[cnt++]=p.s,Hash[cnt++]=p.t;
}
sort(Hash,Hash+cnt);cnt=unique(Hash,Hash+cnt)-Hash;
sort(v.begin(),v.end());
for(int i=0;i<v.size();i++)
{
p=v[i];
p.s=lower_bound(Hash,Hash+cnt,p.s)-Hash+1;
p.t=lower_bound(Hash,Hash+cnt,p.t)-Hash+1;
// printf("%d %d %d %d %d\n",p.s,p.t,p.v,p.id,b[7].query(8));
for(int j=0;j<(1<<n);j++)
{
int x=b[j].query(p.s);
if(x!=-1)b[j|(1<<p.id)].update(p.t,x+p.v);
// if(x!=-1&&(j|(1<<p.id))==7)printf("%d %d %d!!!!\n",p.s,p.t,x+p.v);
// if(j==5&&p.s==7&&p.id==1)printf("%d %d %d***\n",x+p.v,b[5].query(p.s),b[7].query(p.t));
}
}
printf("%d\n",b[(1<<n)-1].query(N-1));
return 0;
}
/******************** ********************/

G:二分,加最大流,二分图复杂度完全可以接受

//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
//#pragma GCC optimize(4)
//#pragma GCC optimize("unroll-loops")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define fi first
#define se second
#define db double
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define ll long long
#define vi vector<int>
#define mod 1000000007
#define ld long double
//#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
//#define cd complex<double>
#define ull unsigned long long
//#define base 1000000000000000000
#define fin freopen("a.txt","r",stdin)
#define fout freopen("a.txt","w",stdout)
#define fio ios::sync_with_stdio(false);cin.tie(0)
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;}
inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}
template<typename T>inline T const& MAX(T const &a,T const &b){return a>b?a:b;}
template<typename T>inline T const& MIN(T const &a,T const &b){return a<b?a:b;}
inline ll qp(ll a,ll b){ll ans=1;while(b){if(b&1)ans=ans*a%mod;a=a*a%mod,b>>=1;}return ans;}
inline ll qp(ll a,ll b,ll c){ll ans=1;while(b){if(b&1)ans=ans*a%c;a=a*a%c,b>>=1;}return ans;} using namespace std; const double eps=1e-8;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int N=2000+10,maxn=50000+10,inf=0x3f3f3f3f; int p,r,c,d[N],E[N],ans;
struct node{
int a,b,c;
bool operator <(const node&rhs)const
{
return c<rhs.c;
}
}f[maxn];
struct edge{
int to,Next,c;
}e[maxn];
int s,t,cnt,head[N],cur[N],dis[N];
void init(){cnt=0;memset(head,-1,sizeof head);}
void add(int u,int v,int c)
{
e[cnt].to=v;e[cnt].c=c;e[cnt].Next=head[u];head[u]=cnt++;
e[cnt].to=u;e[cnt].c=0;e[cnt].Next=head[v];head[v]=cnt++;
}
bool bfs()
{
queue<int>q;
memset(dis,-1,sizeof dis);
dis[s]=1;
q.push(s);
while(!q.empty())
{
int x=q.front();q.pop();
for(int i=head[x];~i;i=e[i].Next)
{
int y=e[i].to;
if(dis[y]==-1&&e[i].c>0)
{
dis[y]=dis[x]+1;
q.push(y);
}
}
}
return dis[t]!=-1;
}
int dfs(int u,int mx)
{
if(u==t)return mx;
int f;
for(int &i=cur[u];~i;i=e[i].Next)
{
int x=e[i].to;
if(dis[x]==dis[u]+1&&e[i].c>0&&(f=dfs(x,min(mx,e[i].c))))
{
e[i].c-=f;
e[i^1].c+=f;
return f;
}
}
return 0;
}
int maxflow()
{
int ans=0,f;
while(bfs())
{
for(int i=0;i<=t;i++)cur[i]=head[i];
while((f=dfs(s,inf)))ans+=f;
}
return ans;
}
bool ok(int x)
{
init();
for(int i=1;i<=p;i++)add(i,t,d[i]);
for(int i=1;i<=r;i++)add(s,p+i,E[i]);
for(int i=1;i<=c;i++)
{
if(f[i].c<=x)add(f[i].b+p,f[i].a,inf);
else break;
}
return maxflow()==ans;
}
int main()
{
scanf("%d%d%d",&p,&r,&c);
s=p+r+1,t=p+r+2;
for(int i=1;i<=p;i++)scanf("%d",&d[i]),ans+=d[i];
for(int i=1;i<=r;i++)scanf("%d",&E[i]);
for(int i=1;i<=c;i++)
{
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
f[i]={a,b,c};
}
sort(f+1,f+1+c);
int l=0,r=f[c].c+1;
while(l<r-1)
{
int m=(l+r)>>1;
if(ok(m))r=m;
else l=m;
}
printf("%d\n",(r<=f[c].c)?r:-1);
return 0;
}
/********************
3 2 5
20 10 10
25 30
1 1 3
2 1 1
2 2 4
3 1 2
3 2 5
********************/

H:留坑

I:按题意模拟即可,bitset优化

//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
//#pragma GCC optimize(4)
//#pragma GCC optimize("unroll-loops")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define fi first
#define se second
#define db double
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define ll long long
#define vi vector<int>
#define mod 1000000007
#define ld long double
//#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
//#define cd complex<double>
#define ull unsigned long long
//#define base 1000000000000000000
#define fin freopen("a.txt","r",stdin)
#define fout freopen("a.txt","w",stdout)
#define fio ios::sync_with_stdio(false);cin.tie(0)
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;}
inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}
template<typename T>inline T const& MAX(T const &a,T const &b){return a>b?a:b;}
template<typename T>inline T const& MIN(T const &a,T const &b){return a<b?a:b;}
inline ll qp(ll a,ll b){ll ans=1;while(b){if(b&1)ans=ans*a%mod;a=a*a%mod,b>>=1;}return ans;}
inline ll qp(ll a,ll b,ll c){ll ans=1;while(b){if(b&1)ans=ans*a%c;a=a*a%c,b>>=1;}return ans;} using namespace std; const double eps=1e-8;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int N=1000+10,maxn=200000+10,inf=0x3f3f3f3f; bitset<1010>b[N],c;
int main()
{
int n,m,k,x;
scanf("%d%d%d",&n,&m,&k);
for(int i=0;i<k;i++)scanf("%d",&x),c.set(x);
for(int i=1;i<=n;i++)
{
scanf("%d",&k);
while(k--)scanf("%d",&x),b[i].set(x);
}
for(int i=1;i<=n;i++)
{
c^=b[i];
if(c.count()==0)return 0*printf("%d\n",i);
}
for(int i=1;i<=n;i++)
{
c^=b[i];
if(c.count()==0)return 0*printf("%d\n",i+n);
}
puts("-1");
return 0;
}
/******************** ********************/

J:斯坦纳树,spfa更新时,只更新后n-k个点,保证不会出现capitals节点连capitals节点

//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
//#pragma GCC optimize(4)
//#pragma GCC optimize("unroll-loops")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define fi first
#define se second
#define db double
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define ll long long
#define vi vector<int>
#define mod 1000000007
#define ld long double
//#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
//#define cd complex<double>
#define ull unsigned long long
//#define base 1000000000000000000
#define fin freopen("a.txt","r",stdin)
#define fout freopen("a.txt","w",stdout)
#define fio ios::sync_with_stdio(false);cin.tie(0)
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;}
inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}
template<typename T>inline T const& MAX(T const &a,T const &b){return a>b?a:b;}
template<typename T>inline T const& MIN(T const &a,T const &b){return a<b?a:b;}
inline ll qp(ll a,ll b){ll ans=1;while(b){if(b&1)ans=ans*a%mod;a=a*a%mod,b>>=1;}return ans;}
inline ll qp(ll a,ll b,ll c){ll ans=1;while(b){if(b&1)ans=ans*a%c;a=a*a%c,b>>=1;}return ans;} using namespace std; const double eps=1e-8;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int N=100+10,maxn=200000+10,inf=0x3f3f3f3f; int x[N],y[N],n,k;
db dp[N][(1<<10)+10];
queue<int>q;
bool vis[N];
db cal(int a,int b){return sqrt(1.0*(x[a]-x[b])*(x[a]-x[b])+(y[a]-y[b])*(y[a]-y[b]));}
void spfa(int st)
{
while(!q.empty())
{
int p=q.front();q.pop();
vis[p]=0;
for(int i=k;i<n;i++)
{
if(i==p)continue;
db te=cal(p,i);
if(dp[p][st]+te<dp[i][st])
{
dp[i][st]=dp[p][st]+te;
q.push(i);
}
}
}
}
int main()
{
scanf("%d%d",&n,&k);
for(int i=0;i<n;i++)for(int j=0;j<(1<<k);j++)dp[i][j]=2e9;
for(int i=0;i<n;i++)
{
scanf("%d%d",&x[i],&y[i]);
if(i<k)dp[i][1<<i]=0;
}
for(int st=0;st<(1<<k);st++)
{
for(int i=0;i<n;i++)
{
for(int s=st;s;s=(s-1)&st)
if(dp[i][s]+dp[i][st-s]<dp[i][st])
dp[i][st]=dp[i][s]+dp[i][st-s];
if(dp[i][st]<inf)q.push(i),vis[i]=1;
}
spfa(st);
}
db ans=2e9;
for(int i=k;i<n;i++)ans=min(ans,dp[i][(1<<k)-1]);
printf("%.5f\n",ans);
return 0;
}
/******************** ********************/

K:可以发现xy范围很小,两圆相交要满足R-r<=d,d最大是\(sqrt(2)*50\),那么我们按r sort之后,暴力枚举满足该条件的圆即可

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
//#pragma GCC optimize("unroll-loops")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define fi first
#define se second
#define db double
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define ll long long
#define vi vector<int>
#define mod 1000000007
#define ld long double
//#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
//#define cd complex<double>
#define ull unsigned long long
//#define base 1000000000000000000
#define fin freopen("a.txt","r",stdin)
#define fout freopen("a.txt","w",stdout)
#define fio ios::sync_with_stdio(false);cin.tie(0)
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;}
inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}
template<typename T>inline T const& MAX(T const &a,T const &b){return a>b?a:b;}
template<typename T>inline T const& MIN(T const &a,T const &b){return a<b?a:b;}
inline ll qp(ll a,ll b){ll ans=1;while(b){if(b&1)ans=ans*a%mod;a=a*a%mod,b>>=1;}return ans;}
inline ll qp(ll a,ll b,ll c){ll ans=1;while(b){if(b&1)ans=ans*a%c;a=a*a%c,b>>=1;}return ans;} using namespace std; const double eps=1e-8;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int N=150000+10,maxn=50000+10,inf=0x3f3f3f3f; struct circle{
db x,y,r;
void read(){scanf("%lf%lf%lf",&x,&y,&r);}
bool operator <(const circle&rhs)const{
return r<rhs.r;
}
}c[N];
bool ok(int i,int j)
{
db d=sqrt((c[i].x-c[j].x)*(c[i].x-c[j].x)+(c[i].y-c[j].y)*(c[i].y-c[j].y));
return c[j].r-c[i].r<d&&d<c[i].r+c[j].r;
}
int main()
{
int n,ans=0;
scanf("%d",&n);
for(int i=1;i<=n;i++)c[i].read();
sort(c+1,c+1+n);
for(int i=1;i<=n;i++)
{
for(int j=i+1;j<=n;j++)
{
if(c[j].r-c[i].r>sqrt(2)*50)break;
else if(ok(i,j))
{
ans+=2;
if(ans>2*n)return 0*puts("greater");
}
}
}
printf("%d\n",ans);
return 0;
}
/******************** ********************/

L:树链剖分裸题

//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
//#pragma GCC optimize(4)
//#pragma GCC optimize("unroll-loops")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define fi first
#define se second
#define db double
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define ll long long
#define vi vector<int>
#define mod 1000000007
#define ld long double
//#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
//#define cd complex<double>
#define ull unsigned long long
//#define base 1000000000000000000
#define fin freopen("a.txt","r",stdin)
#define fout freopen("a.txt","w",stdout)
#define fio ios::sync_with_stdio(false);cin.tie(0)
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;}
inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}
template<typename T>inline T const& MAX(T const &a,T const &b){return a>b?a:b;}
template<typename T>inline T const& MIN(T const &a,T const &b){return a<b?a:b;}
inline ll qp(ll a,ll b){ll ans=1;while(b){if(b&1)ans=ans*a%mod;a=a*a%mod,b>>=1;}return ans;}
inline ll qp(ll a,ll b,ll c){ll ans=1;while(b){if(b&1)ans=ans*a%c;a=a*a%c,b>>=1;}return ans;} using namespace std; const double eps=1e-8;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int N=100000+10,maxn=200000+10,inf=0x3f3f3f3f; struct edge{
int to,Next;
}e[maxn];
int cnt,head[N];
int son[N],fa[N],top[N],sz[N],id[N];
int res,dep[N];
void add(int u,int v){e[cnt].to=v;e[cnt].Next=head[u];head[u]=cnt++;}
void init()
{
cnt=0;
memset(head,-1,sizeof head);
memset(son,-1,sizeof son);
}
void dfs1(int u,int f,int de)
{
fa[u]=f;sz[u]=1;
dep[u]=de;
for(int i=head[u];~i;i=e[i].Next)
{
int v=e[i].to;
if(v!=f)
{
dfs1(v,u,de+1);
sz[u]+=sz[v];
if(son[u]==-1||sz[v]>sz[son[u]])son[u]=v;
}
}
}
void dfs2(int u,int f,int tp)
{
top[u]=tp;id[u]=++res;
if(son[u]!=-1)dfs2(son[u],u,tp);
for(int i=head[u];~i;i=e[i].Next)
{
int v=e[i].to;
if(v!=f&&v!=son[u])dfs2(v,u,v);
}
}
int sum[N<<2],lazy[N<<2];
void pushdown(int l,int r,int rt)
{
if(lazy[rt]!=0)
{
int m=(l+r)>>1;
sum[rt<<1]+=(m-l+1)*lazy[rt];
sum[rt<<1|1]+=(r-m)*lazy[rt];
lazy[rt<<1]+=lazy[rt];
lazy[rt<<1|1]+=lazy[rt];
lazy[rt]=0;
}
}
void pushup(int rt)
{
sum[rt]=sum[rt<<1]+sum[rt<<1|1];
}
void build(int l,int r,int rt)
{
lazy[rt]=sum[rt]=0;
if(l==r)return ;
int m=(l+r)>>1;
build(ls);build(rs);
}
void update(int L,int R,int c,int l,int r,int rt)
{
if(L<=l&&r<=R)
{
sum[rt]+=(r-l+1)*c;
lazy[rt]+=c;
return ;
}
pushdown(l,r,rt);
int m=(l+r)>>1;
if(L<=m)update(L,R,c,ls);
if(m<R)update(L,R,c,rs);
pushup(rt);
}
int query1(int L,int R,int l,int r,int rt)
{
if(L<=l&&r<=R)return sum[rt];
pushdown(l,r,rt);
int m=(l+r)>>1,ans=0;
if(L<=m)ans+=query1(L,R,ls);
if(m<R)ans+=query1(L,R,rs);
return ans;
}
int query(int a,int b)
{
int f1=top[a],f2=top[b],ans=0;
while(f1!=f2)
{
if(dep[f1]<dep[f2])swap(f1,f2),swap(a,b);
ans+=query1(id[f1],id[a],1,res,1);
a=fa[f1],f1=top[a];
}
if(dep[a]>dep[b])swap(a,b);
ans+=query1(id[a],id[b],1,res,1);
return ans;
}
void change(int a,int b,int c)
{
int f1=top[a],f2=top[b];
while(f1!=f2)
{
if(dep[f1]<dep[f2])swap(f1,f2),swap(a,b);
update(id[f1],id[a],c,1,res,1);
a=fa[f1],f1=top[a];
}
if(dep[a]>dep[b])swap(a,b);
update(id[a],id[b],c,1,res,1);
}
int main()
{
int n,q;
scanf("%d%d",&n,&q);
init();
for(int i=1;i<n;i++)
{
int a,b;scanf("%d%d",&a,&b);
add(a,b);add(b,a);
}
dfs1(1,-1,1);
dfs2(1,-1,1);
build(1,res,1);
while(q--)
{
int a,b,c,d;scanf("%d%d%d%d",&a,&b,&c,&d);
change(a,b,1);
printf("%d\n",query(c,d));
change(a,b,-1);
}
return 0;
}
/********************
10 4
1 4
4 5
3 4
3 2
7 3
6 7
7 8
10 8
8 9
6 10 2 5
1 9 5 10
9 10 2 1
5 10 2 9
********************/

M:留坑

2018-2019 ACM-ICPC Brazil Subregional Programming Contest的更多相关文章

  1. (寒假GYM开黑)2018-2019 ACM-ICPC Brazil Subregional Programming Contest

    layout: post title: 2018-2019 ACM-ICPC Brazil Subregional Programming Contest author: "luowenta ...

  2. 2018-2019 ACM-ICPC Brazil Subregional Programming Contest PART (10/13)

    $$2018-2019 ACM-ICPC Brazil Subregional Programming Contest$$ \(A.Slackline\ Adventure\) \(B.Marbles ...

  3. 2019-2020 ACM-ICPC Brazil Subregional Programming Contest (11/13)

    \(2019-2020\ ACM-ICPC\ Brazil\ Subregional\ Programming\ Contest\) \(A.Artwork\) 并查集,把检测区域能在一起的检测器放在 ...

  4. ACM ICPC, JUST Collegiate Programming Contest (2018) Solution

    A:Zero Array 题意:两种操作, 1 p v  将第p个位置的值改成v  2  查询最少的操作数使得所有数都变为0  操作为可以从原序列中选一个非0的数使得所有非0的数减去它,并且所有数不能 ...

  5. ACM ICPC, Amman Collegiate Programming Contest (2018) Solution

    Solution A:Careful Thief 题意:给出n个区间,每个区间的每个位置的权值都是v,然后找长度为k的区间,使得这个区间的所有位置的权值加起来最大,输出最大权值, 所有区间不重叠 思路 ...

  6. Gym.101908 Brazil Subregional Programming Contest(寒假自训第六场)

    这几天睡眠时间都不太够,室友晚上太会折腾了,感觉有点累,所以昨天的题解也没写,看晚上能不能补起来. B . Marbles 题意:给定N组数(xi,yi),玩家轮流操作,每次玩家可以选择其中一组对其操 ...

  7. 2013-2014 ACM-ICPC Brazil Subregional Programming Contest 题解

    [题目链接] 这场比赛题面英文都好长... ... A - Zero or One 模拟. #include <bits/stdc++.h> using namespace std; in ...

  8. Codeforces Gym101473 A.Zero or One (2013-2014 ACM-ICPC Brazil Subregional Programming Contest)

    代码: #include<iostream> #include<cstring> #include<cstdio> #include<cmath> #i ...

  9. Codeforces Gym101473 F.Triangles-前缀和 (2013-2014 ACM-ICPC Brazil Subregional Programming Contest)

    前缀和. 代码: 1 #include<iostream> 2 #include<cstring> 3 #include<cstdio> 4 #include< ...

随机推荐

  1. java 之 xml 之解析工具jaxp

    一.jaxp的api查看 *jaxp是javase一部分 *jaxp解析器在jdk的javax.xml.parsers包里面 *共四个类:分别针对dom和sax解析使用的类 *dom解析类: Docu ...

  2. C# DateTime判断时间

    两种情况: 1 DateTime? dtTemp = null; if(dtTime != null) { //wawawa } 刚刚学会的,可空值类型,可判断是否赋值 2 DateTime dtTe ...

  3. 搭建git 服务器

    Gogs 什么是 Gogs? Gogs 是一款极易搭建的自助 Git 服务. https://gogs.io/docs

  4. 强化学习策略梯度方法之: REINFORCE 算法(从原理到代码实现)

    强化学习策略梯度方法之: REINFORCE 算法 (从原理到代码实现) 2018-04-01  15:15:42   最近在看policy gradient algorithm, 其中一种比较经典的 ...

  5. postgreSql——时区问题

    timestamptz.timestamp SELECT ts AT TIME ZONE 'UTC' FROM ( VALUES (timestamptz '2012-03-05 17:00:00+0 ...

  6. 【NOIP 2015】Day2 T3 运输计划

    Problem Background 公元 \(2044\) 年,人类进入了宇宙纪元. Description 公元\(2044\) 年,人类进入了宇宙纪元. $L $国有 \(n\) 个星球,还有 ...

  7. SAP FI 常用表

    SAP FI 常用表 GL 部分: FAGLFLEXT 新总账汇总表 GLT0 旧总帐汇总表 SKA1 总账科目主记录 (科目表) 科目表层数据 SKAT 总帐科目主记录(科目表:说明) 包括语言代码 ...

  8. WaitingFormHelper

    using Lba_Ciac; using System; using System.Collections.Generic; using System.Linq; using System.Text ...

  9. sticky-footer的三种解决方案

    在网页设计中,Sticky footers设计是最古老和最常见的效果之一,大多数人都曾经经历过.它可以概括如下:如果页面内容不够长的时候,页脚块粘贴在视窗底部:如果内容足够长时,页脚块会被内容向下推送 ...

  10. IDEA @Autowired 出现红色下划线 报红

    例如: 解决方法: