# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
480685 | MilosMilutinovic | Growing Trees (BOI11_grow) | C++14 | 134 ms | 4152 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
const int nax=100*1007;
int n, q;
int tab[nax];
ll fen[nax];
void dodaj(int a, int b, int w)
{
for (int i=b; i; i-=(i&(-i)))
fen[i]+=w;
for (int i=a-1; i; i-=(i&(-i)))
fen[i]-=w;
}
int get(int v)
{
int ret=0;
for (int i=v; i<nax; i+=(i&(-i)))
ret+=fen[i];
return ret;
}
int getl(int h)
{
int bot=1, top=n, ans=n+1;
while (bot<=top)
{
int mid=bot+top>>1;
if (get(mid)>=h)
{
ans=mid;
top=mid-1;
}
else
{
bot=mid+1;
}
}
return ans;
}
int main()
{
scanf("%d %d", &n, &q);
for (int i=1; i<=n; i++)
{
scanf("%d", &tab[i]);
}
sort(tab+1, tab+n+1);
for (int i=1; i<=n; i++)
{
dodaj(i, i, tab[i]);
}
while (q--)
{
char typ;
scanf("\n%c",&typ);
if (typ=='F')
{
int c, h;
scanf("%d %d", &c, &h);
int L = getl(h), R = min(n, L+c-1);
if (get(L)!=get(R))
{
int gde=getl(get(R))-1;
dodaj(L, gde, 1);
c-=(gde-L+1);
int pos=getl(get(R)+1)-1;
dodaj(pos, pos-c+1, 1);
}
else
{
int gde=getl(get(tab[R]+1))-1;
dodaj(max(L, gde-c+1), gde, 1);
}
}
else
{
int L,R;
scanf("%d %d", &L, &R);
printf("%d\n", getl(R+1)-getl(L));
}
}
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... |
# | 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... |