Submission #140673

#TimeUsernameProblemLanguageResultExecution timeMemory
140673khrbuddy03XCorr (KOI18_XCorr)C++14
100 / 100
393 ms37308 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...