# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
838254 |
2023-08-26T12:12:40 Z |
caganyanmaz |
Fish (IOI08_fish) |
C++14 |
|
975 ms |
65536 KB |
#include <bits/stdc++.h>
#define pb push_back
#define mp(x...) array<int, 2>({x})
using namespace std;
//#define DEBUGGING
#ifdef DEBUGGING
#include "../debug.h"
#else
#define debug(x...) void(42)
#endif
constexpr static int MXN = 5e5;
constexpr static int MXST = MXN<<1;
constexpr static int INF = 1e9;
int MOD, n, k;
int add() { return 0; }
int mul() { return 1; }
template<typename... V>
int add(int a, V... v) { return (a+add(v...)) % MOD; }
template<typename... V>
int mul(int64_t a, V... v) { return (a*mul(v...)) % MOD; }
int st[MXST];
int last_point[MXN];
array<int, 2> v[MXN];
void update(int i, int val) { for (st[i+=k]+=val;i>1;i>>=1) st[i>>1] = mul(st[i], st[i^1]); }
int query(int l, int r)
{
int res = 1;
for (l+=k,r+=k;l<r;l>>=1,r>>=1)
{
if (l&1) res = mul(res, st[l++]);
if (r&1) res = mul(res, st[--r]);
}
return res;
}
array<int, 2> last[MXN];
set<int> pos[MXN];
int p[MXN];
void manage_types()
{
vector<int> a;
for (int i = 0; i < n; i++)
a.pb(v[i][1]);
sort(a.begin(), a.end());
auto it = unique(a.begin(), a.end());
a.erase(it, a.end());
for (int i = 0; i < n; i++)
v[i][1] = lower_bound(a.begin(), a.end(), v[i][1]) - a.begin();
for (int i = 0; i < n; i++)
last[v[i][1]] = {i, v[i][1]};
sort(last, last + k);
for (int i = 0; i < k; i++)
p[last[i][1]] = k-i-1;
for (int i = 0; i < n; i++)
v[i][1] = -p[v[i][1]];
sort(v, v + n);
for (int i = 0; i < n; i++)
v[i][1] = -v[i][1];
}
void manage_pos()
{
for (int i = 0; i < n; i++)
pos[v[i][1]].insert(v[i][0]);
}
set<array<int, 2>> ee;
int main()
{
cin >> n;
cin >> k;
cin >> MOD;
for (int i = 0; i < n; i++)
cin >> v[i][0] >> v[i][1];
sort(v, v + n);
fill(st, st + 2*k, 1);
manage_types();
manage_pos();
for (int i = 0; i < n; i++)
debug(v[i]);
int r;
for (r = 0; v[r][0]*2 <= v[n-1][0]; r++)
update(v[r][1], 1);
int sum = query(0, k);
debug(sum);
ee.insert({v[n-1][0], 0});
int j = 1;
for (int i = n-2; i>= 0; i--)
{
if (v[i][1] != j)
continue;
last_point[i] = *pos[v[i][1]].upper_bound(v[i][0] / 2);
j++;
}
for (int i = 0; i < k; i++)
pos[i].clear();
j = 1;
for (int i = n-2; i >= 0; i--)
{
debug(v[i][1], j);
if (v[i][1] != j)
continue;
while (v[r-1][0]*2>v[i][0])
{
debug(r-1);
update(v[--r][1], -1);
}
auto it = ee.lower_bound(mp(last_point[i]*2, -INF));
if (it != ee.begin())
it--;
int ls;
if (it == ee.end())
ls = 0;
else
{
ls = -(*it)[1];
if (last_point[i]*2 <= (*it)[0])
ls++;
}
debug(v[i][1], ls, *it, last_point[i]);
int all_zero = query(j, k);
debug(ls, j, j+1, k);
int some_zero = mul(query(ls, j), query(j+1, k));
int inter = query(j+1, k);
debug(all_zero, some_zero, inter);
debug(v[i][0], j, all_zero, some_zero, inter);
sum = add(sum, all_zero, some_zero, -inter);
debug(v[i][0], v[i][1]);
ee.insert(mp(v[i][0], -v[i][1]));// Current point
j++;
}
cout << sum << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
23764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
14 ms |
23916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23808 KB |
Output is correct |
2 |
Correct |
495 ms |
51108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
24020 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
213 ms |
32820 KB |
Output is correct |
2 |
Correct |
240 ms |
37468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
24020 KB |
Output is correct |
2 |
Correct |
21 ms |
24148 KB |
Output is correct |
3 |
Correct |
19 ms |
24020 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
325 ms |
40312 KB |
Output is correct |
2 |
Correct |
560 ms |
51328 KB |
Output is correct |
3 |
Correct |
535 ms |
51248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
410 ms |
29868 KB |
Output is correct |
2 |
Correct |
608 ms |
51316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
259 ms |
41440 KB |
Output is correct |
2 |
Correct |
596 ms |
51556 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
528 ms |
48952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
622 ms |
51288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
382 ms |
46864 KB |
Output is correct |
2 |
Correct |
677 ms |
55044 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
775 ms |
52884 KB |
Output is correct |
2 |
Correct |
508 ms |
44340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
624 ms |
49756 KB |
Output is correct |
2 |
Correct |
782 ms |
54916 KB |
Output is correct |
3 |
Correct |
746 ms |
62384 KB |
Output is correct |
4 |
Correct |
783 ms |
55088 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
896 ms |
62532 KB |
Output is correct |
2 |
Correct |
912 ms |
65536 KB |
Output is correct |
3 |
Correct |
798 ms |
65536 KB |
Output is correct |
4 |
Correct |
975 ms |
65536 KB |
Output is correct |