답안 #484632

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
484632 2021-11-04T22:07:56 Z badont Sails (IOI07_sails) C++17
0 / 100
30 ms 3788 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef long double LD;
typedef pair<LL,LL> pii;
typedef pair<LL,pii> ppi;
typedef pair<pii,pii> ppp;
#define FOR(i, n) for(int i = 1; i<=n; i++)
#define F0R(i, n) for(int i = 0; i<n; i++)
#define mp make_pair
#define pb push_back
#define f first
#define s second

template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout << "(" << p.f << ", " << p.s << ")"; }
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) {cout << "["; F0R(i, v.size()) {if (i) cout << ", "; cout << v[i];} return cout << "]";}

struct fen{
	vector<LL> tr;
	LL mxn;

	fen(LL sz){
		mxn = sz;
		tr.assign(sz + 5, 0);
	}

	void upd(LL g, LL k){
		for(; g <= mxn; g += g&-g)
			tr[g] += k;
	}

	LL ge(LL g){
		LL res = 0;
		for(; g; g -= g&-g)
			res += tr[g];
		return res;
	}

	LL rng(LL l, LL r){return ge(r) - ge(l - 1);}

	//maxi and mini only work with positive numbers
	LL maxi(LL k){
		//max i such that ge(i) <= k.
		//log(n) vs log^2(n) binary search
		LL running = 0, res = 0;
		LL lg = 32 - __builtin_clz(mxn);

		for(int i = lg; i>=0; i--){
			if(res + (1LL << i) > mxn) continue;
			if(running + tr[res + (1LL << i)] > k) continue;
			running += tr[res + (1LL << i)];
			res += (1LL << i);
		}

		return res;
	}

	LL mini(LL k){
		//kth order statistic
		LL running = 0, res = 0;
		LL lg = 32 - __builtin_clz(mxn);

		for(int i = lg; i>=0; i--){
			if(res + (1LL << i) > mxn) continue;
			if(running + tr[res + (1LL << i)] >= k) continue;
			running += tr[res + (1LL << i)];
			res += (1LL << i);
		}

		return res + 1;
	}
};

//var 
LL T, n;

void solve(){
	cin >> n;

	vector<pii> a(n);
	for(auto& [h, k] : a)
		cin >> h >> k;

	sort(a.begin(), a.end());
	fen tr(100000);
	LL mxin = 0;

	for (auto [h, k] : a) {
		LL rb = min(h, mxin + k);
		tr.upd(mxin + 1, 1);
		tr.upd(rb + 1, -1);
		k -= rb - mxin;
		mxin = rb; mxin %= h;

		if (k) {
			tr.upd(mxin + 1, 1);
			tr.upd(mxin + 1 + k, -1);
			mxin += k;
			mxin %= h;
		}
	}

	LL ans = 0;
	FOR(i, 100000) {
		LL x = tr.ge(i);
		ans += (x * (x - 1)) / 2;
	}

	cout << ans << '\n';
}

int main(){
	ios_base::sync_with_stdio(0); 
	cin.tie(0);

	T = 1;
	//cin >> T;
	FOR(t, T)
		solve();

	cout.flush();
	return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 1100 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 1100 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 1100 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 1100 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 1100 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 1228 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 1912 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 19 ms 2500 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 22 ms 3140 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 30 ms 3520 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 29 ms 3788 KB Output isn't correct
2 Halted 0 ms 0 KB -