Submission #372246

# Submission time Handle Problem Language Result Execution time Memory
372246 2021-02-27T10:14:44 Z gustason Travels (LMIO17_keliones) C++11
45 / 100
1000 ms 34924 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) % mod;
        tree[idx].sum += mod;
        tree[idx].sum %= 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) % mod) + mod) % 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;
            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) + mod) % 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 % mod) + mod) % mod;

        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) + mod) % 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;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4972 KB Output is correct
2 Correct 4 ms 4972 KB Output is correct
3 Correct 4 ms 5100 KB Output is correct
4 Correct 4 ms 5100 KB Output is correct
5 Correct 4 ms 4972 KB Output is correct
6 Correct 5 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 5100 KB Output is correct
10 Correct 4 ms 4972 KB Output is correct
11 Correct 5 ms 4972 KB Output is correct
12 Correct 4 ms 4972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4972 KB Output is correct
2 Correct 4 ms 4972 KB Output is correct
3 Correct 4 ms 5100 KB Output is correct
4 Correct 4 ms 5100 KB Output is correct
5 Correct 4 ms 4972 KB Output is correct
6 Correct 5 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 5100 KB Output is correct
10 Correct 4 ms 4972 KB Output is correct
11 Correct 5 ms 4972 KB Output is correct
12 Correct 4 ms 4972 KB Output is correct
13 Correct 144 ms 6508 KB Output is correct
14 Correct 182 ms 6656 KB Output is correct
15 Correct 127 ms 6380 KB Output is correct
16 Correct 47 ms 5484 KB Output is correct
17 Correct 130 ms 6252 KB Output is correct
18 Correct 82 ms 5868 KB Output is correct
19 Correct 9 ms 5100 KB Output is correct
20 Correct 9 ms 5100 KB Output is correct
21 Correct 7 ms 5100 KB Output is correct
22 Correct 7 ms 5100 KB Output is correct
23 Correct 9 ms 5100 KB Output is correct
24 Correct 6 ms 5100 KB Output is correct
25 Correct 6 ms 5100 KB Output is correct
26 Correct 6 ms 5100 KB Output is correct
27 Correct 20 ms 5356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 144 ms 6508 KB Output is correct
2 Correct 182 ms 6656 KB Output is correct
3 Correct 127 ms 6380 KB Output is correct
4 Correct 47 ms 5484 KB Output is correct
5 Correct 130 ms 6252 KB Output is correct
6 Correct 82 ms 5868 KB Output is correct
7 Correct 9 ms 5100 KB Output is correct
8 Correct 9 ms 5100 KB Output is correct
9 Correct 7 ms 5100 KB Output is correct
10 Correct 7 ms 5100 KB Output is correct
11 Correct 9 ms 5100 KB Output is correct
12 Correct 6 ms 5100 KB Output is correct
13 Correct 6 ms 5100 KB Output is correct
14 Correct 6 ms 5100 KB Output is correct
15 Correct 20 ms 5356 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 5100 KB Output is correct
19 Correct 4 ms 5100 KB Output is correct
20 Correct 4 ms 4972 KB Output is correct
21 Correct 5 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 5100 KB Output is correct
25 Correct 4 ms 4972 KB Output is correct
26 Correct 5 ms 4972 KB Output is correct
27 Correct 4 ms 4972 KB Output is correct
28 Correct 240 ms 7404 KB Output is correct
29 Correct 70 ms 6268 KB Output is correct
30 Correct 140 ms 6636 KB Output is correct
31 Correct 63 ms 6124 KB Output is correct
32 Correct 27 ms 5740 KB Output is correct
33 Correct 37 ms 6140 KB Output is correct
34 Correct 169 ms 6764 KB Output is correct
35 Correct 269 ms 7532 KB Output is correct
36 Correct 276 ms 7532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 144 ms 6508 KB Output is correct
2 Correct 182 ms 6656 KB Output is correct
3 Correct 127 ms 6380 KB Output is correct
4 Correct 47 ms 5484 KB Output is correct
5 Correct 130 ms 6252 KB Output is correct
6 Correct 82 ms 5868 KB Output is correct
7 Correct 9 ms 5100 KB Output is correct
8 Correct 9 ms 5100 KB Output is correct
9 Correct 7 ms 5100 KB Output is correct
10 Correct 7 ms 5100 KB Output is correct
11 Correct 9 ms 5100 KB Output is correct
12 Correct 6 ms 5100 KB Output is correct
13 Correct 6 ms 5100 KB Output is correct
14 Correct 6 ms 5100 KB Output is correct
15 Correct 20 ms 5356 KB Output is correct
16 Correct 240 ms 7404 KB Output is correct
17 Correct 70 ms 6268 KB Output is correct
18 Correct 140 ms 6636 KB Output is correct
19 Correct 63 ms 6124 KB Output is correct
20 Correct 27 ms 5740 KB Output is correct
21 Correct 37 ms 6140 KB Output is correct
22 Correct 169 ms 6764 KB Output is correct
23 Correct 269 ms 7532 KB Output is correct
24 Correct 276 ms 7532 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 5100 KB Output is correct
28 Correct 4 ms 5100 KB Output is correct
29 Correct 4 ms 4972 KB Output is correct
30 Correct 5 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 5100 KB Output is correct
34 Correct 4 ms 4972 KB Output is correct
35 Correct 5 ms 4972 KB Output is correct
36 Correct 4 ms 4972 KB Output is correct
37 Execution timed out 1094 ms 34924 KB Time limit exceeded
38 Halted 0 ms 0 KB -