답안 #295823

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
295823 2020-09-10T02:54:20 Z caoash Sails (IOI07_sails) C++14
0 / 100
1000 ms 3448 KB
#include <bits/stdc++.h> 
using namespace std;

using ll = long long;

using vi = vector<int>;
#define pb push_back
#define rsz resize
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()

using pi = pair<int,int>;
#define f first
#define s second
#define mp make_pair

const int MX = 100005;

template<int SZ> struct BIT {
    int bit[SZ];
    void upd(int i, int x) {
        // cerr << "CHANGING: " << i << " " << x << '\n';
        for (; i < SZ; i += (i & -i)) {
            // cerr << "UPD: " << i << '\n';
            bit[i] += x;
        }
    }
    ll qry(int i) {
        // cerr << "QUERY: " << i << '\n';
        ll ret = 0;
        for (; i > 0; i -= (i & -i)) {
            // cerr << "GOTO: " << i << '\n';
            ret += bit[i];
        }
        // cerr << ret << '\n';
        return ret;
    }
};

BIT<MX + 5> orz;

void upd(int l, int r) {
    l++, r++;
    orz.upd(l, 1);
    orz.upd(r + 1, -1);
}

int get(int x) {
    return orz.qry(x + 1);
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin >> n;
    vector<pi> sails(n);
    for (int i = 0; i < n; i++) {
        cin >> sails[i].f >> sails[i].s;
    }
    sort(all(sails));
    // cerr << '\n';
    auto getl = [&](int val) {
        int lo = 0; 
        int hi = MX - 1;
        int ans = 0;
        while(lo <= hi) {
            int mid = (lo + hi) / 2;
            int curr = get(mid);
            if (curr < val) {
                lo = mid + 1;
            }
            else {
                ans = mid;
                hi = mid - 1;
            }
        }
        return ans;
    };
    auto getr = [&](int val) {
        int lo = 0; 
        int hi = MX - 1;
        int ans = 0;
        while(lo <= hi) {
            int mid = (lo + hi) / 2;
            int curr = get(mid);
            if (curr <= val) {
                lo = mid + 1;
                ans = mid;
            }
            else {
                hi = mid - 1;
            }
        }
        return ans;
    };
    for (int i = 0; i < n; i++) {
        int cl = MX - sails[i].f, cr = cl + sails[i].s - 1;
        cerr << "range: " << cl << " " << cr << '\n';
        int val = get(cr);
        cerr << "val: " << val << '\n';
        int cf = max(cl, getl(val)), cs = getr(val);
        cerr << "l, r: " << cf << " " << cs << '\n';
        int rem = sails[i].s;
        if (cf > cl) {
            cerr << "updating: " << cl << " " << cf - 1 << '\n';
            upd(cl, cf - 1);
            rem -= (cf - cl);
        }
        cerr << rem << '\n';
        cerr << "updating: " << cs - rem + 1 << " " << cs << '\n';
        upd(cs - rem + 1, cs);
        for (int i = cl; i < MX; i++) {
            cerr << i << '\n';
            cerr << get(i) << " ";
            cerr << '\n';
        }
        cerr << '\n';
    }
    ll ans = 0;
    for (int i = 0; i < MX; i++) {
        ll cv = get(i);
        if (cv > 0) {
            cerr << "i, val: " << i << " " << get(i) << '\n';
        }
        ans += ((cv - 1) * cv) / 2;
    }
    cerr << ans << '\n';
}

# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 236 ms 760 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1071 ms 1536 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1087 ms 1528 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1066 ms 2184 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1080 ms 2552 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1069 ms 3008 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1091 ms 3324 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1092 ms 3448 KB Time limit exceeded
2 Halted 0 ms 0 KB -