This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
const int sz = 1 << 19;
int n, k, mod;
pii L[500001];
int cnt[500001], last[500001];
int seg1[sz << 1], seg2[sz << 1];
bool used[500001];
int P[500001];
void update(int seg[], int i, int x) {
seg[i += sz] += x % mod + mod;
seg[i] %= mod;
while (i /= 2) seg[i] = seg[i + i] * seg[i + i + 1] % mod;
}
int query(int seg[], int e) {
int x = sz, y = sz + e;
int ret = 1;
while (x <= y) {
if ((x & 1) == 1) ret = ret * seg[x++] % mod;
if ((y & 1) == 0) ret = ret * seg[y--] % mod;
x >>= 1;
y >>= 1;
}
return ret;
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> k >> mod;
for (int i = 1; i <= n; ++i) {
cin >> L[i].first >> L[i].second;
}
sort(L + 1, L + (n + 1));
fill(seg1, seg1 + (sz << 1), 1);
fill(seg2, seg2 + (sz << 1), 1);
int j;
for (j = 1; j <= n; ++j) {
if (L[j].first * 2 > L[n].first) break;
++cnt[L[j].second];
update(seg1, L[j].second, 1);
}
for (int i = 1; i <= k; ++i) last[i] = n;
int ans = 0;
for (int i = n; i > 0; --i) {
if (used[L[i].second]) continue;
while (j > 1 && L[j - 1].first * 2 > L[i].first) {
int c = L[--j].second;
--cnt[c];
last[c] = i;
if (used[c]) update(seg2, P[c], -1);
else update(seg1, c, -1);
}
ans = (ans + seg1[1]) % mod;
int p = seg1[L[i].second + sz] - 1;
update(seg1, L[i].second, -p);
ans = (ans + mod - seg1[1]) % mod;
ans = (ans + seg1[1] * query(seg2, last[L[i].second])) % mod;
update(seg2, P[L[i].second] = i, cnt[L[i].second]);
used[L[i].second] = 1;
}
printf("%d\n", 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... |