답안 #372250

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
372250 2021-02-27T10:23:16 Z gustason Travels (LMIO17_keliones) C++11
45 / 100
1000 ms 34284 KB
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
#define int ll
struct Node {
    ll sum;
    ll delta;
    Node() {
        sum = 0;
        delta = 0;
    }
    void Reset() {
        delta = 0;
    }
};
struct SegTree {
    int n;
    vector<Node> tree;
    SegTree(vector<int>& a) {
        n = a.size();
        tree.assign(4*n, Node());

    }
    void build_r(vector<int>& a, int l, int r, int idx) {
        if (l == r) {
            if (l < n)
                tree[idx].sum = a[l];
            else
                tree[idx].sum = 0;
            return;
        }

        int mid = (l + r) / 2;
        build_r(a, l, mid, 2*idx+1);
        build_r(a, mid+1, r, 2*idx+2);
//        tree[idx].sum = (tree[2*idx+1].sum + tree[2*idx+2].sum) % mod;
    }
    void applyAggr(int idx, int l, int r) {
        tree[idx].sum = (tree[idx].sum + (r-l+1) * tree[idx].delta) % mod;

        if (l != r) {
            compose(idx, 2*idx+1);
            compose(idx, 2*idx+2);
        }

        tree[idx].Reset();
    }
    void compose(int par, int child) {
        tree[child].delta = (tree[child].delta + tree[par].delta);
        if (tree[child].delta < 0) {
            tree[child].delta += mod;
        } else tree[child].delta %= mod;
    }
    void updateSum(int L, int R, int val) {
        updateSum_r(0, 0, n-1, L, R, val);
    }
    void updateSum_r(int idx, int l, int r, int& L, int& R, int& val) {
        if (r < L || R < l || l >= n) {
            return;
        }
        if (L <= l && R >= r) {
            tree[idx].delta += val;
            tree[idx].delta %= mod;
            return;
        }
        applyAggr(idx, l, r);

        int mid = (l + r) / 2;
        updateSum_r(2*idx+1, l, mid, L, R, val);
        updateSum_r(2*idx+2, mid+1, r, L, R, val);
        applyAggr(2*idx+1, l, mid);
        applyAggr(2*idx+2, mid+1, r);

        tree[idx].sum = (tree[2*idx+1].sum + tree[2*idx+2].sum) % mod;
    }
    ll getSum(int L, int R) {
        return getSum_r(0, 0, n-1, L, R);
    }
    ll getSum_r(int idx, int l, int r, int& L, int& R) {
        if (r < L || R < l || l >= n)
            return 0;
        applyAggr(idx, l, r);
        if (L <= l && R >= r)
            return tree[idx].sum;

        int mid = (l + r) / 2;
        return (getSum_r(2*idx+1, l, mid, L, R) + getSum_r(2*idx+2, mid+1, r, L, R)) % mod;
    }
};
const int maxN = 2e5 + 5;
vector<int> adj[maxN];
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("test.in", "r", stdin);
    int n, m;
    cin >> n >> m;
    vector<int> add(n+1);
    for(int i = 0; i < n; i++) {
        cin >> add[i];
    }
    for(int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        adj[a].push_back(b);
    }

    vector<int> a(n+1, 0);
    SegTree sum(a), cnt(a);
    for(int i = 0; i < n; i++) {
        sum.updateSum(i, i, cnt.getSum(i, i) * add[i]);
        cnt.updateSum(i+1, n-1, cnt.getSum(i, i) + 1);
        sum.updateSum(i+1, n-1, sum.getSum(i, i) + add[i]);
        for(int j : adj[i]) {
            cnt.updateSum(j, j, -cnt.getSum(i, i) - 1);
            sum.updateSum(j, j, -sum.getSum(i, i) - add[i]);
        }
    }
    cout << sum.getSum(0, n-1) << "\n";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4972 KB Output is correct
2 Correct 4 ms 4972 KB Output is correct
3 Correct 4 ms 4972 KB Output is correct
4 Correct 5 ms 4972 KB Output is correct
5 Correct 4 ms 4972 KB Output is correct
6 Correct 4 ms 4972 KB Output is correct
7 Correct 4 ms 4972 KB Output is correct
8 Correct 4 ms 4972 KB Output is correct
9 Correct 4 ms 4972 KB Output is correct
10 Correct 4 ms 4972 KB Output is correct
11 Correct 4 ms 4972 KB Output is correct
12 Correct 4 ms 4972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4972 KB Output is correct
2 Correct 4 ms 4972 KB Output is correct
3 Correct 4 ms 4972 KB Output is correct
4 Correct 5 ms 4972 KB Output is correct
5 Correct 4 ms 4972 KB Output is correct
6 Correct 4 ms 4972 KB Output is correct
7 Correct 4 ms 4972 KB Output is correct
8 Correct 4 ms 4972 KB Output is correct
9 Correct 4 ms 4972 KB Output is correct
10 Correct 4 ms 4972 KB Output is correct
11 Correct 4 ms 4972 KB Output is correct
12 Correct 4 ms 4972 KB Output is correct
13 Correct 106 ms 6400 KB Output is correct
14 Correct 140 ms 6380 KB Output is correct
15 Correct 108 ms 6124 KB Output is correct
16 Correct 32 ms 5356 KB Output is correct
17 Correct 94 ms 5996 KB Output is correct
18 Correct 59 ms 5612 KB Output is correct
19 Correct 7 ms 5100 KB Output is correct
20 Correct 5 ms 5100 KB Output is correct
21 Correct 5 ms 5100 KB Output is correct
22 Correct 5 ms 5100 KB Output is correct
23 Correct 9 ms 5100 KB Output is correct
24 Correct 5 ms 5100 KB Output is correct
25 Correct 5 ms 5100 KB Output is correct
26 Correct 5 ms 5100 KB Output is correct
27 Correct 16 ms 5228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 106 ms 6400 KB Output is correct
2 Correct 140 ms 6380 KB Output is correct
3 Correct 108 ms 6124 KB Output is correct
4 Correct 32 ms 5356 KB Output is correct
5 Correct 94 ms 5996 KB Output is correct
6 Correct 59 ms 5612 KB Output is correct
7 Correct 7 ms 5100 KB Output is correct
8 Correct 5 ms 5100 KB Output is correct
9 Correct 5 ms 5100 KB Output is correct
10 Correct 5 ms 5100 KB Output is correct
11 Correct 9 ms 5100 KB Output is correct
12 Correct 5 ms 5100 KB Output is correct
13 Correct 5 ms 5100 KB Output is correct
14 Correct 5 ms 5100 KB Output is correct
15 Correct 16 ms 5228 KB Output is correct
16 Correct 4 ms 4972 KB Output is correct
17 Correct 4 ms 4972 KB Output is correct
18 Correct 4 ms 4972 KB Output is correct
19 Correct 5 ms 4972 KB Output is correct
20 Correct 4 ms 4972 KB Output is correct
21 Correct 4 ms 4972 KB Output is correct
22 Correct 4 ms 4972 KB Output is correct
23 Correct 4 ms 4972 KB Output is correct
24 Correct 4 ms 4972 KB Output is correct
25 Correct 4 ms 4972 KB Output is correct
26 Correct 4 ms 4972 KB Output is correct
27 Correct 4 ms 4972 KB Output is correct
28 Correct 181 ms 7148 KB Output is correct
29 Correct 50 ms 5996 KB Output is correct
30 Correct 116 ms 6380 KB Output is correct
31 Correct 57 ms 5996 KB Output is correct
32 Correct 20 ms 5740 KB Output is correct
33 Correct 26 ms 5740 KB Output is correct
34 Correct 134 ms 6508 KB Output is correct
35 Correct 178 ms 7276 KB Output is correct
36 Correct 190 ms 7276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 106 ms 6400 KB Output is correct
2 Correct 140 ms 6380 KB Output is correct
3 Correct 108 ms 6124 KB Output is correct
4 Correct 32 ms 5356 KB Output is correct
5 Correct 94 ms 5996 KB Output is correct
6 Correct 59 ms 5612 KB Output is correct
7 Correct 7 ms 5100 KB Output is correct
8 Correct 5 ms 5100 KB Output is correct
9 Correct 5 ms 5100 KB Output is correct
10 Correct 5 ms 5100 KB Output is correct
11 Correct 9 ms 5100 KB Output is correct
12 Correct 5 ms 5100 KB Output is correct
13 Correct 5 ms 5100 KB Output is correct
14 Correct 5 ms 5100 KB Output is correct
15 Correct 16 ms 5228 KB Output is correct
16 Correct 181 ms 7148 KB Output is correct
17 Correct 50 ms 5996 KB Output is correct
18 Correct 116 ms 6380 KB Output is correct
19 Correct 57 ms 5996 KB Output is correct
20 Correct 20 ms 5740 KB Output is correct
21 Correct 26 ms 5740 KB Output is correct
22 Correct 134 ms 6508 KB Output is correct
23 Correct 178 ms 7276 KB Output is correct
24 Correct 190 ms 7276 KB Output is correct
25 Correct 4 ms 4972 KB Output is correct
26 Correct 4 ms 4972 KB Output is correct
27 Correct 4 ms 4972 KB Output is correct
28 Correct 5 ms 4972 KB Output is correct
29 Correct 4 ms 4972 KB Output is correct
30 Correct 4 ms 4972 KB Output is correct
31 Correct 4 ms 4972 KB Output is correct
32 Correct 4 ms 4972 KB Output is correct
33 Correct 4 ms 4972 KB Output is correct
34 Correct 4 ms 4972 KB Output is correct
35 Correct 4 ms 4972 KB Output is correct
36 Correct 4 ms 4972 KB Output is correct
37 Execution timed out 1090 ms 34284 KB Time limit exceeded
38 Halted 0 ms 0 KB -