제출 #650100

#제출 시각아이디문제언어결과실행 시간메모리
650100rsjwGrowing Trees (BOI11_grow)C++17
100 / 100
42 ms5604 KiB
#include<bits/stdc++.h>
using namespace std;
#define int long long
struct IO{
    static const int S=1<<21;
    char buf[S],*p1,*p2;int st[105],Top;
    ~IO(){clear();}
    inline void clear(){fwrite(buf,1,Top,stdout);Top=0;}
    inline void pc(const char c){Top==S&&(clear(),0);buf[Top++]=c;}
    inline char gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}
    inline IO&operator >> (char&x){while(x=gc(),x==' '||x=='\n'||x=='\r');return *this;}
    template<typename T>inline IO&operator >> (T&x){
        x=0;bool f=0;char ch=gc();
        while(ch<'0'||ch>'9'){if(ch=='-') f^=1;ch=gc();}
        while(ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+ch-'0',ch=gc();
        f?x=-x:0;return *this;
    }
    inline IO&operator << (const char c){pc(c);return *this;}
    template<typename T>inline IO&operator << (T x){
        if(x<0) pc('-'),x=-x;
        do{st[++st[0]]=x%10,x/=10;}while(x);
        while(st[0]) pc('0'+st[st[0]--]);return *this;
    }
}fin,fout;
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=0,sum=0,i;
	for(i=17;i>=0;i--) {
		if(l+(1<<i)<=n&&sum+t[l+(1<<i)]<x) l+=(1<<i),sum+=t[l];
	}
	return l+1;
}
int search_upper(int x) { //第一个大于x 
	int l=0,sum=0,i;
	for(i=17;i>=0;i--) {
		if(l+(1<<i)<=n&&sum+t[l+(1<<i)]<=x) l+=(1<<i),sum+=t[l];
	}
	return l+1;
}
signed main() {
	int m,i,j;
	char c;
	int x,y,t,t1,t2,tt;
	fin>>n>>m;
	for(i=1;i<=n;i++) fin>>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++) {
		fin>>c>>x>>y;
		if(c=='F') {
			t=search_lower(y);
			if(t+x-1>n) {
				update(t,1);
				update(n+1,-1);
			} else {
				tt=query(t+x-1);
				t1=search_lower(tt);
				t2=search_upper(tt)-1;
				update(t,1);
				update(t1,-1);
				update(t2-(x-t1+t)+1,1);
				update(t2+1,-1);
			}
			
		} else {
			fout<<search_upper(y)-search_lower(x)<<'\n';
		}
	}
	return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

grow.cpp: In member function 'IO& IO::operator<<(T)':
grow.cpp:22:9: warning: this 'while' clause does not guard... [-Wmisleading-indentation]
   22 |         while(st[0]) pc('0'+st[st[0]--]);return *this;
      |         ^~~~~
grow.cpp:22:42: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'while'
   22 |         while(st[0]) pc('0'+st[st[0]--]);return *this;
      |                                          ^~~~~~
grow.cpp: In function 'int main()':
grow.cpp:48:10: warning: unused variable 'j' [-Wunused-variable]
   48 |  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...