답안 #971586

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
971586 2024-04-29T03:28:22 Z batsukh2006 Growing Trees (BOI11_grow) C++17
100 / 100
517 ms 6224 KB
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<map>
#include<string>
#include<algorithm>
#include<vector>
#include<string.h>
#include<utility>
#include<set>
#include<cmath>
#include<queue>
#include<deque>
#include<functional>
#include<stack>
#include<limits.h>
#include<iomanip>
#include<unordered_map> 
#include<numeric>
#include<tuple>
#include<bitset>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
#define MOD 1000000007
#define int long long
#define ss second
#define ff first
#define endl '\n'
//#define ordered_set tree<pair<int, int>, null_type, less_equal<pair<int, int> >, rb_tree_tag, tree_order_statistics_node_update>
int n,q;
const int mxN=1e5+1;
vector<int> tree(4*mxN);
int cal(int node, int L, int R, int l, int r){
    if(L>r||R<l) return 0;
    if(L>=l&&R<=r) return tree[node];
    return tree[node]+cal(node*2,L,(L+R)/2,l,r)+cal(node*2+1,(L+R)/2+1,R,l,r);
}
int caln(int x){
    int l=1,r=n;
    while(l<=r){
    	int m=l+(r-l)/2;
    	if(cal(1,1,n,m,m)>=x) r=m-1;
    	else l=m+1;
    }
    return l;
}
int calx(int x){
    int l=1,r=n;
    while(l<=r){
    	int m=l+(r-l)/2;
    	if(cal(1,1,n,m,m)>x) r=m-1;
    	else l=m+1;
    }
    return l;
}
void up(int node, int L, int R, int l, int r, int v){
    if(L>r||R<l) return;
    if(L>=l&&R<=r){
        tree[node]+=v;
        return;
    }
    up(node*2,L,(L+R)/2,l,r,v);
    up(node*2+1,(L+R)/2+1,R,l,r,v);
}
signed main(){
    // freopen("file.in", "r", stdin);
    // freopen("file.out", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    cin>>n>>q;
    vector<int> a(n+1);
    for(int i=1; i<=n; i++) cin>>a[i];
    sort(a.begin(),a.end());
    for(int i=1; i<=n; i++) up(1,1,n,i,i,a[i]);
    while(q--){
    	char c; cin>>c;
    	int u,v; cin>>u>>v;
    	if(c=='F'){
    		int i=caln(v);
    		if(i<=n){
	    		int p=min(i+u-1,n);
	    		int l=caln(cal(1,1,n,p,p));
	    		int r=calx(cal(1,1,n,p,p));
	    		int need=p-l+1;
	    		up(1,1,n,i,l-1,1);
	    		up(1,1,n,r-need,r-1,1);
	    	}
    	}else{
    		cout<<calx(v)-caln(u)<<endl;
    	}
    }
    return 0;
}






























# 결과 실행 시간 메모리 Grader output
1 Correct 282 ms 4436 KB Output is correct
2 Correct 448 ms 5968 KB Output is correct
3 Correct 353 ms 6000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3416 KB Output is correct
2 Correct 6 ms 3420 KB Output is correct
3 Correct 7 ms 3420 KB Output is correct
4 Correct 4 ms 3420 KB Output is correct
5 Correct 186 ms 3652 KB Output is correct
6 Correct 210 ms 3952 KB Output is correct
7 Correct 14 ms 3672 KB Output is correct
8 Correct 118 ms 4172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 197 ms 3928 KB Output is correct
2 Correct 204 ms 4836 KB Output is correct
3 Correct 4 ms 3672 KB Output is correct
4 Correct 146 ms 4412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 171 ms 3872 KB Output is correct
2 Correct 238 ms 4840 KB Output is correct
3 Correct 24 ms 3672 KB Output is correct
4 Correct 223 ms 4816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 280 ms 4100 KB Output is correct
2 Correct 417 ms 5780 KB Output is correct
3 Correct 56 ms 3928 KB Output is correct
4 Correct 277 ms 5548 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 386 ms 4704 KB Output is correct
2 Correct 456 ms 5660 KB Output is correct
3 Correct 342 ms 5712 KB Output is correct
4 Correct 57 ms 3932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 305 ms 4812 KB Output is correct
2 Correct 270 ms 5644 KB Output is correct
3 Correct 346 ms 5716 KB Output is correct
4 Correct 56 ms 3932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 441 ms 4268 KB Output is correct
2 Correct 422 ms 4448 KB Output is correct
3 Correct 69 ms 5084 KB Output is correct
4 Correct 299 ms 5460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 372 ms 4504 KB Output is correct
2 Correct 421 ms 5984 KB Output is correct
3 Correct 517 ms 6224 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 373 ms 5128 KB Output is correct