#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;
ll MOD;
pll fish[500005];
vector<ll> pl[500005];
bitset<500005> vis;
ll cnt[500005];
map<ll,ll> rec[7005];
int main()
{jizz
ll n,k,ans=0,tmp,num,t;
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(fish[i].F);
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,rec[fish[i].S][j]=cnt[j]+1;
else if(j!=fish[i].S)
v.pb(MP(rec[j][fish[i].S],cnt[j]+1));
num=1,t=0;
sort(ALL(v));
while(t<v.size()&&v[t].F<=num)
tmp=tmp*v[t].S%MOD,++t;
ans=(ans+tmp)%MOD;
for(int j=0;j<pl[fish[i].S].size()&&pl[fish[i].S][j]*2<=fish[i].F;++j)
{
++num;
while(t<v.size()&&v[t].F<=num)
tmp=tmp*v[t].S%MOD,++t;
ans=(ans+tmp)%MOD;
}
}
cout << ans << "\n";
}
Compilation message
fish.cpp: In function 'int main()':
fish.cpp:48:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(t<v.size()&&v[t].F<=num)
~^~~~~~~~~
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]*2<=fish[i].F;++j)
~^~~~~~~~~~~~~~~~~~~~~
fish.cpp:54:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(t<v.size()&&v[t].F<=num)
~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
12416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
12416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
12416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
12416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
12440 KB |
Output is correct |
2 |
Correct |
13 ms |
12544 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
12416 KB |
Output is correct |
2 |
Correct |
166 ms |
24892 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
12800 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
12672 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
127 ms |
19816 KB |
Output is correct |
2 |
Correct |
148 ms |
20292 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
164 ms |
65536 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
445 ms |
65536 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
707 ms |
65536 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
271 ms |
65536 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
188 ms |
49916 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
239 ms |
53328 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
178 ms |
45916 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
274 ms |
56240 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
222 ms |
57156 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
281 ms |
60152 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |