Submission #1049582

#TimeUsernameProblemLanguageResultExecution timeMemory
1049582ThegeekKnight16Sails (IOI07_sails)C++17
100 / 100
57 ms2648 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MAXN = 1e5 + 10; array<ll, MAXN> bit; void update(int id, int val) { while (id < MAXN) { bit[id] += val; id += id&-id; } } ll query(int id) { ll resp = 0; while (id > 0) { resp += bit[id]; id -= id&-id; } return resp; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int N; cin >> N; vector<pair<int, int>> v(N); for (auto &[H, K] : v) cin >> H >> K; sort(v.begin(), v.end()); int bitFirstId = MAXN-1; for (auto [H, K] : v) { bitFirstId = MAXN-H; int biggestUpd = query(bitFirstId+K-1); if (query(bitFirstId) != biggestUpd) { int ini = bitFirstId, fim = MAXN-1; while (ini < fim) { int m = (ini + fim + 1) >> 1; if (query(m) < biggestUpd) ini = m; else fim = m-1; } update(bitFirstId, +1); update(ini+1, -1); K -= (ini - bitFirstId + 1); } int ini = bitFirstId, fim = MAXN-1; if (query(MAXN-1) == biggestUpd) ini = fim = MAXN; while (ini < fim) { int m = (ini + fim) >> 1; if (query(m) > biggestUpd) fim = m; else ini = m+1; } update(fim-K, +1); update(fim, -1); } ll resp = 0; for (int i = 1; i < MAXN; i++) { ll x = query(i); resp += (x * (x-1LL))/2LL; } cout << resp << '\n'; }
#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...