Advertisement
GerONSo

F 20

Jan 5th, 2020
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.51 KB | None | 0 0
  1. /*
  2.  
  3. ∧_∧
  4. ( ・ω・。)つ━☆・*。
  5. ⊂  ノ    ・゜
  6. しーJ   Accepted
  7.  
  8. */
  9.  
  10.  
  11.  
  12. // #pragma GCC optimize("O3")
  13. // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
  14.  
  15. #include <bits/stdc++.h>
  16. #include <ext/pb_ds/assoc_container.hpp>
  17. #include <ext/pb_ds/tree_policy.hpp>
  18.  
  19. #define ll long long
  20. #define all(x) begin(x), end(x)
  21. #define x first
  22. #define y second
  23. #define int long long
  24.  
  25. using namespace std;
  26. using namespace __gnu_pbds;
  27.  
  28. typedef long double ld;
  29. template<typename T>
  30. using kawaii_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
  31.  
  32. const ld PI = atan2(0, -1);
  33.  
  34. void seriy() {
  35. ios::sync_with_stdio(0);
  36. cin.tie(0);
  37. cout.tie(0);
  38. cout << fixed << setprecision(14);
  39. #ifdef _offline
  40. freopen("input.txt", "r", stdin);
  41. freopen("output.txt", "w", stdout);
  42. #endif
  43. }
  44.  
  45. const int MAXN = 1001;
  46. const int MAXM = 600;
  47. const int INF = 1e18 + 7;
  48. const int BASE = 47;
  49. const int MOD = 1e9 + 7;
  50. const int MAXLOG = 51;
  51. const ld EPS = 1e-6;
  52.  
  53. struct rq {
  54. int l, r, num;
  55. };
  56.  
  57. signed main() {
  58. seriy();
  59. int n, q, k;
  60. cin >> n >> q >> k;
  61. vector<int> a(n);
  62. for(int i= 0; i < n; i++) {
  63. cin >> a[i];
  64. }
  65.  
  66. vector<rq> req(q);
  67. for(int i = 0; i < q; i++) {
  68. cin >> req[i].l >> req[i].r;
  69. req[i].l--;
  70. req[i].r--;
  71. req[i].num = i;
  72. if(k == 0) {
  73. cout << req[i].r - req[i].l + 1 << '\n';
  74. }
  75. }
  76. if(k == 0) {
  77. return 0;
  78. }
  79.  
  80.  
  81. vector<int> ans(q);
  82. set<int> st;
  83. int sz = sqrt(q);
  84. sort(all(req), [&](rq a, rq b) {
  85. if(a.l / sz < b.l / sz) {
  86. return a.l < b.l;
  87. }
  88. return a.r < b.r;
  89. });
  90. int l = 0, r = -1;
  91. for(int i = 0; i < q; i++) {
  92. while(r < req[i].r) {
  93. r++;
  94. st.insert(a[r]);
  95. }
  96. while(r > req[i].r) {
  97. st.erase(a[r]);
  98. r--;
  99. }
  100. while(l < req[i].l) {
  101. st.erase(a[l]);
  102. l++;
  103. }
  104. while(l > req[i].l) {
  105. l--;
  106. st.insert(a[l]);
  107. }
  108. int res = 0;
  109. for(auto it = st.begin(); it != st.end(); it++) {
  110. if(it != st.begin()) {
  111. res += (abs(*it - *prev(it)) > k);
  112. }
  113. }
  114. ans[req[i].num] = res;
  115. }
  116. for(auto i : ans) {
  117. cout << i + 1 << " ";
  118. }
  119. return 0;
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement