# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1027894 |
2024-07-19T11:01:59 Z |
Tob |
Fish (IOI08_fish) |
C++14 |
|
336 ms |
56244 KB |
#include <bits/stdc++.h>
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define pb push_back
#define FIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
using namespace std;
typedef long long ll;
typedef pair <ll, ll> pii;
const int F = 5e5 + 7, ofs = (1 << 19);
int f, k, mod;
int h[F], c[F], gr[F], fi[F], la[F], cnt[F], ha[F];
vector <int> po[F];
struct T {
vector <int> t;
void init() {
t.clear(); t.resize(2*ofs, 1);
}
void update(int x, int val) {
x += ofs;
t[x] = val;
while (x /= 2) t[x] = (ll)t[2*x]*t[2*x+1]%mod;
}
int query(int x, int a, int b, int lo = 0, int hi = ofs-1) {
if (b < lo || hi < a) return 1;
if (a <= lo && hi <= b) return t[x];
int mid = (lo + hi) / 2;
return (ll)query(2*x, a, b, lo, mid)*query(2*x+1, a, b, mid+1, hi)%mod;
}
} t1, t2;
int main () {
FIO;
memset(fi, -1, sizeof fi);
memset(la, -1, sizeof la);
memset(ha, -1, sizeof ha);
cin >> f >> k >> mod;
vector <pii> v;
for (int i = 0; i < f; i++) {
cin >> h[i] >> c[i]; c[i]--;
v.pb({h[i], c[i]});
}
sort(all(v));
for (int i = 0; i < f; i++) h[i] = v[i].F, c[i] = v[i].S;
t1.init(); t2.init();
for (int i = f-1, j = f-1; i >= 0; i--) {
while (2*h[i] <= h[j]) ha[j--] = i;
gr[i] = j;
if (la[c[i]] == -1) la[c[i]] = i;
fi[c[i]] = i;
cnt[c[i]]++;
}
for (int i = 0; i < f; i++) po[c[i]].pb(i);
for (int i = 0; i < k; i++) {
if (la[i] == -1) continue;
t1.update(fi[i], cnt[i]+1);
}
int res = 0;
for (int i = f-1, j = f-1; i >= 0; i--) {
while (j > ha[i]) {
cnt[c[j]] = max(0, cnt[c[j]]-1);
t1.update(fi[c[j]], cnt[c[j]]+1);
j--;
}
if (la[c[i]] == i) {
ll dod = 1;
if (j != -1) dod = t1.query(1, 0, j);
if (i < f-1) dod *= t2.query(1, i, gr[*upper_bound(all(po[c[i]]), ha[i])]);
res = (res + dod) % mod;
t2.update(i, 2);
t1.update(fi[c[i]], 1+(cnt[c[i]]=0));
}
}
cout << res;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
33372 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
33372 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
33412 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
33372 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
33372 KB |
Output is correct |
2 |
Incorrect |
8 ms |
33448 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
33368 KB |
Output is correct |
2 |
Incorrect |
166 ms |
50404 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
33368 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
33628 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
65 ms |
40368 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
8 ms |
33368 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
100 ms |
45244 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
145 ms |
50652 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
96 ms |
45192 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
164 ms |
50100 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
182 ms |
52504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
164 ms |
49076 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
299 ms |
53172 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
270 ms |
52420 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
336 ms |
56244 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |