結果

問題 No.1347 HS Railway
ユーザー KudeKude
提出日時 2021-01-21 21:13:08
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 49 ms / 2,000 ms
コード長 2,059 bytes
コンパイル時間 2,789 ms
コンパイル使用メモリ 210,228 KB
実行使用メモリ 6,792 KB
最終ジャッジ日時 2023-08-26 09:08:52
合計ジャッジ時間 6,362 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 17 ms
4,376 KB
testcase_13 AC 14 ms
4,376 KB
testcase_14 AC 8 ms
4,380 KB
testcase_15 AC 11 ms
4,376 KB
testcase_16 AC 21 ms
4,588 KB
testcase_17 AC 5 ms
4,380 KB
testcase_18 AC 31 ms
5,256 KB
testcase_19 AC 29 ms
4,788 KB
testcase_20 AC 27 ms
5,204 KB
testcase_21 AC 13 ms
4,376 KB
testcase_22 AC 34 ms
5,552 KB
testcase_23 AC 30 ms
5,148 KB
testcase_24 AC 12 ms
4,384 KB
testcase_25 AC 21 ms
4,576 KB
testcase_26 AC 32 ms
5,252 KB
testcase_27 AC 18 ms
4,520 KB
testcase_28 AC 35 ms
5,860 KB
testcase_29 AC 34 ms
5,520 KB
testcase_30 AC 29 ms
5,236 KB
testcase_31 AC 26 ms
5,024 KB
testcase_32 AC 38 ms
5,752 KB
testcase_33 AC 41 ms
5,740 KB
testcase_34 AC 40 ms
5,596 KB
testcase_35 AC 39 ms
5,772 KB
testcase_36 AC 39 ms
5,612 KB
testcase_37 AC 45 ms
6,112 KB
testcase_38 AC 44 ms
5,852 KB
testcase_39 AC 45 ms
6,040 KB
testcase_40 AC 37 ms
5,384 KB
testcase_41 AC 36 ms
5,480 KB
testcase_42 AC 45 ms
6,300 KB
testcase_43 AC 36 ms
5,804 KB
testcase_44 AC 37 ms
5,956 KB
testcase_45 AC 35 ms
5,456 KB
testcase_46 AC 40 ms
6,244 KB
testcase_47 AC 42 ms
5,920 KB
testcase_48 AC 49 ms
6,792 KB
testcase_49 AC 41 ms
6,012 KB
testcase_50 AC 46 ms
6,644 KB
testcase_51 AC 41 ms
6,096 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
template<class T> void chmax(T& a, const T& b) {a = max(a, b);}
template<class T> void chmin(T& a, const T& b) {a = min(a, b);}
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    VL l(5), r(5);
    VVL a(5);
    rep(i, 5) {
        cin >> l[i] >> r[i];
        l[i]--, r[i]--;
        int cnt = r[i] - l[i];
        a[i].resize(cnt);
        rep(j, cnt) cin >> a[i][j];
    }
    int m;
    cin >> m;
    VVL train(5);
    rep(_, m) {
        int b, s;
        cin >> b >> s;
        b--;
        train[b].push_back(s);
    }
    rep(i, 5) sort(all(train[i]));
    ll ans = 0;
    rep(j, 5) rep(i, j) {
        int sstop = max(l[i], l[j]), tstop = min(r[i], r[j]);
        if (sstop > tstop) continue;
        VL si = train[i], ti = train[i], sj = train[j], tj = train[j];
        {
            ll acc = 0;
            for(int p = l[i]; p < sstop; ++p) {
                acc += a[i][p - l[i]];
            }
            for(ll& x: si) x += acc;
            for(int p = sstop; p < tstop; ++p) {
                acc += a[i][p - l[i]];
            }
            for(ll& x: ti) x += acc;
        }
        {
            ll acc = 0;
            for(int p = l[j]; p < sstop; ++p) {
                acc += a[j][p - l[j]];
            }
            for(ll& x: sj) x += acc;
            for(int p = sstop; p < tstop; ++p) {
                acc += a[j][p - l[j]];
            }
            for(ll& x: tj) x += acc;
        }
        int x = 0, y = 0;
        rep(k, si.size()) {
            while(x < sj.size() && sj[x] <= si[k]) x++;
            while(y < tj.size() && tj[y] < ti[k]) y++;
            ans += max(0, x - y);
        }
    }
    cout << ans << endl;
}
0