結果

問題 No.728 ギブ and テイク
ユーザー gazellegazelle
提出日時 2018-08-24 21:57:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 211 ms / 3,000 ms
コード長 1,235 bytes
コンパイル時間 2,182 ms
コンパイル使用メモリ 207,888 KB
実行使用メモリ 23,364 KB
最終ジャッジ日時 2023-09-05 11:39:48
合計ジャッジ時間 6,677 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 10 ms
4,380 KB
testcase_14 AC 17 ms
4,492 KB
testcase_15 AC 8 ms
4,376 KB
testcase_16 AC 16 ms
4,520 KB
testcase_17 AC 15 ms
4,440 KB
testcase_18 AC 145 ms
13,192 KB
testcase_19 AC 158 ms
13,944 KB
testcase_20 AC 186 ms
19,056 KB
testcase_21 AC 161 ms
14,692 KB
testcase_22 AC 61 ms
7,788 KB
testcase_23 AC 40 ms
6,804 KB
testcase_24 AC 119 ms
11,800 KB
testcase_25 AC 118 ms
11,700 KB
testcase_26 AC 60 ms
7,536 KB
testcase_27 AC 211 ms
19,112 KB
testcase_28 AC 138 ms
23,364 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define MOD 1000000007ll
#define INF 1000000000ll
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v) sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

ll N = 300030;
ll bit[300030];
void add(ll a, ll w) {
	a++;
	for (ll x = a; x <= N; x += x & -x) bit[x] += w;
}
ll sum(ll a) {
	a++;
	ll ret = 0;
	for (ll x = a; x > 0; x -= x & -x) ret += bit[x];
	return ret;
}
void init() {
	for(ll i=0; i < N; i++) bit[i] = 0;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n;
	cin>>n;
	vector<ll> a(n);
	REP(i,n) cin>>a[i];
	vector<ll> l(n);
	vector<ll> r(n);
	REP(i,n) cin>>l[i]>>r[i];
	ll ans=0;
	vector<ll> b(n);
	priority_queue<P,vector<P>,greater<P>> q;
	REP(i,n) {
		while(!q.empty()&&(q.top()).first<a[i]) {
			add((q.top()).second,-1);
			q.pop();
		}
		auto ite=lower_bound(ALL(a),a[i]-l[i]);
		ans+=sum(i);
		if(ite!=a.begin()) ans-=sum((ite-a.begin())-1);
		add(i,1);
		q.push(P(a[i]+r[i],i));
	}
	cout<<ans<<endl;
}
0