# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
92837 | SamAnd | Money (IZhO17_money) | C++17 | 2 ms | 376 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int N = 1000006;
int n;
int a[N];
int t[N];
void ubd(int x)
{
while (x < N)
{
t[x]++;
x += (x & (-x));
}
}
int qry(int l, int r)
{
if (l > r)
return 0;
int ans = 0;
while (r > 0)
{
ans += t[r];
r -= (r & (-r));
}
--l;
while (l > 0)
{
ans -= t[l];
l -= (l & (-l));
}
return ans;
}
int main()
{
//freopen("input2.txt", "r", stdin);
scanf("%d", &n);
for (int i = 1; i <= n; ++i)
scanf("%d", &a[i]);
int ans = 1;
ubd(a[1]);
int s = a[1], ss, ssq;
for (int i = 2; i <= n; ++i)
{
if (a[i] >= a[i - 1] && qry(a[i - 1] + 1, a[i] - 1) == 0)
{
if (a[i] == s)
continue;
else if (a[i - 1] == s)
{
ss = a[i];
ssq = 1;
}
else
{
if (a[i] == ss)
{
ssq++;
}
else if (a[i - 1] == ss)
{
if (qry(a[i - 1], a[i - 1]) == ssq)
continue;
else
{
++ans;
s = a[i];
}
}
else
{
if (qry(a[i - 1], a[i - 1]))
{
++ans;
s = a[i];
}
}
}
}
else
{
++ans;
s = a[i];
}
ubd(a[i]);
}
cout << ans << endl;
return 0;
}
컴파일 시 표준 에러 (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... |