Submission #550807

#TimeUsernameProblemLanguageResultExecution timeMemory
550807JomnoiSails (IOI07_sails)C++17
25 / 100
76 ms2624 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++) { cin >> sail[i].first >> sail[i].second; } 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, 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 = 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++) { int cnt = fw::get(i); ans += 1ll*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...