# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
447991 |
2021-07-28T11:54:02 Z |
parsabahrami |
Fish (IOI08_fish) |
C++17 |
|
1072 ms |
53572 KB |
/* I do it for the glory */
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
#define SZ(x) (int) x.size()
#define F first
#define S second
#define lc id << 1
#define rc lc | 1
const int N = 5e5 + 10;
int lst[N], seg[N << 2], ord[N], A[N], g[N], k, mod, n;
vector<int> vec[N], tmp;
void upd(int p, int id = 1, int l = 1, int r = n + 1) {
if (r - l < 2) { seg[id] = (seg[id] + 1) % mod; return; }
int md = (l + r) >> 1;
p < md ? upd(p, lc, l, md) : upd(p, rc, md, r);
seg[id] = 1ll * seg[lc] * seg[rc] % mod;
}
int get(int ql, int qr, int id = 1, int l = 1, int r = n + 1) {
if (qr <= l || r <= ql || ql >= qr) return 1;
if (ql <= l && r <= qr) return seg[id];
int md = (l + r) >> 1;
return 1ll * get(ql, qr, lc, l, md) * get(ql, qr, rc, md, r) % mod;
}
int main() {
scanf("%d%d%d", &n, &k, &mod);
for (int i = 1; i <= n; i++) {
scanf("%d%d", &A[i], &g[i]), ord[i] = i;
}
sort(ord + 1, ord + n + 1, [&] (int i, int j) { return A[i] < A[j]; });
for (int _ = n; _; _--) {
int i = ord[_];
vec[g[i]].push_back(_); tmp.push_back(A[i]);
if (!lst[g[i]]) lst[g[i]] = _;
}
for (int i = 1; i <= k; i++)
reverse(begin(vec[i]), end(vec[i]));
reverse(begin(tmp), end(tmp));
int ret = 0;
fill(seg, seg + N * 4, 1);
for (int j = 1, pt = 0; j <= n; j++) {
int i = ord[j];
while (A[ord[pt + 1]] * 2 <= A[i]) pt++, upd(lst[g[ord[pt]]]);
if (j != lst[g[i]]) continue;
auto it = upper_bound(vec[g[i]].begin(), vec[g[i]].end(), pt);
assert(it != vec[g[i]].end());
int x = get(j, j + 1), y = get(1, j); x = (x - 1 + mod) % mod;
ret = (ret + 1ll * x * y % mod) % mod;
int nxt = lower_bound(begin(tmp), end(tmp), 2 * A[ord[*it]]) - begin(tmp) + 1;
ret = (ret + 1ll * get(j + 1, nxt) * get(1, j) % mod) % mod;
}
printf("%d\n", ret);
return 0;
}
Compilation message
fish.cpp: In function 'int main()':
fish.cpp:34:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
34 | scanf("%d%d%d", &n, &k, &mod);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
fish.cpp:36:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
36 | scanf("%d%d", &A[i], &g[i]), ord[i] = i;
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
19788 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
19812 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
19856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
19788 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
19916 KB |
Output is correct |
2 |
Correct |
12 ms |
19916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
19916 KB |
Output is correct |
2 |
Correct |
278 ms |
30192 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
19916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
19960 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
112 ms |
24444 KB |
Output is correct |
2 |
Correct |
152 ms |
25792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
19916 KB |
Output is correct |
2 |
Correct |
15 ms |
20012 KB |
Output is correct |
3 |
Correct |
15 ms |
20020 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
174 ms |
26812 KB |
Output is correct |
2 |
Correct |
318 ms |
30428 KB |
Output is correct |
3 |
Correct |
289 ms |
31272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
281 ms |
30892 KB |
Output is correct |
2 |
Correct |
315 ms |
37756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
156 ms |
26640 KB |
Output is correct |
2 |
Correct |
306 ms |
30792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
301 ms |
29872 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
339 ms |
31156 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
266 ms |
29240 KB |
Output is correct |
2 |
Correct |
456 ms |
32864 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
656 ms |
32932 KB |
Output is correct |
2 |
Correct |
467 ms |
34848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
547 ms |
33776 KB |
Output is correct |
2 |
Correct |
583 ms |
40752 KB |
Output is correct |
3 |
Correct |
636 ms |
43444 KB |
Output is correct |
4 |
Correct |
588 ms |
40624 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
831 ms |
35212 KB |
Output is correct |
2 |
Correct |
1064 ms |
52532 KB |
Output is correct |
3 |
Correct |
936 ms |
53572 KB |
Output is correct |
4 |
Correct |
1072 ms |
49780 KB |
Output is correct |