//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define mem(a,v) memset((a), (v), sizeof (a))
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%lld", &(n))
#define nai(a, n) for (int i = 0; i < (n); i++) ni(a[i])
#define nal(a, n) for (int i = 0; i < (n); i++) nl(a[i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%lld\n", (n))
#define pii pair<int, int>
#define pil pair<int, long long>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vil vector<pil>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int MAXN = 1e6 + 5;
const double eps = 1e-9;
pii a[MAXN];
ll dp[MAXN], cnt[MAXN], mx[MAXN];
ll c[7001][7001];
int main() {
int n, k;
scanf("%d %d %d", &n, &k, &MOD);
a[0] = mp(0, 0);
vii tmp;
for (int i = 1; i <= n; i++) {
scanf("%d %d", &a[i].fi, &a[i].se);
mx[a[i].se] = max(mx[a[i].se], (ll)a[i].fi);
}
for (int i = 1; i <= k; i++)
tmp.pb(mp(mx[i], i));
sort(tmp.begin(), tmp.end());
sort(a, a + n+1);
int p = 0, ind = 1;
for (int i1 = 1; i1 <= k; i1++) {
int i = tmp[i1-1].se;
for (int j = 1; j <= k; j++)
c[i][j] = c[p][j];
while (ind <= n && 2 * a[ind].fi <= tmp[i1-1].fi) {
c[i][a[ind].se]++;
ind++;
}
p = i;
}
ll ans = 0;
for (int i = 1; i <= k; i++) {
ll val = 1, va2 = c[i][i];
for (int j = 1; j <= k; j++) {
if (i == j)
continue;
if (c[j][i] > c[i][i])
continue;
if (mx[j] > mx[i])
val = (val * 1ll * ((ll) c[i][j] + 1ll)) % MOD;
else if (mx[j] < mx[i]) {
val = (val * 1ll * ((ll) c[i][j] + 1ll)) % MOD;
va2 = (va2 * 1ll * ((ll) c[i][j] + 1ll)) % MOD;
} else if (i < j) {
val = (val * 1ll * ((ll) c[i][j] + 1ll)) % MOD;
va2 = (va2 * 1ll * ((ll) c[i][j] + 1ll)) % MOD;
} else {
val = (val * 1ll * ((ll) c[i][j] + 1ll)) % MOD;
}
}
ans = (ans + val) % MOD;
ans = (ans + va2) % MOD;
}
prl(ans);
return 0;
}
Compilation message
fish.cpp: In function 'int main()':
fish.cpp:43:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d", &n, &k, &MOD);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
fish.cpp:47:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &a[i].fi, &a[i].se);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
172 ms |
4464 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
896 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
560 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
64 ms |
3576 KB |
Output is correct |
2 |
Correct |
82 ms |
3576 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
236 ms |
41592 KB |
Output is correct |
2 |
Correct |
40 ms |
12416 KB |
Output is correct |
3 |
Correct |
124 ms |
29944 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
197 ms |
30224 KB |
Output is correct |
2 |
Correct |
393 ms |
55264 KB |
Output is correct |
3 |
Correct |
401 ms |
56132 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
288 ms |
43896 KB |
Output is correct |
2 |
Runtime error |
220 ms |
65536 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
154 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 |
167 ms |
12408 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
191 ms |
13172 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
251 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 |
225 ms |
16612 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
177 ms |
16740 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
254 ms |
19036 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |