이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
int ans = 0;
bitset<1000502> s;
ll a[1000500];
int t[4000500];
int p[1000500];
int sz = 1000001;
inline void upd(int v, int tl, int tr, int p)
{
if(tl == tr)
{
t[v] = 1;
return;
}
int tm = tl + tr >> 1;
if(p <= tm) upd(v << 1, tl, tm, p);
else upd((v << 1) + 1, tm + 1, tr, p);
t[v] = t[v << 1] + t[(v << 1) + 1];
}
inline int get(int v, int tl , int tr, int l, int r)
{
if(l > r) return 0;
if(tl == l && tr == r)
return t[v];
int tm = tl + tr >> 1;
return get((v << 1), tl, tm, l, min(r, tm)) + get((v << 1) + 1, tm + 1, tr, max(tm + 1, l), r);
}
inline int fnd(int v, int tl, int tr, int need)
{
if(tl == tr)
return tl;
int tm = tl + tr >> 1;
if(need <= t[(v << 1)])
return fnd((v << 1), tl, tm, need);
else
return fnd((v << 1) + 1, tm + 1, tr, need- t[(v << 1)]);
}
int main()
{
scanf("%d", &n);
for(int i = 1; i <= n; ++i)
scanf("%lld", a + i);
upd(1, 1, sz, sz);
for(int i = 1; i <= n;)
{
int f = get(1, 1, sz, 1, a[i]) + 1;
int nxt = fnd(1, 1, sz, f);
ll last = a[i];
while(i <= n && a[i] <= nxt && a[i] >= last)
upd(1, 1, sz, a[i]), last = a[i], i++;
ans++;
}
printf("%d\n", ans);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
money.cpp: In function 'void upd(int, int, int, int)':
money.cpp:22:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int tm = tl + tr >> 1;
^
money.cpp: In function 'int get(int, int, int, int, int)':
money.cpp:33:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int tm = tl + tr >> 1;
^
money.cpp: In function 'int fnd(int, int, int, int)':
money.cpp:41:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int tm = tl + tr >> 1;
^
money.cpp: In function 'int main()':
money.cpp:50:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
^
money.cpp:52:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld", a + i);
^| # | 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... |