이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 500005;
int m;
struct seg {
vector<int> t;
seg(vector<int> f) {
t = vector<int>(2 * f.size());
for (int i = 0; i < f.size(); ++i) t[i + f.size()] = f[i] + 1;
for (int i = f.size() - 1; i >= 1; --i) t[i] = ((ll)t[2 * i] * t[2 * i + 1]) % m;
}
void upd(int p, int v) {
p += t.size() / 2;
t[p] += v;
t[p] = max(t[p], 1);
for (; p > 1; p /= 2) {
t[p / 2] = ((ll)t[p] * t[p ^ 1]) % m;
}
}
};
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, k;
cin >> n >> k >> m;
vector<int> f(k, 0);
vector<pair<int, int>> a(n);
for (auto & [x, y]: a) {
cin >> x >> y;
f[--y]++;
}
seg s(f);
sort(a.begin(), a.end(), greater<pair<int, int>>());
int ans = 0;
f = vector<int>(k, 0);
for (int i = 0, j = 0; i < n; ++i) {
if (f[a[i].second]) continue;
f[a[i].second] = 1;
while (a[j].first * 2 > a[i].first && j < n) {
s.upd(a[j].second, -1);
j++;
}
if (i != 0) s.upd(a[j].second, -n);
ans += s.t[1];
if (i > 0) s.upd(a[j].second, -n);
ans %= m;
}
cout << ans << '\n';
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
fish.cpp: In constructor 'seg::seg(std::vector<int>)':
fish.cpp:14:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
14 | for (int i = 0; i < f.size(); ++i) t[i + f.size()] = f[i] + 1;
| ~~^~~~~~~~~~
# | 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... |