Submission #550809

#TimeUsernameProblemLanguageResultExecution timeMemory
550809JomnoiSails (IOI07_sails)C++17
100 / 100
87 ms2172 KiB
#include <bits/stdc++.h> #define DEBUG false using namespace std; const int MAX_N = 1e5 + 10; namespace fw { int fenwick[MAX_N]; void add(const int &idx, const int &v) { for(int i = idx; i < MAX_N; i += (i & -i)) { fenwick[i] += v; } } int get(const int &idx) { int res = 0; for(int i = idx; i >= 1; i -= (i & -i)) { res += fenwick[i]; } return res; } } int main() { cin.tie(nullptr)->sync_with_stdio(false); int N; cin >> N; vector <pair <int, int>> sail(N + 1); for(int i = 1; i <= N; i++) { int h, k; cin >> h >> k; sail[i] = make_pair(h, k); } sort(sail.begin() + 1, sail.end()); for(int i = 1; i <= N; i++) { auto [h, k] = sail[i]; int now = fw::get(h - k + 1), l, r, lm, rm; l = 1, r = h - k + 1, lm = 1; while(l <= r) { int mid = (l + r) / 2; if(fw::get(mid) == now) { r = mid - 1; lm = mid; } else { l = mid + 1; } } l = h - k + 1, r = h, rm = h; while(l <= r) { int mid = (l + r) / 2; if(fw::get(mid) == now) { l = mid + 1; rm = mid; } else { r = mid - 1; } } fw::add(rm + 1, 1); fw::add(h + 1, -1); fw::add(lm, 1); fw::add(lm + k - (h - rm), -1); } long long ans = 0; for(int i = 1; i < MAX_N; i++) { long long cnt = fw::get(i); ans += cnt * (cnt - 1) / 2; } cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...