이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
#define rep(i, j, k) for (int i = j; i < k; i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define mt make_tuple
#define iv inline void
#define ii inline int
#define ill inline ll
template <typename S, typename T>
inline bool smin(S& l, T r) {
return r < l ? l = r, 1 : 0;
}
template <typename S, typename T>
inline bool smax(S& l, T r) {
return l < r ? l = r, 1 : 0;
}
int MOD = 1e9 + 7; // 998244353;
template <typename S>
inline S mod(S& l) {
return l = (l % MOD + MOD) % MOD;
}
template <typename S, typename T>
inline S add(S& l, T r) {
return mod(l += r);
}
ill po(ll v, ll u) {
return u ? po(v * v % MOD, u >> 1) * (u & 1 ? v : 1) % MOD : 1;
}
ll gcd(ll v, ll u) { return v ? gcd(u % v, v) : u; }
void fileIO(string s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
constexpr int N = 5e5 + 10;
int F, k;
pii p[N];
bitset<N> mark, have;
int arr[N], ptr;
ll answer;
pll seg[N << 2];
inline pll merge(pll l, pll r) {
return pll(l.first * r.first % MOD, (l.first * r.second + l.second) % MOD);
}
void segInit(int l = 0, int r = k, int id = 1) {
if (l == r - 1) {
seg[id] = {1, 2};
return;
}
int mid = l + r >> 1;
segInit(l, mid, id << 1);
segInit(mid, r, id << 1 | 1);
}
void segAdd(int pos, int l = 0, int r = k, int id = 1) {
if (l == r - 1) {
seg[id].first++;
seg[id].second++;
return;
}
int mid = l + r >> 1;
if (pos < mid)
segAdd(pos, l, mid, id << 1);
else
segAdd(pos, mid, r, id << 1 | 1);
seg[id] = merge(seg[id << 1], seg[id << 1 | 1]);
}
pll segGet(int s, int t, int l = 0, int r = k, int id = 1) {
if (l >= s && r <= t) return seg[id];
if (l >= t || r <= s) return {1, 0};
int mid = l + r >> 1;
return merge(segGet(s, t, l, mid, id << 1),
segGet(s, t, mid, r, id << 1 | 1));
}
int main() {
#ifndef LOCAL
// fileIO("");
#endif
cin >> F >> k >> MOD;
rep(i, 0, F) cin >> p[i].first >> p[i].second;
sort(p, p + F);
for (int i = F - 1; ~i; i--)
if (!have[p[i].second]) {
arr[p[i].second] = ptr++;
mark[i] = true;
have[p[i].second] = true;
}
segInit();
int R = 0;
rep(i, 0, F) {
while (R < F && p[i].first * 2 > p[R].first) {
if (mark[R]) ptr--;
R++;
}
add(answer, segGet(0, k - ptr).first * segGet(k - ptr, k).second);
segAdd(arr[p[i].second]);
}
cout << answer << endl;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
fish.cpp: In function 'void segInit(int, int, int)':
fish.cpp:71:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid = l + r >> 1;
~~^~~
fish.cpp: In function 'void segAdd(int, int, int, int)':
fish.cpp:82:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid = l + r >> 1;
~~^~~
fish.cpp: In function 'pll segGet(int, int, int, int, int)':
fish.cpp:93:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid = l + r >> 1;
~~^~~
fish.cpp: In function 'void fileIO(std::__cxx11::string)':
fish.cpp:46:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
freopen((s + ".in").c_str(), "r", stdin);
~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fish.cpp:47:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
freopen((s + ".out").c_str(), "w", stdout);
~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |