#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef __int128 lll;
typedef long double ld;
typedef pair<ll, ll> pll;
#define MAX 9223372036854775807LL
#define MIN -9223372036854775807LL
#define INF 0x3f3f3f3f3f3f3f3f
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout << fixed; cout.precision(10);
#define sp << " "
#define en << "\n"
#define compress(v) sort(v.begin(), v.end()), v.erase(unique(v.begin(), v.end()), v.end())
ll n, K;
ll ss;
pll a[500010];
vector<ll> w[500010];
pll tmp[500010];
ll idx[500010];
ll ans;
struct segtree
{
ll seg[2000010];
void init(ll no, ll s, ll e)
{
seg[no] = 1;
if(s == e)
return;
init(no << 1, s, (s + e) >> 1);
init(no << 1 | 1, ((s + e) >> 1) + 1, e);
}
void update(ll no, ll s, ll e, ll w, ll v)
{
if(e < w || w < s)
return;
if(s == e)
{
seg[no] = (seg[no] + v) % ss;
return;
}
ll mid = (s + e) >> 1;
update(no << 1, s, mid, w, v);
update(no << 1 | 1, mid + 1, e, w, v);
seg[no] = seg[no << 1] * seg[no << 1 | 1] % ss;
}
ll query(ll no, ll s, ll e, ll l, ll r)
{
if(e < l || r < s || e < s)
return 1;
if(l <= s && e <= r)
return seg[no];
ll mid = (s + e) >> 1;
return (query(no << 1, s, mid, l, r) * query(no << 1 | 1, mid + 1, e, l, r)) % ss;
}
}segt;
int main(void)
{
fastio
cin >> n;
cin >> K;
cin >> ss;
for(ll i = 1 ; i <= n ; i++)
cin >> a[i].fi >> a[i].se;
sort(a + 1, a + 1 + n);
for(ll i = 1 ; i <= n ; i++)
w[a[i].se].push_back(i);
for(ll i = 1 ; i <= K ; i++)
tmp[i] = {w[i].back(), i};
sort(tmp + 1, tmp + 1 + K);
for(ll i = 1 ; i <= K ; i++)
idx[tmp[i].se] = i;
segt.init(1, 1, K);
for(ll i = 1 ; i <= n ; i++)
{
if(w[a[i].se].back() == a[i].fi)
{
ll W = 0;
ll l = 0, r = (ll)w[a[i].se].size() - 2;
while(l <= r)
{
ll mid = (l + r) >> 1;
if(a[w[a[i].se][mid]].fi * 2 <= a[i].fi)
l = mid + 1;
else
r = mid - 1;
}
W = r + 1;
l = idx[a[i].se] + 1;
r = K;
while(l <= r)
{
ll mid = (l + r) >> 1;
if(a[W].fi * 2 <= a[tmp[mid].fi].fi)
r = mid - 1;
else
l = mid + 1;
}
ll gap = segt.query(1, 1, K, 1, idx[a[i].se] - 1);
gap = gap * segt.query(1, 1, K, idx[a[i].se] + 1, r) % ss;
ans = (ans + gap) % ss;
W = w[a[i].se][0];
l = idx[a[i].se] + 1;
r = K;
while(l <= r)
{
ll mid = (l + r) >> 1;
if(a[W].fi * 2 <= a[tmp[mid].fi].fi)
r = mid - 1;
else
l = mid + 1;
}
gap = segt.query(1, 1, K, 1, r);
ans = (ans + gap) % ss;
}
segt.update(1, 1, K, idx[a[i].se], 1);
}
ans = ans % ss < 0 ? ans % ss + ss : ans % ss;
cout << ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
12116 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
9 ms |
12140 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
7 ms |
11988 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
8 ms |
11984 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
9 ms |
12116 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
7 ms |
12028 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
8 ms |
12116 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
9 ms |
12244 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
93 ms |
20256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
12224 KB |
Output is correct |
2 |
Incorrect |
11 ms |
12344 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
117 ms |
24972 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
197 ms |
31568 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
125 ms |
25012 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
199 ms |
31476 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
248 ms |
34580 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
212 ms |
30624 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
411 ms |
41440 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
307 ms |
39892 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
415 ms |
45036 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |