#include <bits/stdc++.h>
using namespace std;
int n,k,m,res;
pair <int, int> f[500001];
map <int, int> pos,ch,ban,cnt;
int main(){
ios_base::sync_with_stdio(NULL);cin.tie(nullptr);
cin >> n >> k >> m;
for (int i=0;i<n;i++){
cin >> f[i].first >> f[i].second;
if (!pos.count(f[i].second))
pos[f[i].second]=f[i].first;
pos[f[i].second]=min(pos[f[i].second],f[i].first);
}
sort(f,f+n);
for (int i=n-1;i>=0;i--){
if (ch.count(f[i].second))
continue;
for (int j=n-1;j>i;j--)
if (f[j].first>=pos[f[i].second]*2)
ban[f[j].second]=1;
for (int j=0;j<i;j++)
if (f[j].first*2<=f[i].first)
cnt[f[j].second]++;
int x=1;
ban[f[i].second]=1;
for (auto [i,j]:cnt)
if (!ban.count(i))
x=x*(j+1)%m;
res=(res+x*(cnt[f[i].second]+1))%m;
ch[f[i].second]=1;
int l=0;
for (int j=0;j<n;j++)
if (f[j].first*2>f[i].first&&f[j].second==f[i].second){
l=f[j].first;
break;
}
int y=1;
for (int j=i+1;j<n;j++)
if (f[j].first>=pos[f[i].second]*2&&l*2>f[j].first)
y=y*(cnt[f[j].second]+1)%m;
res=(res+x*(y+m-1))%m;
ban.clear();
cnt.clear();
}
cout << res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
476 KB |
Output is correct |
2 |
Incorrect |
248 ms |
7656 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
946 ms |
4228 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
47 ms |
600 KB |
Output is correct |
2 |
Correct |
352 ms |
676 KB |
Output is correct |
3 |
Incorrect |
493 ms |
1284 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3004 ms |
5512 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3006 ms |
7880 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3020 ms |
5368 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3036 ms |
8428 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3030 ms |
10132 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3045 ms |
11644 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3055 ms |
21092 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3012 ms |
20684 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3064 ms |
27152 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |