Submission #649855

#TimeUsernameProblemLanguageResultExecution timeMemory
649855rsjwGrowing Trees (BOI11_grow)C++17
0 / 100
1095 ms3532 KiB
#include <bits/stdc++.h> using namespace std; #define int long long 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; } signed main() { int m,i; 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; }
#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...