Submission #140673

# Submission time Handle Problem Language Result Execution time Memory
140673 2019-08-04T11:57:39 Z khrbuddy03 None (KOI18_XCorr) C++14
100 / 100
393 ms 37308 KB
#include <bits/stdc++.h>

using namespace std;

using lint = long long;

const int inf = (int)1e9 + 9;
const int siz = (int)3e5 + 9;

struct seg {
    lint tree[siz * 4];
    lint query(int left, int right, int node, int low, int high) {
        if (right < low || high < left) return 0LL;
        if (left <= low && high <= right) return tree[node] * 1LL;
        int mid = (low + high) / 2;
        return query(left, right, node * 2, low, mid) * 1LL + query(left, right, node * 2 + 1, mid + 1, high);
    }
    void update(int idx, int val, int node, int low, int high) {
        if (idx < low || high < idx) return;
        if (low == high) tree[node] = val * 1LL;
        else {
            int mid = (low + high) / 2;
            update(idx, val, node * 2, low, mid);
            update(idx, val, node * 2 + 1, mid + 1, high);
            tree[node] = tree[node * 2] * 1LL + tree[node * 2 + 1] * 1LL;
        }
    }
} seg;

map<int, int> X;

vector<int> Y;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int N; cin >> N;
    vector<pair<int, int>> QX, QY;
    for (int i = 0; i < N; i++) {
        int IDX, XI; cin >> IDX >> XI;
        X[IDX] = XI;
    }
    int M; cin >> M;
    for (int i = 0; i < M; i++) {
        int IDX, YI; cin >> IDX >> YI;
        QY.emplace_back(IDX, YI);
        Y.push_back(IDX);
    }
    sort(Y.begin(), Y.end());
    for (auto Q : QY) seg.update((int)(lower_bound(Y.begin(), Y.end(), Q.first) - Y.begin()), Q.second, 1, 0, M - 1);
    int A, B; cin >> A >> B;
    lint ANS = 0LL;
    for (auto x : X) {
        ANS += x.second * 1LL * seg.query((int)(lower_bound(Y.begin(), Y.end(), x.first + A) - Y.begin()), (int)(upper_bound(Y.begin(), Y.end(), x.first + B) - Y.begin()) - 1, 1, 0, M - 1);
    }
    cout << ANS << '\n';
}

