Submission

Status:
[PPP][PPPP][PPP][TSSSSSS]

Score: 60

User: akuyga1

Problemset: ขั้นบันได

Language: cpp

Time: 2.081 second

Submitted On: 2025-02-26 01:04:05

#include "bits/stdc++.h"
using namespace std;
#define ii pair<int,int>
#define f first
#define s second
#define mp make_pair

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int N;
	cin>>N;
	vector<ii> A(N-1);
	int x,y;
	cin>>x>>y;
	A[0]=mp(x,y);
	for(int i=1;i<N-1;i++){
	    int x;
	    cin>>x;
	    A[i]=mp(A[i-1].s,x);
	}
	int K;
	cin>>K;
    while(K--){
        ii temp;
        cin>>temp.f>>temp.s;
        int odd=0,even=0;
        for(auto i:A){
            int a=min(i.f,i.s),b=max(i.f,i.s);
            //intersection [a,b] and temp.f temp.s
            a=max(a+1,temp.f); b=min(b-1,temp.s);
            //to count must start with odd end with even so..
            if(b<a)continue;
            if(a%2==0){a++; even++;}
            if(b<a)continue;
            if(b%2==1){b--; odd++;}
            if(b<a)continue;
            odd+=(b-a+1)/2;
            even+=(b-a+1)/2;
        }
        cout<<even<<' '<<odd<<'\n';
    }
}