A:留坑

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

  1. //#pragma GCC optimize(2)
  2. //#pragma GCC optimize(3)
  3. //#pragma GCC optimize(4)
  4. //#pragma GCC optimize("unroll-loops")
  5. //#pragma comment(linker, "/stack:200000000")
  6. //#pragma GCC optimize("Ofast,no-stack-protector")
  7. //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
  8. #include<bits/stdc++.h>
  9. #define fi first
  10. #define se second
  11. #define db double
  12. #define mp make_pair
  13. #define pb push_back
  14. #define pi acos(-1.0)
  15. #define ll long long
  16. #define vi vector<int>
  17. #define mod 1000000007
  18. #define ld long double
  19. //#define C 0.5772156649
  20. #define ls l,m,rt<<1
  21. #define rs m+1,r,rt<<1|1
  22. #define pll pair<ll,ll>
  23. #define pil pair<int,ll>
  24. #define pli pair<ll,int>
  25. #define pii pair<int,int>
  26. //#define cd complex<double>
  27. #define ull unsigned long long
  28. //#define base 1000000000000000000
  29. #define fin freopen("a.txt","r",stdin)
  30. #define fout freopen("a.txt","w",stdout)
  31. #define fio ios::sync_with_stdio(false);cin.tie(0)
  32. inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
  33. inline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;}
  34. inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}
  35. template<typename T>inline T const& MAX(T const &a,T const &b){return a>b?a:b;}
  36. template<typename T>inline T const& MIN(T const &a,T const &b){return a<b?a:b;}
  37. 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;}
  38. 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;}
  39. using namespace std;
  40. const double eps=1e-8;
  41. const ll INF=0x3f3f3f3f3f3f3f3f;
  42. const int N=100+10,maxn=200000+10,inf=0x3f3f3f3f;
  43. int sg[N][N],Hash[200];
  44. int main()
  45. {
  46. for(int i=1;i<=100;i++)
  47. {
  48. for(int j=1;j<=100;j++)
  49. {
  50. if(i==j)continue;
  51. memset(Hash,0,sizeof Hash);
  52. for(int k=1;k<i;k++)if(i-k!=j)Hash[sg[i-k][j]]=1;
  53. for(int k=1;k<j;k++)if(i!=j-k)Hash[sg[i][j-k]]=1;
  54. for(int k=1;k<min(i,j);k++)if(i-k!=j-k)Hash[sg[i-k][j-k]]=1;
  55. for(int k=0;;k++)
  56. {
  57. if(!Hash[k])
  58. {
  59. sg[i][j]=k;
  60. break;
  61. }
  62. }
  63. // printf("%d ",sg[i][j]);
  64. }
  65. // puts("");
  66. }
  67. int n,ans=0;scanf("%d",&n);
  68. while(n--)
  69. {
  70. int x,y;scanf("%d%d",&x,&y);
  71. if(x==y)return 0*puts("Y");
  72. ans^=sg[x][y];
  73. }
  74. puts(ans?"Y":"N");
  75. return 0;
  76. }
  77. /********************
  78. ********************/

C:bit维护逆序对即可

  1. //#pragma GCC optimize(2)
  2. //#pragma GCC optimize(3)
  3. //#pragma GCC optimize(4)
  4. //#pragma GCC optimize("unroll-loops")
  5. //#pragma comment(linker, "/stack:200000000")
  6. //#pragma GCC optimize("Ofast,no-stack-protector")
  7. //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
  8. #include<bits/stdc++.h>
  9. #define fi first
  10. #define se second
  11. #define db double
  12. #define mp make_pair
  13. #define pb push_back
  14. #define pi acos(-1.0)
  15. #define ll long long
  16. #define vi vector<int>
  17. #define mod 1000000007
  18. #define ld long double
  19. //#define C 0.5772156649
  20. #define ls l,m,rt<<1
  21. #define rs m+1,r,rt<<1|1
  22. #define pll pair<ll,ll>
  23. #define pil pair<int,ll>
  24. #define pli pair<ll,int>
  25. #define pii pair<int,int>
  26. //#define cd complex<double>
  27. #define ull unsigned long long
  28. #define base 1000000000000000000
  29. #define Max(a,b) ((a)>(b)?(a):(b))
  30. #define Min(a,b) ((a)<(b)?(a):(b))
  31. #define fin freopen("a.txt","r",stdin)
  32. #define fout freopen("a.txt","w",stdout)
  33. #define fio ios::sync_with_stdio(false);cin.tie(0)
  34. inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
  35. inline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;}
  36. inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}
  37. template<typename T>inline T const& MAX(T const &a,T const &b){return a>b?a:b;}
  38. template<typename T>inline T const& MIN(T const &a,T const &b){return a<b?a:b;}
  39. 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;}
  40. 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;}
  41. using namespace std;
  42. const double eps=1e-8;
  43. const ll INF=0x3f3f3f3f3f3f3f3f;
  44. const int N=4e5+10,maxn=1000000+10,inf=0x3f3f3f3f;
  45. struct bit{
  46. int sum[N];
  47. void init(){memset(sum,0,sizeof sum);}
  48. void update(int i)
  49. {
  50. for(;i<N;i+=i&(-i))sum[i]++;
  51. }
  52. int query(int i)
  53. {
  54. int ans=0;
  55. for(;i;i-=i&(-i))ans+=sum[i];
  56. return ans;
  57. }
  58. }b;
  59. pii x[N],y[N];
  60. int Hash[N],cnt;
  61. int main()
  62. {
  63. int xx,yy,h,v;scanf("%d%d%d%d",&xx,&yy,&h,&v);
  64. 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;
  65. sort(x+1,x+1+h);sort(Hash,Hash+cnt);cnt=unique(Hash,Hash+cnt)-Hash;
  66. for(int i=1;i<=h;i++)
  67. {
  68. x[i].fi=lower_bound(Hash,Hash+cnt,x[i].fi)-Hash+1;
  69. x[i].se=lower_bound(Hash,Hash+cnt,x[i].se)-Hash+1;
  70. }
  71. cnt=0;
  72. 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;
  73. sort(y+1,y+1+v);sort(Hash,Hash+cnt);cnt=unique(Hash,Hash+cnt)-Hash;
  74. for(int i=1;i<=v;i++)
  75. {
  76. y[i].fi=lower_bound(Hash,Hash+cnt,y[i].fi)-Hash+1;
  77. y[i].se=lower_bound(Hash,Hash+cnt,y[i].se)-Hash+1;
  78. }
  79. ll c=0,d=0;
  80. for(int i=1;i<=h;i++)
  81. {
  82. c+=b.query(N-1)-b.query(x[i].se);
  83. b.update(x[i].se);
  84. }
  85. b.init();
  86. for(int i=1;i<=v;i++)
  87. {
  88. d+=b.query(N-1)-b.query(y[i].se);
  89. b.update(y[i].se);
  90. }
  91. printf("%lld\n",1ll*(h+1)*(v+1)+c+d);
  92. return 0;
  93. }
  94. /********************
  95. ********************/

D:签到

  1. //#pragma GCC optimize(2)
  2. //#pragma GCC optimize(3)
  3. //#pragma GCC optimize(4)
  4. //#pragma GCC optimize("unroll-loops")
  5. //#pragma comment(linker, "/stack:200000000")
  6. //#pragma GCC optimize("Ofast,no-stack-protector")
  7. //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
  8. #include<bits/stdc++.h>
  9. #define fi first
  10. #define se second
  11. #define db double
  12. #define mp make_pair
  13. #define pb push_back
  14. #define pi acos(-1.0)
  15. #define ll long long
  16. #define vi vector<int>
  17. #define mod 1000000007
  18. #define ld long double
  19. #define C 0.5772156649
  20. #define ls l,m,rt<<1
  21. #define rs m+1,r,rt<<1|1
  22. #define pll pair<ll,ll>
  23. #define pil pair<int,ll>
  24. #define pli pair<ll,int>
  25. #define pii pair<int,int>
  26. //#define cd complex<double>
  27. #define ull unsigned long long
  28. //#define base 1000000000000000000
  29. #define Max(a,b) ((a)>(b)?(a):(b))
  30. #define Min(a,b) ((a)<(b)?(a):(b))
  31. #define fin freopen("a.txt","r",stdin)
  32. #define fout freopen("a.txt","w",stdout)
  33. #define fio ios::sync_with_stdio(false);cin.tie(0)
  34. inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
  35. inline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;}
  36. inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}
  37. template<typename T>inline T const& MAX(T const &a,T const &b){return a>b?a:b;}
  38. template<typename T>inline T const& MIN(T const &a,T const &b){return a<b?a:b;}
  39. 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;}
  40. 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;}
  41. using namespace std;
  42. const double eps=1e-8;
  43. const ll INF=0x3f3f3f3f3f3f3f3f;
  44. const int N=20200+10,maxn=200000+10,inf=0x3f3f3f3f;
  45. int main()
  46. {
  47. int _,x,ans=0;
  48. for(scanf("%d",&_);_;_--)
  49. {
  50. scanf("%d",&x);
  51. if(x!=1)ans++;
  52. }
  53. printf("%d\n",ans);
  54. return 0;
  55. }
  56. /********************
  57. ********************/

E:签到

  1. //#pragma GCC optimize(2)
  2. //#pragma GCC optimize(3)
  3. //#pragma GCC optimize(4)
  4. //#pragma GCC optimize("unroll-loops")
  5. //#pragma comment(linker, "/stack:200000000")
  6. //#pragma GCC optimize("Ofast,no-stack-protector")
  7. //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
  8. #include<bits/stdc++.h>
  9. #define fi first
  10. #define se second
  11. #define db double
  12. #define mp make_pair
  13. #define pb push_back
  14. #define pi acos(-1.0)
  15. #define ll long long
  16. #define vi vector<int>
  17. #define mod 1000000007
  18. #define ld long double
  19. #define C 0.5772156649
  20. //#define ls l,m,rt<<1
  21. //#define rs m+1,r,rt<<1|1
  22. #define pll pair<ll,ll>
  23. #define pil pair<int,ll>
  24. #define pli pair<ll,int>
  25. #define pii pair<int,int>
  26. //#define cd complex<double>
  27. #define ull unsigned long long
  28. //#define base 1000000000000000000
  29. #define Max(a,b) ((a)>(b)?(a):(b))
  30. #define Min(a,b) ((a)<(b)?(a):(b))
  31. #define fin freopen("a.txt","r",stdin)
  32. #define fout freopen("a.txt","w",stdout)
  33. #define fio ios::sync_with_stdio(false);cin.tie(0)
  34. inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
  35. inline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;}
  36. inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}
  37. template<typename T>inline T const& MAX(T const &a,T const &b){return a>b?a:b;}
  38. template<typename T>inline T const& MIN(T const &a,T const &b){return a<b?a:b;}
  39. 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;}
  40. 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;}
  41. using namespace std;
  42. const double eps=1e-8;
  43. const ll INF=0x3f3f3f3f3f3f3f3f;
  44. const int N=10000+10,maxn=200000+10,inf=0x3f3f3f3f;
  45. char s[N],p[N];
  46. int main()
  47. {
  48. scanf("%s%s",s,p);
  49. int ls=strlen(s),ps=strlen(p),ans=0;
  50. for(int i=0;i+ps-1<ls;i++)
  51. {
  52. bool f=0;
  53. for(int j=0;j<ps;j++)if(s[i+j]==p[j]){f=1;break;}
  54. if(!f)ans++;
  55. }
  56. printf("%d\n",ans);
  57. return 0;
  58. }
  59. /********************
  60. ********************/

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

  1. //#pragma GCC optimize(2)
  2. //#pragma GCC optimize(3)
  3. //#pragma GCC optimize(4)
  4. //#pragma GCC optimize("unroll-loops")
  5. //#pragma comment(linker, "/stack:200000000")
  6. //#pragma GCC optimize("Ofast,no-stack-protector")
  7. //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
  8. #include<bits/stdc++.h>
  9. #define fi first
  10. #define se second
  11. #define db double
  12. #define mp make_pair
  13. #define pb push_back
  14. #define pi acos(-1.0)
  15. #define ll long long
  16. #define vi vector<int>
  17. #define mod 1000000007
  18. #define ld long double
  19. #define C 0.5772156649
  20. #define ls l,m,rt<<1
  21. #define rs m+1,r,rt<<1|1
  22. #define pll pair<ll,ll>
  23. #define pil pair<int,ll>
  24. #define pli pair<ll,int>
  25. #define pii pair<int,int>
  26. //#define cd complex<double>
  27. #define ull unsigned long long
  28. //#define base 1000000000000000000
  29. #define Max(a,b) ((a)>(b)?(a):(b))
  30. #define Min(a,b) ((a)<(b)?(a):(b))
  31. #define fin freopen("a.txt","r",stdin)
  32. #define fout freopen("a.txt","w",stdout)
  33. #define fio ios::sync_with_stdio(false);cin.tie(0)
  34. inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
  35. inline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;}
  36. inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}
  37. template<typename T>inline T const& MAX(T const &a,T const &b){return a>b?a:b;}
  38. template<typename T>inline T const& MIN(T const &a,T const &b){return a<b?a:b;}
  39. 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;}
  40. 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;}
  41. using namespace std;
  42. const double eps=1e-8;
  43. const ll INF=0x3f3f3f3f3f3f3f3f;
  44. const int N=2000+10,maxn=100000+10,inf=0x3f3f3f3f;
  45. struct bit{
  46. int sum[N];
  47. bit(){memset(sum,-1,sizeof sum);}
  48. void update(int i,int x)
  49. {
  50. for(;i<N;i+=i&(-i))sum[i]=max(sum[i],x);
  51. }
  52. int query(int i)
  53. {
  54. int ma=-1;
  55. for(;i;i-=i&(-i))ma=max(ma,sum[i]);
  56. return ma;
  57. }
  58. }b[N];
  59. struct node{
  60. int s,t,v,id;
  61. bool operator <(const node&rhs)const
  62. {
  63. return s<rhs.s || s==rhs.s&&t<rhs.t;
  64. }
  65. }p;
  66. vector<node>v;
  67. int Hash[N],cnt;
  68. int main()
  69. {
  70. b[0].update(1,0);
  71. int n;scanf("%d",&n);
  72. for(int i=0,k;i<n;i++)for(scanf("%d",&k);k;k--)
  73. {
  74. scanf("%d%d%d",&p.s,&p.t,&p.v),p.id=i,v.pb(p);
  75. Hash[cnt++]=p.s,Hash[cnt++]=p.t;
  76. }
  77. sort(Hash,Hash+cnt);cnt=unique(Hash,Hash+cnt)-Hash;
  78. sort(v.begin(),v.end());
  79. for(int i=0;i<v.size();i++)
  80. {
  81. p=v[i];
  82. p.s=lower_bound(Hash,Hash+cnt,p.s)-Hash+1;
  83. p.t=lower_bound(Hash,Hash+cnt,p.t)-Hash+1;
  84. // printf("%d %d %d %d %d\n",p.s,p.t,p.v,p.id,b[7].query(8));
  85. for(int j=0;j<(1<<n);j++)
  86. {
  87. int x=b[j].query(p.s);
  88. if(x!=-1)b[j|(1<<p.id)].update(p.t,x+p.v);
  89. // if(x!=-1&&(j|(1<<p.id))==7)printf("%d %d %d!!!!\n",p.s,p.t,x+p.v);
  90. // 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));
  91. }
  92. }
  93. printf("%d\n",b[(1<<n)-1].query(N-1));
  94. return 0;
  95. }
  96. /********************
  97. ********************/

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

  1. //#pragma GCC optimize(2)
  2. //#pragma GCC optimize(3)
  3. //#pragma GCC optimize(4)
  4. //#pragma GCC optimize("unroll-loops")
  5. //#pragma comment(linker, "/stack:200000000")
  6. //#pragma GCC optimize("Ofast,no-stack-protector")
  7. //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
  8. #include<bits/stdc++.h>
  9. #define fi first
  10. #define se second
  11. #define db double
  12. #define mp make_pair
  13. #define pb push_back
  14. #define pi acos(-1.0)
  15. #define ll long long
  16. #define vi vector<int>
  17. #define mod 1000000007
  18. #define ld long double
  19. //#define C 0.5772156649
  20. #define ls l,m,rt<<1
  21. #define rs m+1,r,rt<<1|1
  22. #define pll pair<ll,ll>
  23. #define pil pair<int,ll>
  24. #define pli pair<ll,int>
  25. #define pii pair<int,int>
  26. //#define cd complex<double>
  27. #define ull unsigned long long
  28. //#define base 1000000000000000000
  29. #define fin freopen("a.txt","r",stdin)
  30. #define fout freopen("a.txt","w",stdout)
  31. #define fio ios::sync_with_stdio(false);cin.tie(0)
  32. inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
  33. inline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;}
  34. inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}
  35. template<typename T>inline T const& MAX(T const &a,T const &b){return a>b?a:b;}
  36. template<typename T>inline T const& MIN(T const &a,T const &b){return a<b?a:b;}
  37. 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;}
  38. 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;}
  39. using namespace std;
  40. const double eps=1e-8;
  41. const ll INF=0x3f3f3f3f3f3f3f3f;
  42. const int N=2000+10,maxn=50000+10,inf=0x3f3f3f3f;
  43. int p,r,c,d[N],E[N],ans;
  44. struct node{
  45. int a,b,c;
  46. bool operator <(const node&rhs)const
  47. {
  48. return c<rhs.c;
  49. }
  50. }f[maxn];
  51. struct edge{
  52. int to,Next,c;
  53. }e[maxn];
  54. int s,t,cnt,head[N],cur[N],dis[N];
  55. void init(){cnt=0;memset(head,-1,sizeof head);}
  56. void add(int u,int v,int c)
  57. {
  58. e[cnt].to=v;e[cnt].c=c;e[cnt].Next=head[u];head[u]=cnt++;
  59. e[cnt].to=u;e[cnt].c=0;e[cnt].Next=head[v];head[v]=cnt++;
  60. }
  61. bool bfs()
  62. {
  63. queue<int>q;
  64. memset(dis,-1,sizeof dis);
  65. dis[s]=1;
  66. q.push(s);
  67. while(!q.empty())
  68. {
  69. int x=q.front();q.pop();
  70. for(int i=head[x];~i;i=e[i].Next)
  71. {
  72. int y=e[i].to;
  73. if(dis[y]==-1&&e[i].c>0)
  74. {
  75. dis[y]=dis[x]+1;
  76. q.push(y);
  77. }
  78. }
  79. }
  80. return dis[t]!=-1;
  81. }
  82. int dfs(int u,int mx)
  83. {
  84. if(u==t)return mx;
  85. int f;
  86. for(int &i=cur[u];~i;i=e[i].Next)
  87. {
  88. int x=e[i].to;
  89. if(dis[x]==dis[u]+1&&e[i].c>0&&(f=dfs(x,min(mx,e[i].c))))
  90. {
  91. e[i].c-=f;
  92. e[i^1].c+=f;
  93. return f;
  94. }
  95. }
  96. return 0;
  97. }
  98. int maxflow()
  99. {
  100. int ans=0,f;
  101. while(bfs())
  102. {
  103. for(int i=0;i<=t;i++)cur[i]=head[i];
  104. while((f=dfs(s,inf)))ans+=f;
  105. }
  106. return ans;
  107. }
  108. bool ok(int x)
  109. {
  110. init();
  111. for(int i=1;i<=p;i++)add(i,t,d[i]);
  112. for(int i=1;i<=r;i++)add(s,p+i,E[i]);
  113. for(int i=1;i<=c;i++)
  114. {
  115. if(f[i].c<=x)add(f[i].b+p,f[i].a,inf);
  116. else break;
  117. }
  118. return maxflow()==ans;
  119. }
  120. int main()
  121. {
  122. scanf("%d%d%d",&p,&r,&c);
  123. s=p+r+1,t=p+r+2;
  124. for(int i=1;i<=p;i++)scanf("%d",&d[i]),ans+=d[i];
  125. for(int i=1;i<=r;i++)scanf("%d",&E[i]);
  126. for(int i=1;i<=c;i++)
  127. {
  128. int a,b,c;
  129. scanf("%d%d%d",&a,&b,&c);
  130. f[i]={a,b,c};
  131. }
  132. sort(f+1,f+1+c);
  133. int l=0,r=f[c].c+1;
  134. while(l<r-1)
  135. {
  136. int m=(l+r)>>1;
  137. if(ok(m))r=m;
  138. else l=m;
  139. }
  140. printf("%d\n",(r<=f[c].c)?r:-1);
  141. return 0;
  142. }
  143. /********************
  144. 3 2 5
  145. 20 10 10
  146. 25 30
  147. 1 1 3
  148. 2 1 1
  149. 2 2 4
  150. 3 1 2
  151. 3 2 5
  152. ********************/

H:留坑

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

  1. //#pragma GCC optimize(2)
  2. //#pragma GCC optimize(3)
  3. //#pragma GCC optimize(4)
  4. //#pragma GCC optimize("unroll-loops")
  5. //#pragma comment(linker, "/stack:200000000")
  6. //#pragma GCC optimize("Ofast,no-stack-protector")
  7. //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
  8. #include<bits/stdc++.h>
  9. #define fi first
  10. #define se second
  11. #define db double
  12. #define mp make_pair
  13. #define pb push_back
  14. #define pi acos(-1.0)
  15. #define ll long long
  16. #define vi vector<int>
  17. #define mod 1000000007
  18. #define ld long double
  19. //#define C 0.5772156649
  20. #define ls l,m,rt<<1
  21. #define rs m+1,r,rt<<1|1
  22. #define pll pair<ll,ll>
  23. #define pil pair<int,ll>
  24. #define pli pair<ll,int>
  25. #define pii pair<int,int>
  26. //#define cd complex<double>
  27. #define ull unsigned long long
  28. //#define base 1000000000000000000
  29. #define fin freopen("a.txt","r",stdin)
  30. #define fout freopen("a.txt","w",stdout)
  31. #define fio ios::sync_with_stdio(false);cin.tie(0)
  32. inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
  33. inline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;}
  34. inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}
  35. template<typename T>inline T const& MAX(T const &a,T const &b){return a>b?a:b;}
  36. template<typename T>inline T const& MIN(T const &a,T const &b){return a<b?a:b;}
  37. 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;}
  38. 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;}
  39. using namespace std;
  40. const double eps=1e-8;
  41. const ll INF=0x3f3f3f3f3f3f3f3f;
  42. const int N=1000+10,maxn=200000+10,inf=0x3f3f3f3f;
  43. bitset<1010>b[N],c;
  44. int main()
  45. {
  46. int n,m,k,x;
  47. scanf("%d%d%d",&n,&m,&k);
  48. for(int i=0;i<k;i++)scanf("%d",&x),c.set(x);
  49. for(int i=1;i<=n;i++)
  50. {
  51. scanf("%d",&k);
  52. while(k--)scanf("%d",&x),b[i].set(x);
  53. }
  54. for(int i=1;i<=n;i++)
  55. {
  56. c^=b[i];
  57. if(c.count()==0)return 0*printf("%d\n",i);
  58. }
  59. for(int i=1;i<=n;i++)
  60. {
  61. c^=b[i];
  62. if(c.count()==0)return 0*printf("%d\n",i+n);
  63. }
  64. puts("-1");
  65. return 0;
  66. }
  67. /********************
  68. ********************/

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

  1. //#pragma GCC optimize(2)
  2. //#pragma GCC optimize(3)
  3. //#pragma GCC optimize(4)
  4. //#pragma GCC optimize("unroll-loops")
  5. //#pragma comment(linker, "/stack:200000000")
  6. //#pragma GCC optimize("Ofast,no-stack-protector")
  7. //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
  8. #include<bits/stdc++.h>
  9. #define fi first
  10. #define se second
  11. #define db double
  12. #define mp make_pair
  13. #define pb push_back
  14. #define pi acos(-1.0)
  15. #define ll long long
  16. #define vi vector<int>
  17. #define mod 1000000007
  18. #define ld long double
  19. //#define C 0.5772156649
  20. #define ls l,m,rt<<1
  21. #define rs m+1,r,rt<<1|1
  22. #define pll pair<ll,ll>
  23. #define pil pair<int,ll>
  24. #define pli pair<ll,int>
  25. #define pii pair<int,int>
  26. //#define cd complex<double>
  27. #define ull unsigned long long
  28. //#define base 1000000000000000000
  29. #define fin freopen("a.txt","r",stdin)
  30. #define fout freopen("a.txt","w",stdout)
  31. #define fio ios::sync_with_stdio(false);cin.tie(0)
  32. inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
  33. inline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;}
  34. inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}
  35. template<typename T>inline T const& MAX(T const &a,T const &b){return a>b?a:b;}
  36. template<typename T>inline T const& MIN(T const &a,T const &b){return a<b?a:b;}
  37. 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;}
  38. 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;}
  39. using namespace std;
  40. const double eps=1e-8;
  41. const ll INF=0x3f3f3f3f3f3f3f3f;
  42. const int N=100+10,maxn=200000+10,inf=0x3f3f3f3f;
  43. int x[N],y[N],n,k;
  44. db dp[N][(1<<10)+10];
  45. queue<int>q;
  46. bool vis[N];
  47. 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]));}
  48. void spfa(int st)
  49. {
  50. while(!q.empty())
  51. {
  52. int p=q.front();q.pop();
  53. vis[p]=0;
  54. for(int i=k;i<n;i++)
  55. {
  56. if(i==p)continue;
  57. db te=cal(p,i);
  58. if(dp[p][st]+te<dp[i][st])
  59. {
  60. dp[i][st]=dp[p][st]+te;
  61. q.push(i);
  62. }
  63. }
  64. }
  65. }
  66. int main()
  67. {
  68. scanf("%d%d",&n,&k);
  69. for(int i=0;i<n;i++)for(int j=0;j<(1<<k);j++)dp[i][j]=2e9;
  70. for(int i=0;i<n;i++)
  71. {
  72. scanf("%d%d",&x[i],&y[i]);
  73. if(i<k)dp[i][1<<i]=0;
  74. }
  75. for(int st=0;st<(1<<k);st++)
  76. {
  77. for(int i=0;i<n;i++)
  78. {
  79. for(int s=st;s;s=(s-1)&st)
  80. if(dp[i][s]+dp[i][st-s]<dp[i][st])
  81. dp[i][st]=dp[i][s]+dp[i][st-s];
  82. if(dp[i][st]<inf)q.push(i),vis[i]=1;
  83. }
  84. spfa(st);
  85. }
  86. db ans=2e9;
  87. for(int i=k;i<n;i++)ans=min(ans,dp[i][(1<<k)-1]);
  88. printf("%.5f\n",ans);
  89. return 0;
  90. }
  91. /********************
  92. ********************/

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

  1. #pragma GCC optimize(2)
  2. #pragma GCC optimize(3)
  3. #pragma GCC optimize(4)
  4. //#pragma GCC optimize("unroll-loops")
  5. //#pragma comment(linker, "/stack:200000000")
  6. //#pragma GCC optimize("Ofast,no-stack-protector")
  7. //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
  8. #include<bits/stdc++.h>
  9. #define fi first
  10. #define se second
  11. #define db double
  12. #define mp make_pair
  13. #define pb push_back
  14. #define pi acos(-1.0)
  15. #define ll long long
  16. #define vi vector<int>
  17. #define mod 1000000007
  18. #define ld long double
  19. //#define C 0.5772156649
  20. #define ls l,m,rt<<1
  21. #define rs m+1,r,rt<<1|1
  22. #define pll pair<ll,ll>
  23. #define pil pair<int,ll>
  24. #define pli pair<ll,int>
  25. #define pii pair<int,int>
  26. //#define cd complex<double>
  27. #define ull unsigned long long
  28. //#define base 1000000000000000000
  29. #define fin freopen("a.txt","r",stdin)
  30. #define fout freopen("a.txt","w",stdout)
  31. #define fio ios::sync_with_stdio(false);cin.tie(0)
  32. inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
  33. inline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;}
  34. inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}
  35. template<typename T>inline T const& MAX(T const &a,T const &b){return a>b?a:b;}
  36. template<typename T>inline T const& MIN(T const &a,T const &b){return a<b?a:b;}
  37. 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;}
  38. 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;}
  39. using namespace std;
  40. const double eps=1e-8;
  41. const ll INF=0x3f3f3f3f3f3f3f3f;
  42. const int N=150000+10,maxn=50000+10,inf=0x3f3f3f3f;
  43. struct circle{
  44. db x,y,r;
  45. void read(){scanf("%lf%lf%lf",&x,&y,&r);}
  46. bool operator <(const circle&rhs)const{
  47. return r<rhs.r;
  48. }
  49. }c[N];
  50. bool ok(int i,int j)
  51. {
  52. 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));
  53. return c[j].r-c[i].r<d&&d<c[i].r+c[j].r;
  54. }
  55. int main()
  56. {
  57. int n,ans=0;
  58. scanf("%d",&n);
  59. for(int i=1;i<=n;i++)c[i].read();
  60. sort(c+1,c+1+n);
  61. for(int i=1;i<=n;i++)
  62. {
  63. for(int j=i+1;j<=n;j++)
  64. {
  65. if(c[j].r-c[i].r>sqrt(2)*50)break;
  66. else if(ok(i,j))
  67. {
  68. ans+=2;
  69. if(ans>2*n)return 0*puts("greater");
  70. }
  71. }
  72. }
  73. printf("%d\n",ans);
  74. return 0;
  75. }
  76. /********************
  77. ********************/

L:树链剖分裸题

  1. //#pragma GCC optimize(2)
  2. //#pragma GCC optimize(3)
  3. //#pragma GCC optimize(4)
  4. //#pragma GCC optimize("unroll-loops")
  5. //#pragma comment(linker, "/stack:200000000")
  6. //#pragma GCC optimize("Ofast,no-stack-protector")
  7. //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
  8. #include<bits/stdc++.h>
  9. #define fi first
  10. #define se second
  11. #define db double
  12. #define mp make_pair
  13. #define pb push_back
  14. #define pi acos(-1.0)
  15. #define ll long long
  16. #define vi vector<int>
  17. #define mod 1000000007
  18. #define ld long double
  19. //#define C 0.5772156649
  20. #define ls l,m,rt<<1
  21. #define rs m+1,r,rt<<1|1
  22. #define pll pair<ll,ll>
  23. #define pil pair<int,ll>
  24. #define pli pair<ll,int>
  25. #define pii pair<int,int>
  26. //#define cd complex<double>
  27. #define ull unsigned long long
  28. //#define base 1000000000000000000
  29. #define fin freopen("a.txt","r",stdin)
  30. #define fout freopen("a.txt","w",stdout)
  31. #define fio ios::sync_with_stdio(false);cin.tie(0)
  32. inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
  33. inline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;}
  34. inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}
  35. template<typename T>inline T const& MAX(T const &a,T const &b){return a>b?a:b;}
  36. template<typename T>inline T const& MIN(T const &a,T const &b){return a<b?a:b;}
  37. 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;}
  38. 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;}
  39. using namespace std;
  40. const double eps=1e-8;
  41. const ll INF=0x3f3f3f3f3f3f3f3f;
  42. const int N=100000+10,maxn=200000+10,inf=0x3f3f3f3f;
  43. struct edge{
  44. int to,Next;
  45. }e[maxn];
  46. int cnt,head[N];
  47. int son[N],fa[N],top[N],sz[N],id[N];
  48. int res,dep[N];
  49. void add(int u,int v){e[cnt].to=v;e[cnt].Next=head[u];head[u]=cnt++;}
  50. void init()
  51. {
  52. cnt=0;
  53. memset(head,-1,sizeof head);
  54. memset(son,-1,sizeof son);
  55. }
  56. void dfs1(int u,int f,int de)
  57. {
  58. fa[u]=f;sz[u]=1;
  59. dep[u]=de;
  60. for(int i=head[u];~i;i=e[i].Next)
  61. {
  62. int v=e[i].to;
  63. if(v!=f)
  64. {
  65. dfs1(v,u,de+1);
  66. sz[u]+=sz[v];
  67. if(son[u]==-1||sz[v]>sz[son[u]])son[u]=v;
  68. }
  69. }
  70. }
  71. void dfs2(int u,int f,int tp)
  72. {
  73. top[u]=tp;id[u]=++res;
  74. if(son[u]!=-1)dfs2(son[u],u,tp);
  75. for(int i=head[u];~i;i=e[i].Next)
  76. {
  77. int v=e[i].to;
  78. if(v!=f&&v!=son[u])dfs2(v,u,v);
  79. }
  80. }
  81. int sum[N<<2],lazy[N<<2];
  82. void pushdown(int l,int r,int rt)
  83. {
  84. if(lazy[rt]!=0)
  85. {
  86. int m=(l+r)>>1;
  87. sum[rt<<1]+=(m-l+1)*lazy[rt];
  88. sum[rt<<1|1]+=(r-m)*lazy[rt];
  89. lazy[rt<<1]+=lazy[rt];
  90. lazy[rt<<1|1]+=lazy[rt];
  91. lazy[rt]=0;
  92. }
  93. }
  94. void pushup(int rt)
  95. {
  96. sum[rt]=sum[rt<<1]+sum[rt<<1|1];
  97. }
  98. void build(int l,int r,int rt)
  99. {
  100. lazy[rt]=sum[rt]=0;
  101. if(l==r)return ;
  102. int m=(l+r)>>1;
  103. build(ls);build(rs);
  104. }
  105. void update(int L,int R,int c,int l,int r,int rt)
  106. {
  107. if(L<=l&&r<=R)
  108. {
  109. sum[rt]+=(r-l+1)*c;
  110. lazy[rt]+=c;
  111. return ;
  112. }
  113. pushdown(l,r,rt);
  114. int m=(l+r)>>1;
  115. if(L<=m)update(L,R,c,ls);
  116. if(m<R)update(L,R,c,rs);
  117. pushup(rt);
  118. }
  119. int query1(int L,int R,int l,int r,int rt)
  120. {
  121. if(L<=l&&r<=R)return sum[rt];
  122. pushdown(l,r,rt);
  123. int m=(l+r)>>1,ans=0;
  124. if(L<=m)ans+=query1(L,R,ls);
  125. if(m<R)ans+=query1(L,R,rs);
  126. return ans;
  127. }
  128. int query(int a,int b)
  129. {
  130. int f1=top[a],f2=top[b],ans=0;
  131. while(f1!=f2)
  132. {
  133. if(dep[f1]<dep[f2])swap(f1,f2),swap(a,b);
  134. ans+=query1(id[f1],id[a],1,res,1);
  135. a=fa[f1],f1=top[a];
  136. }
  137. if(dep[a]>dep[b])swap(a,b);
  138. ans+=query1(id[a],id[b],1,res,1);
  139. return ans;
  140. }
  141. void change(int a,int b,int c)
  142. {
  143. int f1=top[a],f2=top[b];
  144. while(f1!=f2)
  145. {
  146. if(dep[f1]<dep[f2])swap(f1,f2),swap(a,b);
  147. update(id[f1],id[a],c,1,res,1);
  148. a=fa[f1],f1=top[a];
  149. }
  150. if(dep[a]>dep[b])swap(a,b);
  151. update(id[a],id[b],c,1,res,1);
  152. }
  153. int main()
  154. {
  155. int n,q;
  156. scanf("%d%d",&n,&q);
  157. init();
  158. for(int i=1;i<n;i++)
  159. {
  160. int a,b;scanf("%d%d",&a,&b);
  161. add(a,b);add(b,a);
  162. }
  163. dfs1(1,-1,1);
  164. dfs2(1,-1,1);
  165. build(1,res,1);
  166. while(q--)
  167. {
  168. int a,b,c,d;scanf("%d%d%d%d",&a,&b,&c,&d);
  169. change(a,b,1);
  170. printf("%d\n",query(c,d));
  171. change(a,b,-1);
  172. }
  173. return 0;
  174. }
  175. /********************
  176. 10 4
  177. 1 4
  178. 4 5
  179. 3 4
  180. 3 2
  181. 7 3
  182. 6 7
  183. 7 8
  184. 10 8
  185. 8 9
  186. 6 10 2 5
  187. 1 9 5 10
  188. 9 10 2 1
  189. 5 10 2 9
  190. ********************/

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. dll注入到指定进程

    talk is cheap,show me code 代码有详细注释 主程序 #include "stdafx.h" #include <windows.h> #inc ...

  2. hdu5628 Clarke and math

    题目地址 题目链接 题意 求 \[ g(i)=\sum_{i1|i}\sum_{i_2|i_1}\sum_{i_3|i_2}...\sum_{i_k|i_{k-1}}f(i_k)\space mod\ ...

  3. demoshow - webdemo展示助手

    demoshow - web demo展示助手 动态图演示页面: http://www.cnblogs.com/daysme/p/6790829.html 一个用来展示前端网页demo的小“助手”,提 ...

  4. js中属性点.和中括号[]的关系。

    本来这里说的是 js 执行一个字符串形式函数的方法. 但是呢看到一个 window['test'] ,居然一下子转不过弯来.这就尴尬了. 不是说好了 [] 和 . 其他都是 “什么的什么” 关系吗?如 ...

  5. 4、Ansible(tags、roles)

    Tags https://docs.ansible.com/ansible/latest/user_guide/playbooks_tags.html http://www.zsythink.net/ ...

  6. codeforces 768D Jon and Orbs

    题目链接:http://codeforces.com/problemset/problem/768/D 令$f[i][j]$表示当前产生过了$i$个球,产生过了$j$个不同的球的概率. ${Ans_i ...

  7. javascript 创建video元素

    <!DOCTYPE html> <html> <body> <h3>演示如何创建 VIDEO 元素</h3> <p>请点击按钮来 ...

  8. Centos7 安装python3.7.2

    下载python3.7.2源码 wget https://www.python.org/ftp/python/3.7.2/Python-3.7.2.tgz 下载完后对压缩包解压缩 tar -xf Py ...

  9. Python 列表list 字典dict

    # coding=utf-8 支持中文 # 列表 n1 = [1, 2, 3] print n1 print len(n1) n1.append(4) print n1 # 字典,包含键值 dic = ...

  10. vue定义全局方法 调用其他组件的方法

    官网的写法  vue实例.$on就可以在根实例上定义全局方法 this.$root就是获取根实例  如果没有根实例 就表示当前实例 this.$root.$on 不需要.eventHub 不需要下面这 ...