답안 #879159

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
879159 2023-11-26T14:17:39 Z dosts Growing Trees (BOI11_grow) C++14
100 / 100
84 ms 5364 KB
#include <bits/stdc++.h>
using namespace std;
#define sp << " " << 
#define int long long
#define vi vector<int>
#define F(xxx,yyy) for (int xxx=1;xxx<=yyy;xxx++)
#define pii pair<int,int>
const int N = 2e5+1;
vi a(N,0),bit(N,0);
int n;
void add(int p,int v) {
  for (int i=p;i<=n;i+=i&-i) bit[i]+=v;
} 
int get(int p) {
  int ans = 0;
  for (int i=p;i>0;i-=i&-i) ans+=bit[i];
  return ans;
} 
void solve() {
  int q;
  cin >> n >> q;
  F(i,n) cin >> a[i];
  sort(a.begin()+1,a.begin()+n+1);
  while (q--) {
    char cc;
    cin >> cc;
    if (cc == 'F') {
      int c,h;
      cin >> c >> h; 
      int l = 1;
      int r = n;
      while (l<=r) {
        int m = (l+r) >> 1; 
        if (get(m)+a[m] < h) l = m+1;
        else r = m-1;
      }
      if (l > n) continue;
      int L = l;
      int R = L+c-1;
      if (R >= n) {
        add(l,1);
        continue;
      }
      int x = a[R]+get(R);
      l = 1;
      r = n;
      while (l<=r) {
        int m = (l+r) >> 1;
        if (a[m]+get(m) < x) l = m+1;
        else r = m-1; 
      }
      int L2 = r+1;
      l = L2;
      r = n;
      while (l<=r) {
        int m = (l+r) >> 1;
        if (a[m]+get(m) <= x) l = m+1;
        else r = m-1;
      }
      int R2 = r;
      add(L,1);
      if(L2<n)add(L2,-1);
      add(R2-(c-(L2-L))+1,1);
      if(R2<n)add(R2+1,-1);
    }
    else {
      int l,r;
      cin >> l >> r;
      int l2 = 1;
      int r2 = n;
      while (l2<=r2) {
        int m = (l2+r2) >> 1;
        if (a[m]+get(m) < l) l2 = m+1;
        else r2 = m-1;
      }
      int firs = r2+1;
      l2 = 1;
      r2 = n;
      while (l2<=r2) {
        int m = (l2+r2) >> 1;
        if (a[m]+get(m) <= r) l2 = m+1;
        else r2 = m-1;
      }
      int lst = r2;
      cout << lst-firs+1 << '\n';
    }
  }
}	
    
                 
                             
signed main() { 
  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  #ifdef Local
  freopen("in","r",stdin);
  freopen("out","w",stdout);
  #endif
  int t = 1;
  //cin >> t;
	F(i,t) solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 54 ms 3800 KB Output is correct
2 Correct 84 ms 5200 KB Output is correct
3 Correct 30 ms 5208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3420 KB Output is correct
2 Correct 3 ms 3420 KB Output is correct
3 Correct 3 ms 3420 KB Output is correct
4 Correct 2 ms 3416 KB Output is correct
5 Correct 37 ms 4620 KB Output is correct
6 Correct 42 ms 4728 KB Output is correct
7 Correct 4 ms 3672 KB Output is correct
8 Correct 25 ms 4592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 3920 KB Output is correct
2 Correct 44 ms 4948 KB Output is correct
3 Correct 2 ms 3420 KB Output is correct
4 Correct 27 ms 4416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 3932 KB Output is correct
2 Correct 54 ms 4768 KB Output is correct
3 Correct 5 ms 3676 KB Output is correct
4 Correct 47 ms 4964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 54 ms 3664 KB Output is correct
2 Correct 80 ms 4812 KB Output is correct
3 Correct 14 ms 4088 KB Output is correct
4 Correct 26 ms 4852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 68 ms 3668 KB Output is correct
2 Correct 82 ms 4864 KB Output is correct
3 Correct 29 ms 5260 KB Output is correct
4 Correct 14 ms 3932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 3732 KB Output is correct
2 Correct 55 ms 4948 KB Output is correct
3 Correct 30 ms 5200 KB Output is correct
4 Correct 14 ms 3928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 83 ms 3596 KB Output is correct
2 Correct 78 ms 4832 KB Output is correct
3 Correct 23 ms 4184 KB Output is correct
4 Correct 51 ms 4692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 72 ms 3872 KB Output is correct
2 Correct 82 ms 5204 KB Output is correct
3 Correct 84 ms 5364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 82 ms 3920 KB Output is correct