## 답안 #100947

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
100947 2019-03-15T11:26:51 Z shafinalam Growing Trees (BOI11_grow) C++14
10 / 100
822 ms 6136 KB
```#include <bits/stdc++.h>

using namespace std;

const int mx = 1e5+5;
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef pair<int,int>pii;
typedef pair<int,pii>piii;

#define  sf scanf
#define  pf printf

#define  input freopen("input.txt","r",stdin)
#define  output freopen("output.txt","w",stdout)

#define  inf 1e16
#define  ff first
#define  ss second
#define  MP make_pair
#define  pb push_back
#define  all(v) v.begin(), v.end()
#define  printcase(cases) printf("Case %d:", cases);
#define  Unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define  FAST  ios_base::sync_with_stdio(0);cout.tie(0)
#define  endl printf("\n")
#define  __lcm(a, b) ((a*b)/__gcd(a, b))

int  Set(int N,int pos)
{
return N=N | (1<<pos);
}
int  reset(int N,int pos)
{
return N= N & ~(1<<pos);
}
bool check(int N,int pos)
{
return (bool)(N & (1<<pos));
}

ll tree[mx<<2];
ll lazy[mx<<2];
ll arr[mx];
int n, m;

void push(int node, int b,int e)
{
if(lazy[node])
{
int left = node<<1;
int right = left|1;
tree[node]+=((e-b+1)*lazy[node]);
if(b!=e)
{
lazy[left]+=lazy[node];
lazy[right]+=lazy[node];
}
lazy[node] = 0;
}
return;
}
void update(int node, int b, int e, int l, int r)
{
push(node, b, e);
if(b>r || e<l) return;
if(b>=l && e<=r)
{
lazy[node]++;
push(node, b, e);
return;
}
int mid = (b+e)>>1;
int left = node<<1;
int right = left|1;
update(left, b, mid, l, r);
update(right, mid+1, e, l, r);
tree[node] = tree[left]+tree[right];
}
int query(int node, int b, int e, int pos)
{
push(node, b, e);
if(b>pos || e<pos)
return 0;
if(b==e && pos==b)
return tree[node];
int mid = (b+e)>>1;
int left = node<<1;
int right = left|1;
if(pos<=mid) return query(left, b, mid, pos);
return query(right, mid+1, e, pos);
}
int get(int pos)
{
return query(1, 1, n, pos);
}
int main()
{
sf("%d%d", &n, &m);

for(int i = 1; i <= n; i++) sf("%lld", &arr[i]);
sort(arr+1, arr+n+1);

while(m--)
{
char type;
cin >> type;

if(type=='F')
{
ll h, c;
sf("%lld%lld", &c, &h);

int lo = 1, hi = n, pos = -1;
while(lo<=hi)
{
int mid = (lo+hi)>>1;
if(arr[mid]+get(mid)>=h)
{
pos = mid;
hi = mid-1;
}
else
lo = mid+1;
}
if(pos==-1) continue;
int last = pos+c-1;
last = min(last, n);
if(last==n || arr[last]+get(last)!=arr[last+1]+get(last+1)) update(1, 1, n, pos, last);
else
{
int l, r, val = arr[last]+get(last);
lo = 1, hi = n;
while(lo<=hi)
{
int mid = (lo+hi)>>1;
if(arr[mid]+get(mid)<val)
{
lo = mid+1;
l = mid;
}
else hi = mid-1;
}
lo = 1, hi = n;
while(lo<=hi)
{
int mid = (lo+hi)>>1;
if(arr[mid]+get(mid)>val)
{
r = mid;
hi = mid-1;
}
else lo = mid+1;
}
l++;
r--;
int len = last-l+1;
update(1, 1, n, pos, l-1);
update(1, 1, n, r-len+1, r);

}
//for(int i = 1; i <= n; i++) pf("%lld ", arr[i]+get(i));
//cout << '\n';
}
else
{
ll a, b;
sf("%lld%lld", &a, &b);

int l = -1, r = -1, lo = 1, hi = n;

while(lo<=hi)
{
int mid = (lo+hi)>>1;
if(arr[mid]+get(mid)>=a)
{
l = mid;
hi = mid-1;
}
else lo = mid+1;
}
if(l==-1)
{
pf("0\n");
continue;
}
lo = 1, hi = n;
while(lo<=hi)
{
int mid = (lo+hi)>>1;
if(arr[mid]+get(mid)<=b)
{
r = mid;
lo = mid+1;
}
else hi = mid-1;
}
pf("%d\n", r-l+1);
}
}
return 0;
}
```

### Compilation message

```grow.cpp: In function 'int main()':
grow.cpp:100:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
sf("%d%d", &n, &m);
^
grow.cpp:102:35: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(int i = 1; i <= n; i++) sf("%lld", &arr[i]);
^
grow.cpp:113:15: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
sf("%lld%lld", &c, &h);
^
grow.cpp:169:15: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
sf("%lld%lld", &a, &b);
^
grow.cpp:157:18: warning: 'r' may be used uninitialized in this function [-Wmaybe-uninitialized]
r--;
~^~
grow.cpp:159:23: warning: 'l' may be used uninitialized in this function [-Wmaybe-uninitialized]
update(1, 1, n, pos, l-1);
~~~~~~^~~~~~~~~~~~~~~~~~~```

#### Subtask #1 0 / 10.0

# 결과 실행 시간 메모리 Grader output
1 Incorrect 337 ms 5884 KB Output isn't correct
2 Halted 0 ms 0 KB -

#### Subtask #2 0 / 10.0

# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 384 KB Output is correct
2 Incorrect 13 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -

#### Subtask #3 0 / 10.0

# 결과 실행 시간 메모리 Grader output
1 Incorrect 317 ms 972 KB Output isn't correct
2 Halted 0 ms 0 KB -

#### Subtask #4 0 / 10.0

# 결과 실행 시간 메모리 Grader output
1 Incorrect 331 ms 924 KB Output isn't correct
2 Halted 0 ms 0 KB -

#### Subtask #5 0 / 10.0

# 결과 실행 시간 메모리 Grader output
1 Incorrect 309 ms 3348 KB Output isn't correct
2 Halted 0 ms 0 KB -

#### Subtask #6 0 / 10.0

# 결과 실행 시간 메모리 Grader output
1 Incorrect 403 ms 5440 KB Output isn't correct
2 Halted 0 ms 0 KB -

#### Subtask #7 0 / 10.0

# 결과 실행 시간 메모리 Grader output
1 Incorrect 412 ms 5612 KB Output isn't correct
2 Halted 0 ms 0 KB -

#### Subtask #8 0 / 10.0

# 결과 실행 시간 메모리 Grader output
1 Incorrect 611 ms 5868 KB Output isn't correct
2 Halted 0 ms 0 KB -

#### Subtask #9 0 / 10.0

# 결과 실행 시간 메모리 Grader output
1 Incorrect 456 ms 6136 KB Output isn't correct
2 Halted 0 ms 0 KB -

#### Subtask #10 10.0 / 10.0

# 결과 실행 시간 메모리 Grader output
1 Correct 822 ms 5892 KB Output is correct