이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int n, k, m, segtree[2000000];
tuple<int, int, int> f[500000];
pair<int, int> mx[500000];
int ord[500000], idx[500000];
void increment(int pos, int node = 1, int l = 0, int r = k - 1) {
if (l == r) segtree[node] = (segtree[node] + 1) % m;
else {
int mid = (l + r) / 2;
if (pos > mid) increment(pos, node * 2 + 1, mid + 1, r);
else increment(pos, node * 2, l, mid);
segtree[node] = (segtree[node * 2] * segtree[node * 2 + 1]) % m;
}
}
int query(int pos, int node = 1, int l = 0, int r = k - 1) {
if (l > pos) return 1;
if (r <= pos) return segtree[node];
int mid = (l + r) / 2;
return (query(pos, node * 2, l, mid) * query(pos, node * 2 + 1, mid + 1, r)) % m;
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> k >> m;
fill(segtree, segtree + 4 * k, 1);
for (int i = 0; i < n; i++) {
int l, t;
cin >> l >> t;
t--;
mx[t] = max(mx[t], {l, i});
f[i] = {l, t, i};
}
sort(f, f + n);
iota(ord, ord + k, 0);
sort(ord, ord + k, [](int A, int B) { return mx[A] < mx[B]; });
for (int i = 0; i < k; i++) idx[ord[i]] = i;
int ans = 0;
for (int i = 0, j = 0; i < n; i++) {
while (get<0>(f[i]) >= get<0>(f[j]) * 2) increment(idx[get<1>(f[j++])]);
if (get<2>(f[i]) == mx[get<1>(f[i])].second) ans = (ans + query(idx[get<1>(f[i])])) % m;
}
cout << ans;
return 0;
}
# | 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... |