# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
335524 | luciocf | Money (IZhO17_money) | C++14 | 381 ms | 15084 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6+10;
int a[maxn];
struct FenwickTree
{
int bit[maxn];
void upd(int x, int v)
{
for (; x < maxn; x += (x&-x))
bit[x] += v;
}
int soma(int x)
{
int ans = 0;
for (; x > 0; x -= (x&-x))
ans += bit[x];
return ans;
}
int get(int s)
{
int pos = 0, soma = 0;
for (int i = 20; i >= 0; i--)
if (pos+(1<<i) < maxn && soma + bit[pos+(1<<i)] < s)
pos += (1<<i), soma += bit[pos];
return pos+1;
}
} BIT;
int main(void)
{
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++)
{
scanf("%d", &a[i]);
BIT.upd(a[i], 1);
}
int ans = 0;
for (int r = n; r >= 1; r--)
{
++ans;
int l = r;
BIT.upd(a[l], -1);
while (l > 1 && a[l-1] == a[l])
{
l--;
BIT.upd(a[l], -1);
}
while (l > 1)
{
if (a[l] == a[r] && a[l-1] != BIT.get(BIT.soma(a[l]-1))) break;
if (a[l] != a[r] && a[l-1] != BIT.get(BIT.soma(a[l]))) break;
--l;
BIT.upd(a[l], -1);
}
r = l;
}
printf("%d\n", ans);
}
컴파일 시 표준 에러 (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... |