Submission

Status:
[PPP][TSSS][TSS][xSSSSSS]

Score: 10

User: ShynyC

Problemset: ขั้นบันได

Language: cpp

Time: 2.086 second

Submitted On: 2025-04-17 23:41:37

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
    int n,temp,q,l,h,ghostcount = 0,humancount = 0;
    cin >> n;
    vector<int> rooms,ghost,human;
    for(int i = 0; i < n; i++){
        cin >> temp;
        rooms.push_back(temp);
    }
    for(int i = 1; i < n; i++){
        if(rooms[i] < rooms[i-1]){
            for(int j = rooms[i]+1; j < rooms[i-1]; j++){
                if(j%2 == 0){
                    ghost.push_back(j);
                }else{
                    human.push_back(j);
                }
            }
        }else{
            for(int j = rooms[i]-1; j > rooms[i-1]; j--){
                if(j%2 == 0){
                    ghost.push_back(j);
                }else{
                    human.push_back(j);
                }
            }
        }
    }
    cin >> q;
    for(int i = 0; i < q; i++){
        cin >> l >> h;
        for(int j = 0; j < ghost.size(); j++){
            if(ghost[j] >= l && ghost[j] <= h){
                ghostcount++;
            }
        }
        for(int j = 0; j < human.size(); j++){
            if(human[j] >= l && human[j] <= h){
                humancount++;
            }
        }
        cout << ghostcount << " " << humancount << "\n";
        ghostcount = 0;
        humancount = 0;
    }
}