Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ∧_∧
- ( ・ω・。)つ━☆・*。
- ⊂ ノ ・゜
- しーJ Accepted
- */
- // #pragma GCC optimize("O3")
- // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
- #include <bits/stdc++.h>
- #include <ext/pb_ds/assoc_container.hpp>
- #include <ext/pb_ds/tree_policy.hpp>
- #define ll long long
- #define all(x) begin(x), end(x)
- #define x first
- #define y second
- #define int long long
- using namespace std;
- using namespace __gnu_pbds;
- typedef long double ld;
- template<typename T>
- using kawaii_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
- const ld PI = atan2(0, -1);
- void seriy() {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- cout << fixed << setprecision(14);
- #ifdef _offline
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- }
- const int MAXN = 1001;
- const int MAXM = 600;
- const int INF = 1e18 + 7;
- const int BASE = 47;
- const int MOD = 1e9 + 7;
- const int MAXLOG = 51;
- const ld EPS = 1e-6;
- struct rq {
- int l, r, num;
- };
- signed main() {
- seriy();
- int n, q, k;
- cin >> n >> q >> k;
- vector<int> a(n);
- for(int i= 0; i < n; i++) {
- cin >> a[i];
- }
- vector<rq> req(q);
- for(int i = 0; i < q; i++) {
- cin >> req[i].l >> req[i].r;
- req[i].l--;
- req[i].r--;
- req[i].num = i;
- if(k == 0) {
- cout << req[i].r - req[i].l + 1 << '\n';
- }
- }
- if(k == 0) {
- return 0;
- }
- vector<int> ans(q);
- set<int> st;
- int sz = sqrt(q);
- sort(all(req), [&](rq a, rq b) {
- if(a.l / sz < b.l / sz) {
- return a.l < b.l;
- }
- return a.r < b.r;
- });
- int l = 0, r = -1;
- for(int i = 0; i < q; i++) {
- while(r < req[i].r) {
- r++;
- st.insert(a[r]);
- }
- while(r > req[i].r) {
- st.erase(a[r]);
- r--;
- }
- while(l < req[i].l) {
- st.erase(a[l]);
- l++;
- }
- while(l > req[i].l) {
- l--;
- st.insert(a[l]);
- }
- int res = 0;
- for(auto it = st.begin(); it != st.end(); it++) {
- if(it != st.begin()) {
- res += (abs(*it - *prev(it)) > k);
- }
- }
- ans[req[i].num] = res;
- }
- for(auto i : ans) {
- cout << i + 1 << " ";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement