답안 #348867

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
348867 2021-01-16T01:18:17 Z alishahali1382 Sails (IOI07_sails) C++14
100 / 100
94 ms 2796 KB
#include <bits/stdc++.h>
#pragma GCC optimize ("O2,unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) {cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;}
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod=1000000007;
const int MAXN=100010, LOG=20;

int n, m, k, u, v, x, y, t, a, b, sz;
pii A[MAXN];
int B[MAXN];
int fen[MAXN];

inline void add(int pos, int val){
	for (; pos<MAXN; pos+=pos&-pos) fen[pos]+=val;
}
inline int get(int pos){
	int res=0;
	for (; pos; pos-=pos&-pos) res+=fen[pos];
	return res;
}
int BS(int val){
	int dwn=0, up=sz+1;
	while (up-dwn>1){
		int mid=(dwn+up)>>1;
		if (get(mid)<=val) up=mid;
		else dwn=mid;
	}
	return up;
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin>>n;
	for (int i=1; i<=n; i++) cin>>A[i].first>>A[i].second;
	sort(A+1, A+n+1);
	for (int i=1; i<=n; i++){
		sz=A[i].first;
		int x=A[i].second, val=get(sz-x+1);
		int a=BS(val), b=BS(val-1);
//		debug2(sz, x)
//		debug2(a, b)
		add(a, +1);
		add(a+x-(sz-b+1), -1);
		add(b, +1);
		add(sz+1, -1);
//		for (int j=1; j<=sz; j++) cerr<<get(j)<<" \n"[j==sz];
	}
	ll out=0;
	for (int i=1; i<MAXN; i++) B[i]=get(i), out+=B[i]*(B[i]-1ll)/2;
	cout<<out<<"\n";
	
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 748 KB Output is correct
2 Correct 2 ms 748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 748 KB Output is correct
2 Correct 2 ms 748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 748 KB Output is correct
2 Correct 2 ms 748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 748 KB Output is correct
2 Correct 2 ms 748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 748 KB Output is correct
2 Correct 3 ms 1132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 876 KB Output is correct
2 Correct 21 ms 1260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 1132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 1420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 73 ms 1772 KB Output is correct
2 Correct 67 ms 2796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 73 ms 1816 KB Output is correct
2 Correct 79 ms 2540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 94 ms 2028 KB Output is correct
2 Correct 69 ms 2668 KB Output is correct