답안 #768358

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
768358 2023-06-28T02:10:04 Z Charizard2021 Sails (IOI07_sails) C++17
30 / 100
72 ms 2992 KB
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false);; cin.tie(NULL)
void selfMax(long long& a, long long b){
    a = max(a, b);
}
void selfMin(long long& a, long long b){
    a = min(a, b);
}
template<typename T> istream& operator>>(istream& in, vector<T>& a) {for(auto &x : a) in >> x; return in;};
template<typename T1, typename T2> istream& operator>>(istream& in, pair<T1, T2>& x) {return in >> x.first >> x.second;}

template<typename T1, typename T2> ostream& operator<<(ostream& out, const pair<T1, T2>& x) {return out << x.first << ' ' << x.second;}
template<typename T> ostream& operator<<(ostream& out, vector<T>& a) {for(auto &x : a) out << x << ' '; return out;};
template<typename T> ostream& operator<<(ostream& out, vector<vector<T> >& a) {for(auto &x : a) out << x << '\n'; return out;};
template<typename T1, typename T2> ostream& operator<<(ostream& out, vector<pair<T1, T2> >& a) {for(auto &x : a) out << x << '\n'; return out;};

/*

Use DSU dsu(N);

*/
struct DSU {
	vector<long long> e;
	DSU(long long N) { e = vector<long long>(N, -1); }

	// get representive component (uses path compression)
	long long get(long long x) { return e[x] < 0 ? x : e[x] = get(e[x]); }

	bool same_set(long long a, long long b) { return get(a) == get(b); }

	long long size(long long x) { return -e[get(x)]; }

	bool unite(long long x, long long y) {  // union by size
		x = get(x), y = get(y);
		if (x == y) return false;
		if (e[x] > e[y]) swap(x, y);
		e[x] += e[y]; e[y] = x;
		return true;
	}
};
/*

Run with Bit<long long> BIT

*/
template <class T> class BIT {
    private:
        long long size;
        vector<T> bit;
        vector<T> arr;
    public:
        BIT(long long size) : size(size), bit(size + 1), arr(size) {}
        void set(long long ind, long long val) { add(ind, val - arr[ind]); }
        void add(long long ind, long long val) {
            arr[ind] += val;
            for (; ind <= size; ind += ind & -ind) { bit[ind] += val; }
        }
        T pref_sum(long long ind) {
            T total = 0;
            for (; ind > 0; ind -= ind & -ind) { total += bit[ind]; }
            return total;
        }
};
/*

Change Comb for specific Seg tree probs, but run with Seg<long long> Seg;

*/
template<class T> struct Seg {
	const T ID = 1e18; T comb(T a, T b) { return min(a,b); }
	long long n; vector<T> seg;
	void init(long long _n) { n = _n; seg.assign(2*n,ID); }
	void pull(long long p) { seg[p] = comb(seg[2*p],seg[2*p+1]); }
	void upd(long long p, T val) {
		seg[p += n] = val; for (p /= 2; p; p /= 2) pull(p); }
	T query(long long l, long long r) {
		T ra = ID, rb = ID;
		for (l += n, r += n+1; l < r; l /= 2, r /= 2) {
			if (l&1) ra = comb(ra,seg[l++]);
			if (r&1) rb = comb(seg[--r],rb);
		}
		return comb(ra,rb);
	}
};
int main(){
    IOS;
    int n;
    cin >> n;
    pair<int, int> v[1 + n];
    for(int i = 1; i <= n; i++){
        cin >> v[i].first >> v[i].second;
    }
    sort(v + 1, v + n + 1);
    int max_height = v[n].first;
    BIT<int> Bit(max_height);
    for(int i = 1; i <= n; i++){
        int h = v[i].first;
        int k = v[i].second;
        int difference = h - k + 1;
        int cur = Bit.pref_sum(difference);
        int ans = -1;
        int low = difference;
        int high = h;
        while(low <= high){
            int mid = (low + high)/2;
            if(Bit.pref_sum(mid) >= cur){
                ans = mid;
                low = mid + 1;
            }
            else{
                high = mid - 1;
            }
        }
        int ans2 = -1;
        int low2 = 1;
        int high2 = difference;
        while(low2 <= high2){
            int mid2 = (low2 + high2)/2;
            if(Bit.pref_sum(mid2) <= cur){
                ans2 = mid2;
                high2 = mid2 - 1;
            }
            else{
                low2 = mid2 + 1;
            }
        }
        Bit.add(ans + 1, 1);
        Bit.add(h + 1, -1);
        Bit.add(ans2, 1);
        Bit.add(ans2 + k - (h - ans), -1);
    }
    int ans = 0;
    for(int i = 1; i <= max_height; i++){
        int value = Bit.pref_sum(i);
        ans += value * (value - 1)/2;
    }
    cout << ans << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 6 ms 1096 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 12 ms 1008 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 32 ms 1564 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 56 ms 2548 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 53 ms 2840 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 72 ms 2992 KB Output isn't correct
2 Halted 0 ms 0 KB -