結果

問題 No.1347 HS Railway
ユーザー PCTprobabilityPCTprobability
提出日時 2021-01-15 16:43:26
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 3,720 bytes
コンパイル時間 2,880 ms
コンパイル使用メモリ 164,620 KB
実行使用メモリ 10,004 KB
最終ジャッジ日時 2024-05-05 01:17:17
合計ジャッジ時間 13,938 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 RE -
testcase_43 RE -
testcase_44 RE -
testcase_45 RE -
testcase_46 RE -
testcase_47 RE -
testcase_48 RE -
testcase_49 RE -
testcase_50 RE -
testcase_51 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define all(s) (s).begin(),(s).end()
#define vcin(n) for(ll i=0;i<ll(n.size());i++) cin>>n[i]
#define rever(vec) reverse(vec.begin(), vec.end())
#define sor(vec) sort(vec.begin(), vec.end())
#define fi first
#define se second
const ll mod = 998244353;
//const ll mod = 1000000007;
const ll inf = 2000000000000000000ll;
static const long double pi = 3.141592653589793;
template<class T,class U> void chmax(T& t,const U& u){if(t<u) t=u;}
template<class T,class U> void chmin(T& t,const U& u){if(t>u) t=u;}
ll modPow(ll a, ll n, ll mod) { ll ret = 1; ll p = a % mod; while (n) { if (n & 1) ret = ret * p % mod; p = p * p % mod; n >>= 1; } return ret; }
int main() {
  /* mod は 1e9+7 */
  ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
  cout<< fixed << setprecision(10);
  ll n;
  cin>>n;
  assert(2<=n&&n<=100000);
  ll a[5][n-1];
  ll f[5][n];
  for(int i=0;i<5;i++){
    for(int j=0;j<n-1;j++){
      cin>>a[i][j];
      assert(1<=a[i][j]&&a[i][j]<=100000);
      if(i!=0){
        assert(a[i-1][j]<a[i][j]);
      }
      f[i][j]=0;
    }
    f[i][n-1]=0;
  }
  for(int i=0;i<5;i++){
    for(int j=1;j<n;j++){
      f[i][j]=f[i][j-1]+a[i][j-1];
    }
  }
  vector<ll> l(5),r(5);
  for(int i=0;i<5;i++){
    cin>>l[i]>>r[i];
    assert(1<=l[i]&&l[i]<=r[i]&&r[i]<=n);
    l[i]--;
    r[i]--;
  }
  ll m;
  cin>>m;
  vector<vector<ll>> s(5);
  for(int i=0;i<m;i++){
    ll b,si;
    cin>>b>>si;
    assert(1<=b&&b<=5&&1<=si&&si<=100000);
    b--;
    s[b].push_back(si);
  }
  for(int i=0;i<5;i++){
    sor(s[i]);
  }
  ll ans=0;
  for(int i=4;i>=0;i--){
    for(int j=i-1;j>=0;j--){
      if(l[i]>r[j]||l[j]>r[i]){
        continue;
      }
      if(l[i]<=l[j]&&r[j]<=r[i]){
        for(int k=0;k<int(s[j].size());k++){
          ll b=s[j][k];
          ll c=f[j][r[j]]-f[j][l[j]];
          ll d=f[i][r[j]]-f[i][l[j]];
     //     cout<<0<<" "<<i<<" "<<j<<" "<<b<<" "<<d<<" "<<c<<" "<<(upper_bound(all(s[i]),b)-s[i].begin())-(lower_bound(all(s[i]),b+c-d)-s[i].begin())<<endl;
          ans+=(upper_bound(all(s[i]),b-(f[i][l[j]]-f[i][l[i]]))-s[i].begin())-(lower_bound(all(s[i]),b+c-d-(f[i][l[j]]-f[i][l[i]]))-s[i].begin());
        }
      }
      else if(l[j]<=l[i]&&r[i]<=r[j]){
        for(int k=0;k<int(s[j].size());k++){
          ll b=s[j][k]+f[j][l[i]]-f[j][l[j]];
          ll c=f[j][r[i]]-f[j][l[i]];
          ll d=f[i][r[i]]-f[i][l[i]];
      //    cout<<1<<" "<<i<<" "<<j<<" "<<b<<" "<<d<<" "<<c<<" "<<(upper_bound(all(s[i]),b)-s[i].begin())-(lower_bound(all(s[i]),b+c-d)-s[i].begin())<<endl;
          ans+=(upper_bound(all(s[i]),b)-s[i].begin())-(lower_bound(all(s[i]),b+c-d)-s[i].begin());
        }
      }
      else if(l[i]<=l[j]){
        for(int k=0;k<int(s[j].size());k++){
          ll b=s[j][k];
          ll c=f[j][r[i]]-f[j][l[j]];
          ll d=f[i][r[i]]-f[i][l[j]];
      //    cout<<2<<" "<<i<<" "<<j<<" "<<b<<" "<<d<<" "<<c<<" "<<(upper_bound(all(s[i]),b)-s[i].begin())-(lower_bound(all(s[i]),b+c-d)-s[i].begin())<<endl;
          ans+=(upper_bound(all(s[i]),b-(f[i][l[j]]-f[i][l[i]]))-s[i].begin())-(lower_bound(all(s[i]),b+c-d-(f[i][l[j]]-f[i][l[i]]))-s[i].begin());
        }
      }
      else if(l[j]<=l[i]){
        for(int k=0;k<int(s[j].size());k++){
          ll b=s[j][k]+f[j][l[i]]-f[j][l[j]];
          ll c=f[j][r[j]]-f[j][l[i]];
          ll d=f[i][r[j]]-f[i][l[i]];
       //   cout<<3<<" "<<i<<" "<<j<<" "<<b<<" "<<d<<" "<<c<<" "<<(upper_bound(all(s[i]),b)-s[i].begin())-(lower_bound(all(s[i]),b+c-d)-s[i].begin())<<endl;
          ans+=(upper_bound(all(s[i]),b)-s[i].begin())-(lower_bound(all(s[i]),b+c-d)-s[i].begin());
        }
      }
    }
  }
  cout<<ans<<endl;
}
0