You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
n개의 배열 a, b, c가 주어진다.
a[i] < b[j] < c[k] 를 만족시키는 모든 쌍의 개수를 구하는 문제.
Solution
순서 상관 없으니 정렬부터 해보면 뭔가 보인다.
b를 기준으로 살펴보자. b의 원소 중 하나를 정했다면
b보다 작은 a 배열 원소의 개수 X b보다 큰 c 배열 원소의 개수
가 해당 b 원소를 뽑았을 때 만들 수 있는 경우의 수가 된다.
모든 n에 대해 돌리면서 b의 원소를 기준으로 a, c 배열에 대해 이분 탐색을 사용하면 된다.
Code
#include<iostream>
#include<algorithm>usingnamespacestd;int a[100000];
int b[100000];
int c[100000];
intmain() {
int n;
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> a[i];
}
for (int i = 0; i < n; i++)
{
cin >> b[i];
}
for (int i = 0; i < n; i++)
{
cin >> c[i];
}
sort(a, a + n);
sort(b, b + n);
sort(c, c + n);
longlong ans = 0;
for (int i = 0; i < n; i++)
{
int aIdx = lower_bound(a, a + n, b[i]) - a - 1;
int cIdx = upper_bound(c, c + n, b[i]) - c;
if (aIdx < 0 || cIdx >= n)
{
continue;
}
ans += (longlong)(aIdx + 1) * (n - cIdx);
}
cout << ans << endl;
}
This discussion was converted from issue #18 on September 15, 2026 10:44.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Problem link
https://atcoder.jp/contests/arc084/tasks/arc084_a
Problem Summary
n개의 배열 a, b, c가 주어진다.
a[i] < b[j] < c[k] 를 만족시키는 모든 쌍의 개수를 구하는 문제.
Solution
순서 상관 없으니 정렬부터 해보면 뭔가 보인다.
b를 기준으로 살펴보자. b의 원소 중 하나를 정했다면
가 해당 b 원소를 뽑았을 때 만들 수 있는 경우의 수가 된다.
모든 n에 대해 돌리면서 b의 원소를 기준으로 a, c 배열에 대해 이분 탐색을 사용하면 된다.
Code
All reactions