Advertisement
a53

mere1

a53
Feb 22nd, 2020
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. #include <cstdio>
  2. #include <algorithm>
  3. #include <vector>
  4. #define TMax 200000
  5. #define KMax 100000
  6. long long ans;
  7. int vx[TMax+1], vy[TMax+1], n, t, k;
  8. struct Elem
  9. {
  10. int pos;
  11. int x;
  12. long long val;
  13. } Q[KMax+1];
  14.  
  15. bool cmp_pos(const Elem &A, const Elem &B)
  16. {
  17. return A.pos < B.pos;
  18. }
  19.  
  20. bool cmp_x(const Elem &A, const Elem &B)
  21. {
  22. return A.x < B.x;
  23. }
  24.  
  25. struct comparer
  26. {
  27. bool operator ()(Elem const& p, int const i) const
  28. {
  29. return p.x < i;
  30. }
  31. };
  32.  
  33. inline void add(int poz, int val)
  34. {
  35. if (poz == 0)
  36. poz = n;
  37. std::lower_bound(Q + 1, Q + k + 1, poz, comparer())->val += val;
  38. }
  39.  
  40. void read()
  41. {
  42. scanf("%d %d %d", &n, &t, &k);
  43. for (int i = 1; i <= t; ++i)
  44. {
  45. scanf("%d %d", vx + i, vy + i);
  46. }
  47. for (int i = 1; i <= k; ++i){
  48. scanf("%d", &Q[i].x);
  49. Q[i].pos = i;
  50. Q[i].val = 0;
  51. }
  52. }
  53.  
  54. void build_solution()
  55. {
  56. std::sort(Q + 1, Q + k + 1, cmp_x);
  57. for (int i = 1; i <= t; ++i)
  58. {
  59. int x = vx[i];
  60. int y = vy[i];
  61. if (y >= n)
  62. {
  63. ans += 1LL * y / n;
  64. y = y % n;
  65. }
  66. if (y == 0)
  67. {
  68. continue;
  69. }
  70. add(x, 1);
  71. if (x + y - 1 <= n)
  72. {
  73. add(x + y, -1);
  74. }
  75. else
  76. {
  77. add(1, 1);
  78. add(x + y - n, -1);
  79. }
  80. }
  81. for (int i = 1; i <= k; ++i)
  82. {
  83. Q[i].val += Q[i - 1].val;
  84. }
  85. }
  86.  
  87. void print_solution()
  88. {
  89. std::sort(Q + 1, Q + k + 1, cmp_pos);
  90. for (int i = 1; i <= k; ++i) {
  91. printf("%lld ", ans + Q[i].val);
  92. }
  93. }
  94.  
  95. int main()
  96. {
  97. freopen("mere.in", "r", stdin);
  98. freopen("mere.out", "w", stdout);
  99. read();
  100. build_solution();
  101. print_solution();
  102. return 0;
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement