# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
625919 |
2022-08-11T02:18:05 Z |
tabr |
Fish (IOI08_fish) |
C++17 |
|
770 ms |
15288 KB |
#include <bits/stdc++.h>
using namespace std;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif
long long mod = 2;
struct mint {
long long value;
mint(long long x = 0) {
value = x % mod;
if (value < 0) value += mod;
}
mint& operator+=(const mint& other) {
if ((value += other.value) >= mod) value -= mod;
return *this;
}
mint& operator-=(const mint& other) {
if ((value -= other.value) < 0) value += mod;
return *this;
}
mint& operator*=(const mint& other) {
value = value * other.value % mod;
return *this;
}
mint& operator/=(const mint& other) {
long long a = 0, b = 1, c = other.value, m = mod;
while (c != 0) {
long long t = m / c;
m -= t * c;
swap(c, m);
a -= t * b;
swap(a, b);
}
a %= mod;
if (a < 0) a += mod;
value = value * a % mod;
return *this;
}
friend mint operator+(const mint& lhs, const mint& rhs) { return mint(lhs) += rhs; }
friend mint operator-(const mint& lhs, const mint& rhs) { return mint(lhs) -= rhs; }
friend mint operator*(const mint& lhs, const mint& rhs) { return mint(lhs) *= rhs; }
friend mint operator/(const mint& lhs, const mint& rhs) { return mint(lhs) /= rhs; }
mint& operator++() { return *this += 1; }
mint& operator--() { return *this -= 1; }
mint operator++(int) {
mint result(*this);
*this += 1;
return result;
}
mint operator--(int) {
mint result(*this);
*this -= 1;
return result;
}
mint operator-() const { return mint(-value); }
bool operator==(const mint& rhs) const { return value == rhs.value; }
bool operator!=(const mint& rhs) const { return value != rhs.value; }
bool operator<(const mint& rhs) const { return value < rhs.value; }
};
string to_string(const mint& x) {
return to_string(x.value);
}
ostream& operator<<(ostream& stream, const mint& x) {
return stream << x.value;
}
istream& operator>>(istream& stream, mint& x) {
stream >> x.value;
x.value %= mod;
if (x.value < 0) x.value += mod;
return stream;
}
mint power(mint a, long long n) {
mint res = 1;
while (n > 0) {
if (n & 1) {
res *= a;
}
a *= a;
n >>= 1;
}
return res;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, k;
cin >> n >> k >> mod;
vector<pair<int, int>> f(n);
for (int i = 0; i < n; i++) {
cin >> f[i].first >> f[i].second;
f[i].second--;
}
sort(f.begin(), f.end());
vector<int> cnt(k);
for (int i = 0; i < n; i++) {
cnt[f[i].second]++;
}
map<int, int> freq0, freq1;
auto Add = [&](map<int, int>& mp, int key, int val) {
mp[key] += val;
if (mp[key] == 0) {
mp.erase(key);
}
};
auto Get = [&](map<int, int>& mp) {
mint res = 1;
for (auto [x, y] : mp) {
res *= power(x + 1, y);
}
return res;
};
for (int i = 0; i < k; i++) {
Add(freq0, cnt[i], 1);
}
vector<int> mx(k);
mint ans = 0;
set<int> done;
for (int i = n - 1, j = n - 1; i >= 0; i--) {
if (done.count(f[i].second)) {
continue;
}
while (j >= 0 && f[j].first * 2 > f[i].first) {
if (done.count(f[j].second)) {
Add(freq1, cnt[f[j].second], -1);
cnt[f[j].second]--;
Add(freq1, cnt[f[j].second], +1);
} else {
Add(freq0, cnt[f[j].second], -1);
cnt[f[j].second]--;
Add(freq0, cnt[f[j].second], +1);
}
j--;
}
if (i == n - 1) {
mx = cnt;
}
Add(freq0, cnt[f[i].second], -1);
mint t0 = Get(freq0);
mint t1 = Get(freq1);
debug(i, j, t0, t1);
if (cnt[f[i].second] == mx[f[i].second]) {
ans += t0 * (t1 - 1);
}
ans += t0 * t1 * (cnt[f[i].second] + 1);
Add(freq1, cnt[f[i].second], +1);
done.emplace(f[i].second);
}
cout << ans << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
166 ms |
4236 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
76 ms |
1896 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Incorrect |
5 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
125 ms |
2660 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
182 ms |
4228 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
113 ms |
2800 KB |
Output is correct |
2 |
Incorrect |
230 ms |
4496 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
249 ms |
4392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
312 ms |
5188 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
164 ms |
6192 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
579 ms |
12044 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
632 ms |
12028 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
770 ms |
15288 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |