# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
53863 | baactree | Fish (IOI08_fish) | C++17 | 1214 ms | 31900 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll tree[1 << 20];
int sz = 1 << 19;
int n, m, mod;
pair<int, int> arr[500005];
vector<int> vec[500005];
bool chk[500005];
int t[500005];
void update(int idx, int val) {
idx += sz;
tree[idx] = val;
idx /= 2;
while (idx) {
tree[idx] = tree[idx * 2] * tree[idx * 2 + 1] % mod;
idx /= 2;
}
}
ll query(int le, int ri) {
le += sz;
ri += sz;
ll ret = 1;
while (le <= ri) {
if (le & 1)ret = ret * tree[le++] % mod;
if (!(ri & 1))ret = ret * tree[ri--] % mod;
le /= 2;
ri /= 2;
}
return ret;
}
int main() {
scanf("%d%d%d", &n, &m, &mod);
for (int i = 0; i < n; i++)
scanf("%d%d", &arr[i].first, &arr[i].second);
sort(arr, arr + n);
int cnt = 0;
for (int i = n - 1; i >= 0; i--) {
if (!chk[arr[i].second]) {
t[arr[i].second] = ++cnt;
chk[arr[i].second] = true;
}
}
for (int i = 0; i < n; i++) {
arr[i].second = t[arr[i].second];
vec[arr[i].second].push_back(i);
}
ll ans = 0;
for (int i = 0; i < 500005; i++)
tree[i + sz] = 1;
for (int i = sz - 1; i; i--)
tree[i] = tree[i * 2] * tree[i * 2 + 1] % mod;
int idx = 0;
int ri = 500004;
for (int i = 0; i < n; i++) {
while (arr[idx].first * 2 <= arr[i].first) {
update(arr[idx].second, tree[arr[idx].second + sz] + 1);
idx++;
}
if (vec[arr[i].second].back()==i) {
ans = (ans + query(arr[i].second, 500004)) % mod;
ll temp = tree[arr[idx].second + sz];
update(arr[idx].second, 1);
int it = -1;
for (auto x : vec[arr[i].second]) {
if (arr[x].first > arr[i].first / 2) {
it = x;
break;
}
}
int le = arr[it].first * 2;
int l, r, mid, ri;
l = 1;
r = arr[i].second;
while (l <= r) {
mid = (l + r) / 2;
if (arr[vec[mid].back()].first < le) {
ri = mid;
r = mid - 1;
}
else l = mid + 1;
}
ans = (ans + query(ri, 500004)) % mod;
update(arr[idx].second, temp);
}
}
printf("%lld\n", ans);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |