Submission #649854

#TimeUsernameProblemLanguageResultExecution timeMemory
649854rsjwGrowing Trees (BOI11_grow)C++17
0 / 100
1074 ms2720 KiB
#include <bits/stdc++.h> using namespace std; int n; int t[100010],a[100010]; void update(int x,int I) { while(x<=n) t[x]+=I,x+=x&-x; } int query(int x) { int ans=0; while(x) ans+=t[x],x-=x&-x; return ans; } //写个假的二分 int search_lower(int x) { //第一个大于等于x int l=1,r=n,mid; while(l<=r) { mid=(l+r)/2; if(query(mid)<x) l=mid+1; else r=mid-1; } return r+1; } int search_upper(int x) { //第一个大于x int l=1,r=n,mid; while(l<=r) { mid=(l+r)/2; if(query(mid)<=x) l=mid+1; else r=mid-1; } return r+1; } int main() { int m,i,j; char c; int x,y,t,t2; cin>>n>>m; for(i=1;i<=n;i++) cin>>a[i]; sort(a+1,a+n+1); for(i=1;i<=n;i++) update(i,a[i]-a[i-1]); for(i=1;i<=m;i++) { cin>>c>>x>>y; if(c=='F') { t=search_lower(y); update(t,1); update(t+x-1,-1); t2=search_upper(query(t+x-1))-1; update(t2,1); update(t2+1,-1); } else cout<<search_upper(y)-search_lower(x)<<endl; } return 0; }

Compilation message (stderr)

grow.cpp: In function 'int main()':
grow.cpp:31:10: warning: unused variable 'j' [-Wunused-variable]
   31 |  int m,i,j;
      |          ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...