This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//#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[7003][7003];
int main() {
int n, k;
scanf("%d %d %d", &n, &k, &MOD);
if (k > 7000) return 0;
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 (stderr)
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:48: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);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |