• 22/8/3-杭电多校5


    1010,1003,1012;


    1,1010;

    只有是两边都是全部牌都不一样,即第三条规则,那么yahaha是无法叫的,一定会被challenge;

    会输,其余情况都是赢;

    2,1003;

    难点在于如何将两层的图建好;

    一开始找了一个虚拟节点,将所有来到该节点路径的边权设为p,所有从该节点的路径设为0;

    但是每两层要换一个;

    按理说同层之间还是可以相互到达,且路径为p,但是没wa;

    code:

    1. #pragma GCC optimize(2)
    2. #include
    3. #define rep1(i,a,n) for(register int i=(a);i<(n);++i)
    4. #define rep2(i,a,n) for(register int i=(a);i<=(n);++i)
    5. #define per1(i,n,a) for( int i=(n);i>(a);i--)
    6. #define per2(i,n,a) for( int i=(n);i>=(a);i--)
    7. #define quick_cin() cin.tie(0),cout.tie(0),ios::sync_with_stdio(false)
    8. #define memset(a,i,b) memset((a),(i),sizeof (b))
    9. #define memcpy(a,i,b) memcpy((a),(i),sizeof (b))
    10. #define pro_q priority_queue
    11. #define eb emplace_back
    12. #define endl "\n"
    13. #define lowbit(m) ((-m)&(m))
    14. #define dbug(y) cout<<(y)<<"\n"
    15. #define dbug2(a,b) cout<<(a)<<" "<<(b)<<"\n"
    16. #define dbug3(a,b,c) cout<<(a)<<" "<<(b)<<" "<<(c)<<"\n"
    17. #define dbug4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<"\n"
    18. #define yi first
    19. #define er second
    20. #define tulun int e[N],ne[N],h[N],w[N],idx;
    21. #define add2(a,b) e[idx]=b,ne[idx]=h[a],h[a]=idx++;
    22. #define add3(a,b,c) w[idx]=c,e[idx]=b,ne[idx]=h[a],h[a]=idx++;
    23. #define T_solve() int T;cin>>T;while(T--)solve();
    24. #define pi 3.14159265358979323846
    25. using namespace std;
    26. typedef long long LL;
    27. typedef pair<int,int> PII;
    28. typedef pair<long long,long long> PLL;
    29. typedef double dob;
    30. const int N=3e6+10;
    31. int e[N],ne[N],h[N],idx;
    32. LL w[N];
    33. void add(int a,int b,int c)
    34. {
    35. w[idx]=c,e[idx]=b,ne[idx]=h[a],h[a]=idx++;
    36. }
    37. int k,p;
    38. int s,t;
    39. int d[N];
    40. int q[N<<1];
    41. int ceng_db[N];
    42. vector<int>ceng[N];
    43. int n,maxd;
    44. void bfs()
    45. {
    46. int hh=0,tt=0;
    47. q[0]=1;
    48. d[1]=1;
    49. ceng_db[1]=1;
    50. while(hh<=tt)
    51. {
    52. int t=q[hh++];
    53. bool f=0;
    54. for(int i=h[t];~i;i=ne[i])
    55. {
    56. int j=e[i];
    57. if(!d[j])
    58. {
    59. d[j]=d[t]+1;
    60. maxd=max(maxd,d[j]);
    61. if(!f)
    62. {
    63. f=1;
    64. ceng_db[d[j]]=j;
    65. }
    66. q[++tt]=j;
    67. }
    68. }
    69. }
    70. rep2(i,1,n)
    71. {
    72. ceng[d[i]].emplace_back(i);
    73. }
    74. }
    75. LL dist[N];
    76. int st[N];
    77. void dijkstra()
    78. {
    79. pro_q,greater>heap;
    80. heap.push({0,s});
    81. dist[s]=0;
    82. while(heap.size())
    83. {
    84. auto tt=heap.top();
    85. heap.pop();
    86. int t=tt.second;
    87. if(st[t])continue;
    88. st[t]=1;
    89. for(int i=h[t];~i;i=ne[i])
    90. {
    91. int j=e[i];
    92. // dbug4(j,dist[j],dist[t],w[i]);
    93. if(dist[j]>dist[t]+w[i])
    94. {
    95. dist[j]=dist[t]+w[i];
    96. // dbug3(t,j,dist[j]);
    97. heap.push({dist[j],j});
    98. }
    99. }
    100. }
    101. }
    102. void solve()
    103. {
    104. memset(h,-1,h);
    105. maxd=0;
    106. idx=0;
    107. cin>>n;
    108. memset(st,0,st);
    109. memset(dist,0x3f,dist);
    110. memset(d,0,d);
    111. rep2(i,0,n+5)ceng[i].clear();
    112. rep2(i,1,n-1)
    113. {
    114. int a,b,c;
    115. cin>>a>>b>>c;
    116. add(a,b,c);
    117. add(b,a,c);
    118. }
    119. cin>>k>>p;
    120. cin>>s>>t;
    121. bfs();
    122. int superv=n+1;
    123. rep2(i,1,maxd-k)
    124. {
    125. int nn=i+k;
    126. int siz1=ceng[i].size();
    127. int siz2=ceng[nn].size();
    128. rep1(j,0,siz1)
    129. {
    130. add(superv,ceng[i][j],0);
    131. add(ceng[i][j],superv,p);
    132. }
    133. rep1(j,0,siz2)
    134. {
    135. add(ceng[nn][j],superv,p);
    136. add(superv,ceng[nn][j],0);
    137. }
    138. superv++;
    139. }
    140. //rep2(i,1,n+1)dbug2(i,dist[i]);
    141. dijkstra();
    142. dbug(dist[t]);
    143. }
    144. signed main()
    145. {
    146. quick_cin();
    147. T_solve();
    148. return 0;
    149. }

    真正维护好同层之间关系的是每层用两个点,d1,d2;

    上一层都指向d1,边权为p,然后d1指向下一层,边权为0;

    下一层都指向d2,边权为p,然后d2指向上一层,边权为0;

    这样同层之间达到路径就是2p;

    code:唯一区别就是建图;

    1. #pragma GCC optimize(2)
    2. #include
    3. #define rep1(i,a,n) for(register int i=(a);i<(n);++i)
    4. #define rep2(i,a,n) for(register int i=(a);i<=(n);++i)
    5. #define per1(i,n,a) for( int i=(n);i>(a);i--)
    6. #define per2(i,n,a) for( int i=(n);i>=(a);i--)
    7. #define quick_cin() cin.tie(0),cout.tie(0),ios::sync_with_stdio(false)
    8. #define memset(a,i,b) memset((a),(i),sizeof (b))
    9. #define memcpy(a,i,b) memcpy((a),(i),sizeof (b))
    10. #define pro_q priority_queue
    11. #define eb emplace_back
    12. #define endl "\n"
    13. #define lowbit(m) ((-m)&(m))
    14. #define dbug(y) cout<<(y)<<"\n"
    15. #define dbug2(a,b) cout<<(a)<<" "<<(b)<<"\n"
    16. #define dbug3(a,b,c) cout<<(a)<<" "<<(b)<<" "<<(c)<<"\n"
    17. #define dbug4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<"\n"
    18. #define yi first
    19. #define er second
    20. #define tulun int e[N],ne[N],h[N],w[N],idx;
    21. #define add2(a,b) e[idx]=b,ne[idx]=h[a],h[a]=idx++;
    22. #define add3(a,b,c) w[idx]=c,e[idx]=b,ne[idx]=h[a],h[a]=idx++;
    23. #define T_solve() int T;cin>>T;while(T--)solve();
    24. #define pi 3.14159265358979323846
    25. using namespace std;
    26. typedef long long LL;
    27. typedef pair<int,int> PII;
    28. typedef pair<long long,long long> PLL;
    29. typedef double dob;
    30. const int N=3e6+10;
    31. int e[N],ne[N],h[N],idx;
    32. LL w[N];
    33. void add(int a,int b,int c)
    34. {
    35. w[idx]=c,e[idx]=b,ne[idx]=h[a],h[a]=idx++;
    36. }
    37. int k,p;
    38. int s,t;
    39. int d[N];
    40. int q[N<<1];
    41. int ceng_db[N];
    42. vector<int>ceng[N];
    43. int n,maxd;
    44. void bfs()
    45. {
    46. int hh=0,tt=0;
    47. q[0]=1;
    48. d[1]=1;
    49. ceng_db[1]=1;
    50. while(hh<=tt)
    51. {
    52. int t=q[hh++];
    53. bool f=0;
    54. for(int i=h[t];~i;i=ne[i])
    55. {
    56. int j=e[i];
    57. if(!d[j])
    58. {
    59. d[j]=d[t]+1;
    60. maxd=max(maxd,d[j]);
    61. if(!f)
    62. {
    63. f=1;
    64. ceng_db[d[j]]=j;
    65. }
    66. q[++tt]=j;
    67. }
    68. }
    69. }
    70. rep2(i,1,n)
    71. {
    72. ceng[d[i]].emplace_back(i);
    73. }
    74. }
    75. LL dist[N];
    76. int st[N];
    77. void dijkstra()
    78. {
    79. pro_q,greater>heap;
    80. heap.push({0,s});
    81. dist[s]=0;
    82. while(heap.size())
    83. {
    84. auto tt=heap.top();
    85. heap.pop();
    86. int t=tt.second;
    87. if(st[t])continue;
    88. st[t]=1;
    89. for(int i=h[t];~i;i=ne[i])
    90. {
    91. int j=e[i];
    92. // dbug4(j,dist[j],dist[t],w[i]);
    93. if(dist[j]>dist[t]+w[i])
    94. {
    95. dist[j]=dist[t]+w[i];
    96. // dbug3(t,j,dist[j]);
    97. heap.push({dist[j],j});
    98. }
    99. }
    100. }
    101. }
    102. void solve()
    103. {
    104. memset(h,-1,h);
    105. maxd=0;
    106. idx=0;
    107. cin>>n;
    108. memset(st,0,st);
    109. memset(dist,0x3f,dist);
    110. memset(d,0,d);
    111. rep2(i,0,n+5)ceng[i].clear();
    112. rep2(i,1,n-1)
    113. {
    114. int a,b,c;
    115. cin>>a>>b>>c;
    116. add(a,b,c);
    117. add(b,a,c);
    118. }
    119. cin>>k>>p;
    120. cin>>s>>t;
    121. bfs();
    122. int superv=n+1;
    123. rep2(i,1,maxd-k)
    124. {
    125. int nn=i+k;
    126. int d1=superv;
    127. superv++;
    128. int d2=superv;
    129. int siz1=ceng[i].size();
    130. int siz2=ceng[nn].size();
    131. rep1(j,0,siz1)
    132. {
    133. add(d2,ceng[i][j],0);
    134. add(ceng[i][j],d1,p);
    135. }
    136. rep1(j,0,siz2)
    137. {
    138. add(ceng[nn][j],d2,p);
    139. add(d1,ceng[nn][j],0);
    140. }
    141. }
    142. //rep2(i,1,n+1)dbug2(i,dist[i]);
    143. dijkstra();
    144. dbug(dist[t]);
    145. }
    146. signed main()
    147. {
    148. quick_cin();
    149. T_solve();
    150. return 0;
    151. }

    3,1012;

    开个线段树统计1~m窗口的人数和编号;

    关键在于如何更新队伍人数;

    开个小根堆记录离开时间和所在窗口,每次只要到了时间,都给他离开掉;

    1. #pragma GCC optimize(2)
    2. #include
    3. #define rep1(i,a,n) for(register int i=(a);i<(n);++i)
    4. #define rep2(i,a,n) for(register int i=(a);i<=(n);++i)
    5. #define per1(i,n,a) for( int i=(n);i>(a);i--)
    6. #define per2(i,n,a) for( int i=(n);i>=(a);i--)
    7. #define quick_cin() cin.tie(0),cout.tie(0),ios::sync_with_stdio(false)
    8. #define memset(a,i,b) memset((a),(i),sizeof (b))
    9. #define memcpy(a,i,b) memcpy((a),(i),sizeof (b))
    10. #define pro_q priority_queue
    11. #define eb emplace_back
    12. #define endl "\n"
    13. #define lowbit(m) ((-m)&(m))
    14. #define dbug(y) cout<<(y)<<"\n"
    15. #define dbug2(a,b) cout<<(a)<<" "<<(b)<<"\n"
    16. #define dbug3(a,b,c) cout<<(a)<<" "<<(b)<<" "<<(c)<<"\n"
    17. #define dbug4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<"\n"
    18. #define yi first
    19. #define er second
    20. #define tulun int e[N],ne[N],h[N],w[N],idx;
    21. #define add2(a,b) e[idx]=b,ne[idx]=h[a],h[a]=idx++;
    22. #define add3(a,b,c) w[idx]=c,e[idx]=b,ne[idx]=h[a],h[a]=idx++;
    23. #define T_solve() int T;cin>>T;while(T--)solve();
    24. #define pi 3.14159265358979323846
    25. using namespace std;
    26. typedef long long LL;
    27. #define int LL
    28. typedef pair<int,int> PII;
    29. typedef pair<long long,long long> PLL;
    30. typedef double dob;
    31. const int N=2e6+10;
    32. int n,m,a[N];
    33. int leave[N];
    34. struct node1
    35. {
    36. int start,len;
    37. bool operator <(const node1 &B)const
    38. {
    39. return start
    40. }
    41. }p[N];
    42. struct node2
    43. {
    44. int l,r;
    45. int id,minv;
    46. }tr[N<<2];
    47. void pushup(int u)
    48. {
    49. tr[u].minv=min(tr[u<<1].minv,tr[u<<1|1].minv);
    50. if(tr[u<<1].minv==tr[u].minv)tr[u].id=tr[u<<1].id;
    51. else tr[u].id=tr[u<<1|1].id;
    52. }
    53. void build(int u,int l,int r)
    54. {
    55. tr[u]={l,r,l,0};
    56. if(l==r)return;
    57. int mid=l+r>>1;
    58. build(u<<1,l,mid),build(u<<1|1,mid+1,r);
    59. pushup(u);
    60. }
    61. void modify(int u,int x,int v)
    62. {
    63. if(x==tr[u].l&&x==tr[u].r)
    64. {
    65. tr[u].minv+=v;
    66. }
    67. else
    68. {
    69. int mid=tr[u].l+tr[u].r>>1;
    70. if(x<=mid)modify(u<<1,x,v);
    71. if(x>mid)modify(u<<1|1,x,v);
    72. pushup(u);
    73. }
    74. }
    75. int query(int u,int l,int r)
    76. {
    77. return tr[u].id;
    78. }
    79. void solve()
    80. {
    81. cin>>n>>m;
    82. rep2(i,1,n)
    83. {
    84. int a,b;
    85. cin>>a>>b;
    86. p[i]={a,b};
    87. }
    88. rep2(i,1,m)leave[i]=0;
    89. build(1,1,m);
    90. sort(p+1,p+n+1);
    91. pro_q,greater>q;
    92. int ans=0;
    93. rep2(i,1,n)
    94. {
    95. while(q.size()&&q.top().first<=p[i].start)
    96. {
    97. modify(1,q.top().second,-1);
    98. q.pop();
    99. }
    100. int pos=query(1,1,m);
    101. modify(1,pos,1);
    102. leave[pos]=max(p[i].start,leave[pos])+p[i].len;
    103. q.push({leave[pos],pos});
    104. ans=max(leave[pos],ans);
    105. }
    106. dbug(ans);
    107. }
    108. signed main()
    109. {
    110. quick_cin();
    111. T_solve();
    112. return 0;
    113. }
    1. #pragma GCC optimize(2)
    2. #include
    3. #define rep1(i,a,n) for(register int i=(a);i<(n);++i)
    4. #define rep2(i,a,n) for(register int i=(a);i<=(n);++i)
    5. #define per1(i,n,a) for( int i=(n);i>(a);i--)
    6. #define per2(i,n,a) for( int i=(n);i>=(a);i--)
    7. #define quick_cin() cin.tie(0),cout.tie(0),ios::sync_with_stdio(false)
    8. #define memset(a,i,b) memset((a),(i),sizeof (b))
    9. #define memcpy(a,i,b) memcpy((a),(i),sizeof (b))
    10. #define pro_q priority_queue
    11. #define eb emplace_back
    12. #define endl "\n"
    13. #define lowbit(m) ((-m)&(m))
    14. #define dbug(y) cout<<(y)<<"\n"
    15. #define dbug2(a,b) cout<<(a)<<" "<<(b)<<"\n"
    16. #define dbug3(a,b,c) cout<<(a)<<" "<<(b)<<" "<<(c)<<"\n"
    17. #define dbug4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<"\n"
    18. #define yi first
    19. #define er second
    20. #define tulun int e[N],ne[N],h[N],w[N],idx;
    21. #define add2(a,b) e[idx]=b,ne[idx]=h[a],h[a]=idx++;
    22. #define add3(a,b,c) w[idx]=c,e[idx]=b,ne[idx]=h[a],h[a]=idx++;
    23. #define T_solve() int T;cin>>T;while(T--)solve();
    24. #define pi 3.14159265358979323846
    25. using namespace std;
    26. typedef long long LL;
    27. #define int LL
    28. typedef pair<int,int> PII;
    29. typedef pair<long long,long long> PLL;
    30. typedef double dob;
    31. const int N=2e6+10;
    32. int n,m,a[N];
    33. int leave[N];
    34. struct node1
    35. {
    36. int start,len;
    37. bool operator <(const node1 &B)const
    38. {
    39. return start
    40. }
    41. }p[N];
    42. struct node2
    43. {
    44. int l,r;
    45. int id,minv;
    46. }tr[N<<2];
    47. void pushup(int u)
    48. {
    49. tr[u].minv=min(tr[u<<1].minv,tr[u<<1|1].minv);
    50. if(tr[u<<1].minv==tr[u].minv)tr[u].id=tr[u<<1].id;
    51. else tr[u].id=tr[u<<1|1].id;
    52. }
    53. void build(int u,int l,int r)
    54. {
    55. tr[u]={l,r,l,0};
    56. if(l==r)return;
    57. int mid=l+r>>1;
    58. build(u<<1,l,mid),build(u<<1|1,mid+1,r);
    59. pushup(u);
    60. }
    61. void modify(int u,int x,int v)
    62. {
    63. if(x==tr[u].l&&x==tr[u].r)
    64. {
    65. tr[u].minv+=v;
    66. }
    67. else
    68. {
    69. int mid=tr[u].l+tr[u].r>>1;
    70. if(x<=mid)modify(u<<1,x,v);
    71. if(x>mid)modify(u<<1|1,x,v);
    72. pushup(u);
    73. }
    74. }
    75. int query(int u,int l,int r)
    76. {
    77. return tr[u].id;
    78. }
    79. void solve()
    80. {
    81. cin>>n>>m;
    82. rep2(i,1,n)
    83. {
    84. int a,b;
    85. cin>>a>>b;
    86. p[i]={a,b};
    87. }
    88. rep2(i,1,m)leave[i]=0;
    89. build(1,1,m);
    90. sort(p+1,p+n+1);
    91. pro_q,greater>q;
    92. int ans=0;
    93. rep2(i,1,n)
    94. {
    95. while(q.size()&&q.top().first<=p[i].start)
    96. {
    97. modify(1,q.top().second,-1);
    98. q.pop();
    99. }
    100. int pos=query(1,1,m);
    101. modify(1,pos,1);
    102. leave[pos]=max(p[i].start,leave[pos])+p[i].len;
    103. q.push({leave[pos],pos});
    104. ans=max(leave[pos],ans);
    105. }
    106. dbug(ans);
    107. }
    108. signed main()
    109. {
    110. quick_cin();
    111. T_solve();
    112. return 0;
    113. }

  • 相关阅读:
    redis的原理和源码-主从复制的原理介绍
    【kafka】十四、kafka生产者API
    【数据结构】排序3——交换排序(冒泡排序、快速排序)
    JavaScript (上篇)
    【UGUI】给美术的备忘录
    Cryptographic primitives(密码原语)
    SpringCloud无介绍快使用,gateway的基本使用(十六)
    数据异常值检测
    第二十一章 源代码文件 REST API 参考(三)
    Linux编译器gcc的使用
  • 原文地址:https://blog.csdn.net/aidaqiudeaichao/article/details/126140332