Submission

Status:
[PPP][PPPP][PPP][PPPPPPP]

Score: 100

User: chawinkn

Problemset: ขั้นบันได

Language: cpp

Time: 0.029 second

Submitted On: 2024-11-25 20:00:57

#include <bits/stdc++.h>
using namespace std;

int cnt[100009], qso[100009], qse[100009];

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int n, h, prev, mn=100000, mx=0;
	cin >> n >> prev;
	for (int i = 2; i <= n; i++) {
		cin >> h;
		mn = min(h, prev), mx = max(h, prev);
		prev = h;
		cnt[mn+1]++, cnt[mx]--;
	}
	for (int i = 1; i <= 100000; i++) {
		cnt[i] += cnt[i-1];
		if (i%2 == 0) qso[i] += cnt[i];
		else qse[i] += cnt[i];
		qso[i] += qso[i-1], qse[i] += qse[i-1];
	}
	int q;
	cin >> q;
	while (q--) {
		int l, r;
		cin >> l >> r;
		cout << qso[r]-qso[l-1] << " " << qse[r]-qse[l-1] << "\n";
	}
	return 0;
}