记录编号 165874 评测结果 AAAAAAAAA
题目名称 [POJ 2823]滑动窗口 最终得分 100
用户昵称 Gravatarzys 是否通过 通过
代码语言 C++ 运行时间 0.897 s
提交时间 2015-06-13 10:28:25 内存使用 7.94 MiB
显示代码纯文本
  1. #include<cstdio>
  2. #include<queue>
  3. using namespace std;
  4. struct MAx{
  5. int bh,w;
  6. friend bool operator < ( MAx a,MAx b )
  7. {
  8. return a.w < b.w;
  9. }
  10. };
  11. MAx c1;
  12. struct MIn{
  13. int bh,w;
  14. friend bool operator < ( MIn a,MIn b )
  15. {
  16. return a.w > b.w;
  17. }
  18. };
  19. MIn c2;
  20. priority_queue<MAx> Max;
  21. priority_queue<MIn> Min;
  22. int n,k,a,b,MAX[1000000],MIN[1000000],tot;
  23. int main()
  24. {
  25. freopen("window.in","r",stdin);
  26. freopen("window.out","w",stdout);
  27. scanf("%d%d",&n,&k);
  28. for(int i=1;i<=k;i++)
  29. {
  30. scanf("%d",&a);
  31. c1.bh=i;
  32. c1.w=a;
  33. c2.bh=i;
  34. c2.w=a;
  35. Max.push(c1);
  36. Min.push(c2);
  37. }
  38. MAX[++tot]=Max.top().w;
  39. MIN[tot]=Min.top().w;
  40. for(int i=k+1;i<=n;i++)
  41. {
  42. scanf("%d",&a);
  43. c1.bh=i;
  44. c1.w=a;
  45. c2.bh=i;
  46. c2.w=a;
  47. Max.push(c1);
  48. Min.push(c2);
  49. while(Max.top().bh<=tot)
  50. Max.pop();
  51. while(Min.top().bh<=tot)
  52. Min.pop();
  53. MAX[++tot]=Max.top().w;
  54. MIN[tot]=Min.top().w;
  55. }
  56. for(int i=1;i<=tot;i++)
  57. printf("%d ",MIN[i]);
  58. printf("\n");
  59. for(int i=1;i<=tot;i++)
  60. printf("%d ",MAX[i]);
  61. // while(1);
  62. }