Submission
Status:
[PPP][PPPP][PPP][P-SSSSS]
Subtask/Task Score:
{10/10}{25/25}{25/25}{0/40}
Score: 60
User: NovemNotes
Problemset: ขั้นบันได
Language: cpp
Time: 0.720 second
Submitted On: 2025-10-17 12:55:47
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int L = 1e5;
int32_t main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);
int n;cin >> n;
vector<int> v(n);
int h=0;
for(auto &x:v){
cin >> x;
h=max(h,x);
}
vector<int> v1(L+2,0),v2(L+2,0);
for(int i=0;i<n-1;i++){
int n1 = v[i];
int n2 = v[i+1];
if(n1>n2)swap(n1,n2);
for(int j=n1+1;j<n2;j++){
if(j&1){
v1[j]++;
}else{
v2[j]++;
}
}
}
for(int j=1;j<L;j++){
v1[j]+=v1[j-1];
v2[j]+=v2[j-1];
}
// for(int j=0;j<=h;j++){
// cout << v1[j] << " ";
// }cout << "\n";
// for(int j=0;j<=h;j++){
// cout << v2[j] << " ";
// }cout << "\n";
int q;cin >> q;
while(q--){
int a,b;cin >> a >> b;
a=max(a-1,0LL);
cout << v2[b]-v2[a] << " " << v1[b]-v1[a] << "\n";
}
return 0;
}