結果
| 問題 |
No.728 ギブ and テイク
|
| コンテスト | |
| ユーザー |
gazelle
|
| 提出日時 | 2018-08-24 21:57:52 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 176 ms / 3,000 ms |
| コード長 | 1,235 bytes |
| コンパイル時間 | 1,845 ms |
| コンパイル使用メモリ | 202,008 KB |
| 最終ジャッジ日時 | 2025-01-06 12:33:04 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 30 |
ソースコード
#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;
}
gazelle