답안 #593368

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
593368 2022-07-11T01:42:05 Z Do_you_copy Growing Trees (BOI11_grow) C++17
0 / 100
100 ms 3372 KB
#include <bits/stdc++.h>
#define taskname "test"
#define fi first
#define se second
#define pb push_back
#define faster ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;
using ll = long long;
using pii = pair <int, int>;
using pil = pair <int, ll>;
using pli = pair <ll, int>;
using pll = pair <ll, ll>;
using ull = unsigned ll;
mt19937 Rand(chrono::steady_clock::now().time_since_epoch().count());

ll min(const ll &a, const ll &b){
    return (a < b) ? a : b;
}

ll max(const ll &a, const ll &b){
    return (a > b) ? a : b;
}

//const ll Mod = 1000000009;
//const ll Mod2 = 999999999989;
//only use when required
const int maxN = 1e5 + 1;

int n, m;
int bit[maxN];
int a[maxN];

void update(int x, int val){
    for (; x <= n; x += x & -x){
        bit[x] += val;
    }
}

int get(int x){
    int ans = 0;
    for (; x; x -= x & -x){
        ans += bit[x];
    }
    return ans;
}

void updatehigh(int x, int y){
    int l = 1, r = n;
    while (l <= r){
        int mid = (l + r) / 2;
        if (get(mid) < y) l = mid + 1;
        else r = mid - 1;
    }
    ++r;
    if (r + x - 1 >= n){
        update(r, 1);
        return;
    }
    x = r + x - 1;
    int z = get(x);
    l = r; r = x;
    while (l <= r){
        int mid = (l + r) / 2;
        if (get(mid) != z) l = mid + 1;
        else r = mid - 1;
    }
    int ll = r + 1;
    l = x; r = n;
    while (l <= r){
        int mid = (l + r) / 2;
        if (get(mid) != z) r = mid - 1;
        else l = mid + 1;
    }
    int rr = r + 1;
    if (ll != 1){
        update(1, 1);
        update(ll, -1);
    }
    update(rr - (x - (ll - 1)), 1);
    update(rr, -1);
}

int getlow(int x){
    int l = 1, r = n;
    while (l <= r){
        int mid = (l + r) / 2;
        if (get(mid) < x) l = mid + 1;
        else r = mid - 1;
    }
    //cerr << r << " " << x << "?\n";
    return r;
}

int gethigh(int x){
    int l = 1, r = n;
    while (l <= r){
        int mid = (l + r) / 2;
        if (get(mid) <= x) l = mid + 1;
        else r = mid - 1;
    }
    //cerr << r << " " << x << "!\n";
    return r;
}


void Init(){
    cin >> n >> m;
    for (int i = 1; i <= n; ++i){
        cin >> a[i];
    }
    sort(a + 1, a + n + 1);
    for (int i = 1; i <= n; ++i) update(i, a[i] - a[i - 1]);
    while (m--){
        /*for (int i = 1; i <= n; ++i) cerr << get(i) << " ";
        cerr << "\n";*/
        char c; cin >> c;
        if (c == 'F'){
            int x, y;
            cin >> x >> y;
            updatehigh(x, y);
        }
        else{
            int l, r;
            cin >> l >> r;
            cout << gethigh(r) - getlow(l) << "\n";
        }
    }
}


int main(){
    if (fopen(taskname".inp", "r")){
        freopen(taskname".inp", "r", stdin);
        //freopen(taskname".out", "w", stdout);
    }
    faster;
    ll tt = 1;
    //cin >> tt;
    while (tt--){
        Init();
    }
}

Compilation message

grow.cpp: In function 'int main()':
grow.cpp:133:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  133 |         freopen(taskname".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 49 ms 2124 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 31 ms 1480 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 35 ms 1552 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 65 ms 1868 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 46 ms 1872 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 46 ms 1968 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 83 ms 2704 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 54 ms 2324 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 100 ms 3372 KB Output isn't correct
2 Halted 0 ms 0 KB -