답안 #1039598

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1039598 2024-07-31T05:12:51 Z trucmai Growing Trees (BOI11_grow) C++17
0 / 100
1000 ms 5212 KB
#include <bits/stdc++.h>
#ifdef LOCAL
    #include "/home/trcmai/code/tools.h"
    #define debug(x...) cerr << "\e[91m"<<__func__<<":"<<__LINE__<<" [" << #x << "] = ["; _print(x); cerr << "\e[39m" << endl;
#else
    #define debug(x...)
#endif
using namespace std;
#define all(a) a.begin(), a.end()
#define ll long long
#define endl '\n'
const int N = 1e6 + 6, LOG = 27, MOD = 1e9 + 7;
const ll INF = 1e18;
int n,q;
ll a[N];
namespace fenwick{
    ll tr[N];
    void add(int i,ll val){
        for(;i < N;i += i&(-i)) tr[i] += val;
    }   
    void upd(int l,int r,ll val){
        if(l > r) return;
        r = min(r,n);
        add(l,val);
        add(r+1,-val);
    }
    ll get(int i){
        ll res = 0;
        for(;i > 0;i -= i&(-i)) res += tr[i];
        return res;
    }
    int walk(ll val){
        int l = 1,r = n + 1;
        while(l < r){
            int m = (r+l) >> 1; 
            if(get(m) >= val) r = m;
            else l = m + 1;
        }
        return l;
    }
}
signed main() {
    cin.tie(0)->sync_with_stdio(0);
    auto solver=[&](){
        cin>>n>>q;
        for(int i = 1;i <= n;++i) cin>>a[i];
        sort(a + 1,a + n + 1);
        for(int i = 1;i <= n;++i)
            fenwick::add(i,a[i] - a[i - 1]);
        while(q--){
            char t; cin>>t;
            if(t == 'F'){
                int tot; ll val; cin>>tot>>val;
                int l = fenwick::walk(val);
                int r = min(n,l + tot - 1);
                if(l > n) return; 
                tot = r - l + 1;
                ll last_val = fenwick::get(r);
                int s = fenwick::walk(last_val);
                int t = fenwick::walk(last_val + 1) - 1;
                //update first range
                fenwick::upd(l,s,1);
                //update second range 
                int ptr = t - (tot - (s - l + 1)) + 1; 
                fenwick::upd(ptr,t,1);
            }else{
                ll low,high; cin>>low>>high;
                cout<<fenwick::walk(high + 1) - fenwick::walk(low) << endl;
            }
        }
    };
    int t = 1; // cin>>t;
    while (t--) solver();
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 5212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1060 ms 860 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1022 ms 2908 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 1624 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 14 ms 3164 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 89 ms 2568 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 13 ms 1880 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 82 ms 4692 KB Output isn't correct
2 Halted 0 ms 0 KB -