Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- Unreal Engine 5
- BFS
- 그래프
- 유니온 파인드
- 스택
- 재귀
- Team Fortress 2
- 백트래킹
- 다익스트라
- 우선순위 큐
- XR Interaction Toolkit
- DFS
- 트리
- 정렬
- 구현
- 유니티
- 자료구조
- c++
- 수학
- 시뮬레이션
- 백준
- 다이나믹 프로그래밍
- 브루트포스
- 누적 합
- 투 포인터
- VR
- 그리디 알고리즘
- 알고리즘
- ue5
- 문자열
Archives
- Today
- Total
1일1알
백준 11663번 선분 위의 점 C++ 본문
https://www.acmicpc.net/problem/11663
11663번: 선분 위의 점
첫째 줄에 점의 개수 N과 선분의 개수 M이 주어진다. (1 ≤ N, M ≤ 100,000) 둘째 줄에는 점의 좌표가 주어진다. 두 점이 같은 좌표를 가지는 경우는 없다. 셋째 줄부터 M개의 줄에는 선분의 시작점과
www.acmicpc.net
이분탐색
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <limits.h>
using namespace std;
using int64 = long long;
int n, m;
vector<int> v;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> m;
v = vector<int>(n);
for (int i = 0; i < n; i++) {
cin >> v[i];
}
sort(v.begin(), v.end());
for (int i = 0; i < m; i++) {
int s, e;
cin >> s >> e;
int left = lower_bound(v.begin(), v.end(), s) - v.begin();
int right = upper_bound(v.begin(), v.end(), e) - v.begin();
cout << right - left << "\n";
}
}
'알고리즘' 카테고리의 다른 글
백준 17451번 평행 우주 C++ (0) | 2023.01.13 |
---|---|
백준 2660번 회장뽑기 C++ (0) | 2023.01.12 |
백준 18115번 카드 놓기 C++ (0) | 2023.01.10 |
백준 17391번 무한부스터 C++ (0) | 2023.01.09 |
백준 2785번 체인 C++ (1) | 2023.01.08 |