# Verdict Execution time Memory Grader output
1 Correct 5 ms 632 KB Output is correct
2 Correct 5 ms 632 KB Output is correct
3 Correct 5 ms 632 KB Output is correct
4 Correct 4 ms 508 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 4 ms 632 KB Output is correct
7 Correct 4 ms 632 KB Output is correct
8 Correct 5 ms 632 KB Output is correct
9 Correct 3 ms 504 KB Output is correct
10 Correct 5 ms 632 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 4 ms 704 KB Output is correct
13 Correct 5 ms 708 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 3 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 632 KB Output is correct
2 Correct 5 ms 632 KB Output is correct
3 Correct 5 ms 632 KB Output is correct
4 Correct 4 ms 508 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 4 ms 632 KB Output is correct
7 Correct 4 ms 632 KB Output is correct
8 Correct 5 ms 632 KB Output is correct
9 Correct 3 ms 504 KB Output is correct
10 Correct 5 ms 632 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 4 ms 704 KB Output is correct
13 Correct 5 ms 708 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 3 ms 504 KB Output is correct
16 Correct 206 ms 18944 KB Output is correct
17 Correct 5 ms 632 KB Output is correct
18 Correct 351 ms 34792 KB Output is correct
19 Correct 4 ms 604 KB Output is correct
20 Correct 5 ms 632 KB Output is correct
21 Correct 4 ms 632 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 4 ms 632 KB Output is correct
24 Correct 361 ms 33140 KB Output is correct
25 Correct 325 ms 35096 KB Output is correct
26 Correct 327 ms 34884 KB Output is correct
27 Correct 5 ms 632 KB Output is correct
28 Correct 5 ms 632 KB Output is correct
29 Correct 3 ms 504 KB Output is correct
30 Correct 324 ms 34880 KB Output is correct
31 Correct 5 ms 632 KB Output is correct
32 Correct 372 ms 34200 KB Output is correct
33 Correct 320 ms 35000 KB Output is correct
34 Correct 141 ms 17116 KB Output is correct
35 Correct 2 ms 376 KB Output is correct
36 Correct 332 ms 34860 KB Output is correct
37 Correct 124 ms 11640 KB Output is correct
38 Correct 4 ms 632 KB Output is correct
39 Correct 312 ms 33444 KB Output is correct
40 Correct 5 ms 636 KB Output is correct
41 Correct 2 ms 376 KB Output is correct
42 Correct 3 ms 504 KB Output is correct
43 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 632 KB Output is correct
2 Correct 5 ms 632 KB Output is correct
3 Correct 5 ms 632 KB Output is correct
4 Correct 4 ms 508 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 4 ms 632 KB Output is correct
7 Correct 4 ms 632 KB Output is correct
8 Correct 5 ms 632 KB Output is correct
9 Correct 3 ms 504 KB Output is correct
10 Correct 5 ms 632 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 4 ms 704 KB Output is correct
13 Correct 5 ms 708 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 3 ms 504 KB Output is correct
16 Correct 206 ms 18944 KB Output is correct
17 Correct 5 ms 632 KB Output is correct
18 Correct 351 ms 34792 KB Output is correct
19 Correct 4 ms 604 KB Output is correct
20 Correct 5 ms 632 KB Output is correct
21 Correct 4 ms 632 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 4 ms 632 KB Output is correct
24 Correct 361 ms 33140 KB Output is correct
25 Correct 325 ms 35096 KB Output is correct
26 Correct 327 ms 34884 KB Output is correct
27 Correct 5 ms 632 KB Output is correct
28 Correct 5 ms 632 KB Output is correct
29 Correct 3 ms 504 KB Output is correct
30 Correct 324 ms 34880 KB Output is correct
31 Correct 5 ms 632 KB Output is correct
32 Correct 372 ms 34200 KB Output is correct
33 Correct 320 ms 35000 KB Output is correct
34 Correct 141 ms 17116 KB Output is correct
35 Correct 2 ms 376 KB Output is correct
36 Correct 332 ms 34860 KB Output is correct
37 Correct 124 ms 11640 KB Output is correct
38 Correct 4 ms 632 KB Output is correct
39 Correct 312 ms 33444 KB Output is correct
40 Correct 5 ms 636 KB Output is correct
41 Correct 2 ms 376 KB Output is correct
42 Correct 3 ms 504 KB Output is correct
43 Correct 2 ms 376 KB Output is correct
44 Correct 199 ms 18876 KB Output is correct
45 Correct 5 ms 632 KB Output is correct
46 Correct 348 ms 34884 KB Output is correct
47 Correct 5 ms 632 KB Output is correct
48 Correct 274 ms 23144 KB Output is correct
49 Correct 109 ms 10852 KB Output is correct
50 Correct 5 ms 632 KB Output is correct
51 Correct 4 ms 632 KB Output is correct
52 Correct 2 ms 376 KB Output is correct
53 Correct 4 ms 632 KB Output is correct
54 Correct 369 ms 32996 KB Output is correct
55 Correct 320 ms 35100 KB Output is correct
56 Correct 348 ms 37308 KB Output is correct
57 Correct 325 ms 34916 KB Output is correct
58 Correct 344 ms 36756 KB Output is correct
59 Correct 5 ms 632 KB Output is correct
60 Correct 2 ms 376 KB Output is correct
61 Correct 5 ms 632 KB Output is correct
62 Correct 344 ms 36752 KB Output is correct
63 Correct 354 ms 36760 KB Output is correct
64 Correct 3 ms 504 KB Output is correct
65 Correct 342 ms 36828 KB Output is correct
66 Correct 333 ms 34928 KB Output is correct
67 Correct 387 ms 36064 KB Output is correct
68 Correct 5 ms 632 KB Output is correct
69 Correct 370 ms 34264 KB Output is correct
70 Correct 171 ms 16760 KB Output is correct
71 Correct 339 ms 36508 KB Output is correct
72 Correct 319 ms 34908 KB Output is correct
73 Correct 138 ms 17116 KB Output is correct
74 Correct 2 ms 376 KB Output is correct
75 Correct 329 ms 34896 KB Output is correct
76 Correct 111 ms 11640 KB Output is correct
77 Correct 4 ms 632 KB Output is correct
78 Correct 306 ms 33376 KB Output is correct
79 Correct 2 ms 376 KB Output is correct
80 Correct 4 ms 632 KB Output is correct
81 Correct 2 ms 376 KB Output is correct
82 Correct 351 ms 36872 KB Output is correct
83 Correct 3 ms 504 KB Output is correct
84 Correct 2 ms 376 KB Output is correct
85 Correct 393 ms 36392 KB Output is correct