Submission #449815

#TimeUsernameProblemLanguageResultExecution timeMemory
449815prvocisloSails (IOI07_sails)C++17
100 / 100
72 ms4636 KiB
#include <iostream> #include <vector> #include <algorithm> #include <set> typedef long long ll; using namespace std; const int maxn = 1e5 + 5; int d[maxn], H = 0; // rozdiel oproti predoslemu, posledny aktivny stlpec set<int> b; void add(int l, int r) // chceme pridat l a r vratane { if (r < l) return; d[l]++, d[r + 1]--; if (d[l] == 0) b.erase(l); if (d[r + 1] < 0) b.insert(r + 1); } struct mast { int h, k; } ship[maxn]; bool cmp(const mast& a, const mast& b) { return a.h < b.h; } int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; for (int i = 0; i < n; i++) cin >> ship[i].h >> ship[i].k; sort(ship, ship + n, cmp); b.insert(1); //cout << "\n"; for (int i = 0; i < n; i++) { if (H != ship[i].h) { if (H && d[H + 1] == 0) b.erase(H + 1); H = ship[i].h; b.insert(H + 1); } int l = H - ship[i].k + 1; int l1 = *b.lower_bound(l), r1 = H; int len = ship[i].k - max(0, r1 - l1 + 1); int l2 = *prev(b.upper_bound(l)), r2 = l2 + len - 1; add(l1, r1); add(l2, r2); /*for (int i = 1, val = d[1]; i <= H; val += d[++i]) cout << val << " "; cout << "\n";*/ } ll ans = 0; for (int i = 1, val = d[1]; i <= H; val += d[++i]) { ans += val * 1ll * (val - 1) / 2ll; } cout << ans << "\n"; 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...