結果

問題 No.728 ギブ and テイク
ユーザー 👑 kmjpkmjp
提出日時 2018-08-24 23:31:13
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 214 ms / 3,000 ms
コード長 1,379 bytes
コンパイル時間 2,949 ms
コンパイル使用メモリ 153,696 KB
実行使用メモリ 16,300 KB
最終ジャッジ日時 2023-09-05 14:41:41
合計ジャッジ時間 6,545 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,556 KB
testcase_01 AC 2 ms
7,456 KB
testcase_02 AC 3 ms
7,736 KB
testcase_03 AC 3 ms
7,628 KB
testcase_04 AC 2 ms
7,620 KB
testcase_05 AC 2 ms
7,492 KB
testcase_06 AC 3 ms
7,688 KB
testcase_07 AC 3 ms
7,560 KB
testcase_08 AC 2 ms
7,468 KB
testcase_09 AC 2 ms
7,748 KB
testcase_10 AC 3 ms
7,516 KB
testcase_11 AC 2 ms
7,520 KB
testcase_12 AC 3 ms
7,572 KB
testcase_13 AC 13 ms
7,720 KB
testcase_14 AC 20 ms
8,056 KB
testcase_15 AC 10 ms
7,728 KB
testcase_16 AC 18 ms
7,912 KB
testcase_17 AC 17 ms
7,812 KB
testcase_18 AC 149 ms
12,392 KB
testcase_19 AC 156 ms
12,688 KB
testcase_20 AC 185 ms
15,568 KB
testcase_21 AC 166 ms
12,636 KB
testcase_22 AC 66 ms
9,456 KB
testcase_23 AC 43 ms
8,636 KB
testcase_24 AC 123 ms
11,604 KB
testcase_25 AC 124 ms
12,372 KB
testcase_26 AC 64 ms
9,456 KB
testcase_27 AC 214 ms
16,300 KB
testcase_28 AC 159 ms
15,880 KB
testcase_29 AC 2 ms
7,504 KB
testcase_30 AC 2 ms
7,564 KB
testcase_31 AC 2 ms
7,488 KB
testcase_32 AC 3 ms
7,684 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

template<class V, int ME> class BIT {
public:
	V bit[1<<ME];
	V operator()(int e) {if(e<0) return 0;V s=0;e++;while(e) s+=bit[e-1],e-=e&-e; return s;}
	void add(int e,V v) { e++; while(e<=1<<ME) bit[e-1]+=v,e+=e&-e;}
};
BIT<int,20> bt;

int N;
int A[301010];
int L[303030];
int R[303030];
vector<pair<int,int>> E;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) cin>>A[i];
	FOR(i,N) {
		cin>>L[i]>>R[i];
		E.push_back({A[i],i});
		E.push_back({A[i]+R[i],N+i});
	}
	ll ret=0;
	sort(ALL(E));
	FORR(e,E) {
		x=e.second%N;
		if(e.second<N) {
			x=e.second;
			y=lower_bound(A,A+N,A[x]-L[x])-A;
			ret+=bt(x)-bt(y-1);
			bt.add(x,1);
		}
		else {
			bt.add(x,-1);
		}
	}
	cout<<ret<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0