Submission

Status:

[PPP][PPPP][PPP][PPPPPPP]

Subtask/Task Score:

{10/10}{25/25}{25/25}{40/40}

Score: 100

User: anonymous

Problemset: ขั้นบันได

Language: cpp

Time: 1.154 second

Submitted On: 2026-11-07 23:53:36

#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+7;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int n,q,mx = -1e9;cin >> n;
    int h[N] = {0},save[N] = {0}, go[N] = {0};
    for(int i=0;i<n;i++){
        cin >> h[i];
        if(i){
            int l = h[i-1];
            int r = h[i];
            if(r < l) swap(l,r);
                for(int i=l+1;i<r;i++){
                    if(i%2) save[i]++;
                    else go[i]++;
                }
        }
    }

    for(int i =1;i<=100000;i++){
        save[i] += save[i-1];
        go[i] += go[i-1];
    }

    cin >> q;
    while(q--){
        int l,r; cin >> l >> r;
        cout << go[r] - go[l-1] << ' ' << save[r] - save[l-1] << '\n';
    }
}