# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
297228 | Kastanda | Fish (IOI08_fish) | C++11 | 562 ms | 9164 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// M
#include<bits/stdc++.h>
#define x first
#define y second
using namespace std;
const int N = 500005;
int n, k, Mod, C[N], M[N], Last[N], S[N * 2], MX[N];
pair < int , int > A[N];
inline void Set(int i, int val)
{
S[i += k - 1] = val;
for (; i; i >>= 1)
S[i >> 1] = S[i] * 1LL * S[i ^ 1] % Mod;
}
inline int GetMult(int l, int r)
{
int rt = 1;
for (l += k - 1, r += k - 1; l < r; l >>= 1, r >>= 1)
{
if (l & 1) rt = rt * 1LL * S[l ++] % Mod;
if (r & 1) rt = rt * 1LL * S[-- r] % Mod;
}
return rt;
}
int main()
{
scanf("%d%d%d", &n, &k, &Mod);
for (int i = 1; i <= n; i ++)
scanf("%d%d", &A[i].x, &A[i].y);
sort(A + 1, A + n + 1);
for (int i = 1; i <= n; i ++)
Last[A[i].y] = i;
int r = 1;
while (r < n && A[r].x * 2 <= A[n].x)
r ++;
int l = 1;
int tot = 0;
for (int i = 1; i <= k; i ++)
Set(i, 1);
for (int i = 1; i <= n; i ++)
if (A[i].x * 2 <= A[n].x)
MX[A[i].y] ++;
for (int i = r; i <= n; i ++)
if (Last[A[i].y] == i)
{
while (l <= n && A[l].x * 2 <= A[i].x)
{
C[A[l].y] ++;
Set(A[l].y, C[A[l].y] + 1);
l ++;
}
if (MX[A[i].y] >= C[A[i].y] + 1)
continue;
int vl = GetMult(1, A[i].y) * 1LL * GetMult(A[i].y + 1, k + 1) % Mod;
if (i == n)
vl = vl * 1LL * (C[A[i].y] + 1) % Mod;
tot = (tot + vl) % Mod;
}
M[A[n].y] = 1;
for (int i = 1; i <= k; i ++)
Set(i, 1), C[i] = 0;
l = 1;
while (l < n)
{
if (!M[A[l].y])
{
C[A[l].y] ++;
Set(A[l].y, C[A[l].y] + 1);
}
l ++;
}
for (int i = n - 1; i; i --)
if (!M[A[i].y] && i == Last[A[i].y])
{
while (l > 1 && A[l - 1].x * 2 > A[i].x)
{
l --;
if (!M[A[l].y])
{
C[A[l].y] --;
Set(A[l].y, C[A[l].y] + 1);
}
}
int vl = GetMult(1, A[i].y) * 1LL * GetMult(A[i].y + 1, k + 1) % Mod;
if (A[i].x * 2 > A[n].x && MX[A[i].y] < C[A[i].y] + 1)
vl = vl * 1LL * (C[A[i].y]) % Mod;
else
vl = vl * 1LL * (C[A[i].y] + 1) % Mod;
tot = (tot + vl) % Mod;
C[A[i].y] = 0;
M[A[i].y] = 1;
Set(A[i].y, 1);
}
return !printf("%d\n", tot);
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |