#include <bits/stdc++.h>
#define jizz ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define pb push_back
#define ET cout << "\n"
#define MEM(i,j) memset(i,j,sizeof i)
#define F first
#define S second
#define MP make_pair
#define ALL(v) v.begin(),v.end()
#define DB(a,s,e) {for(int i=s;i<e;++i) cout << a[i] << " ";ET;}
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll INF=1e9;
ll MOD;
pll fish[500005];
vector<pll> pl[500005];
bitset<500005> vis;
ll cnt[500005];
int main()
{jizz
ll n,k,ans=0,tmp,num;
cin >> n >> k >> MOD;
for(int i=0;i<n;++i)
cin >> fish[i].F >> fish[i].S;
sort(fish,fish+n);
for(int i=0;i<n;++i)
pl[fish[i].S].pb(MP(fish[i].F,1));
for(int i=n-1;i>=0;--i)
if(!vis[fish[i].S])
{
vector<pll> v;
vis[fish[i].S]=1,tmp=1;
for(int j=1;j<=k;++j)
cnt[j]=0;
for(int j=0;j<n&&fish[j].F*2<=fish[i].F;++j)
++cnt[fish[j].S];
for(int j=1;j<=k;++j)
if(!vis[j])
{
tmp=tmp*(cnt[j]+1)%MOD;
if(cnt[j]==0) pl[j].back().S=pl[j].back().S*(upper_bound(ALL(pl[fish[i].S]),MP(pl[j].back().F/2,INF))-pl[fish[i].S].begin()+1)%MOD;
else if(cnt[j]<pl[j].size())
pl[j][cnt[j]-1].S=pl[j][cnt[j]-1].S*(upper_bound(ALL(pl[fish[i].S]),MP(pl[j].back().F/2,INF))-pl[fish[i].S].begin()+1)%MOD;
}
num=1,tmp=tmp*pl[fish[i].S].back().S%MOD;
ans=(ans+tmp)%MOD;
for(int j=0;j<pl[fish[i].S].size()&&pl[fish[i].S][j].F*2<=fish[i].F;++j)
tmp=tmp*pl[fish[i].S][j].S%MOD,ans=(ans+tmp)%MOD;
}
cout << ans << "\n";
}
Compilation message
fish.cpp: In function 'int main()':
fish.cpp:46:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
else if(cnt[j]<pl[j].size())
~~~~~~^~~~~~~~~~~~~
fish.cpp:51:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=0;j<pl[fish[i].S].size()&&pl[fish[i].S][j].F*2<=fish[i].F;++j)
~^~~~~~~~~~~~~~~~~~~~~
fish.cpp:25:19: warning: variable 'num' set but not used [-Wunused-but-set-variable]
ll n,k,ans=0,tmp,num;
^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
12160 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
12160 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
12160 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
12132 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
12160 KB |
Output is correct |
2 |
Correct |
13 ms |
12160 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
12160 KB |
Output is correct |
2 |
Correct |
179 ms |
29184 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
12160 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
12288 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
126 ms |
21432 KB |
Output is correct |
2 |
Correct |
149 ms |
22444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
75 ms |
12180 KB |
Output is correct |
2 |
Correct |
40 ms |
12416 KB |
Output is correct |
3 |
Correct |
61 ms |
12288 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
529 ms |
25872 KB |
Output is correct |
2 |
Correct |
1524 ms |
36128 KB |
Output is correct |
3 |
Correct |
1220 ms |
37564 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2310 ms |
32120 KB |
Output is correct |
2 |
Correct |
1326 ms |
39160 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
867 ms |
25748 KB |
Output is correct |
2 |
Execution timed out |
3036 ms |
32348 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3028 ms |
30968 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3017 ms |
33532 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3042 ms |
27168 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3050 ms |
33660 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3045 ms |
33416 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3024 ms |
35836 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |