結果

問題 No.728 ギブ and テイク
ユーザー chocoruskchocorusk
提出日時 2018-10-08 16:04:48
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,538 ms / 3,000 ms
コード長 1,170 bytes
コンパイル時間 969 ms
コンパイル使用メモリ 89,000 KB
実行使用メモリ 6,784 KB
最終ジャッジ日時 2024-04-20 18:37:15
合計ジャッジ時間 13,036 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,632 KB
testcase_01 AC 3 ms
5,632 KB
testcase_02 AC 3 ms
5,760 KB
testcase_03 AC 3 ms
5,632 KB
testcase_04 AC 3 ms
5,888 KB
testcase_05 AC 3 ms
5,760 KB
testcase_06 AC 3 ms
5,504 KB
testcase_07 AC 3 ms
5,632 KB
testcase_08 AC 3 ms
5,760 KB
testcase_09 AC 3 ms
5,760 KB
testcase_10 AC 3 ms
5,760 KB
testcase_11 AC 3 ms
5,760 KB
testcase_12 AC 3 ms
5,632 KB
testcase_13 AC 58 ms
5,760 KB
testcase_14 AC 111 ms
5,760 KB
testcase_15 AC 43 ms
5,760 KB
testcase_16 AC 92 ms
6,016 KB
testcase_17 AC 83 ms
5,760 KB
testcase_18 AC 962 ms
6,400 KB
testcase_19 AC 1,028 ms
6,656 KB
testcase_20 AC 1,265 ms
6,656 KB
testcase_21 AC 1,111 ms
6,528 KB
testcase_22 AC 389 ms
6,012 KB
testcase_23 AC 243 ms
6,016 KB
testcase_24 AC 777 ms
6,144 KB
testcase_25 AC 766 ms
6,400 KB
testcase_26 AC 376 ms
6,144 KB
testcase_27 AC 1,474 ms
6,784 KB
testcase_28 AC 1,538 ms
6,656 KB
testcase_29 AC 3 ms
5,760 KB
testcase_30 AC 3 ms
5,888 KB
testcase_31 AC 4 ms
5,632 KB
testcase_32 AC 3 ms
5,760 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <unordered_map>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const int sq=2000;
int main()
{
	int n;
  cin>>n;
  int a[300001];
  for(int i=0; i<n; i++) cin>>a[i];
  int x[300001];
  vector<int> v[151];
  ll ans=0;
  for(int i=0; i<n; i++){
    int l, r;
    cin>>l>>r;
    x[i]=a[i]+r;
    if((i+1)%sq==0){
      for(int j=i/sq*sq; j<=i; j++){
        v[i/sq].push_back(x[j]);
      }
      sort(v[i/sq].begin(), v[i/sq].end());
    }
    int i1=lower_bound(a, a+i, a[i]-l)-a;
    if(i1==i) continue;
    if(i1/sq==(i-1)/sq){
      for(int j=i1; j<i; j++){
        if(x[j]>=a[i]) ans++;
      }
      continue;
    }
    for(int j=i1/sq+1; j<(i-1)/sq; j++){
      ans+=((ll)(v[j].end()-lower_bound(v[j].begin(), v[j].end(), a[i])));
    }
    for(int j=i1; j<(i1/sq+1)*sq; j++){
      if(x[j]>=a[i]) ans++;
    }
    for(int j=(i-1)/sq*sq; j<i; j++){
      if(x[j]>=a[i]) ans++;
    }
  }
	cout<<ans<<endl;
	return 0;
}
0