Submission #773300

#TimeUsernameProblemLanguageResultExecution timeMemory
773300rominanafuSails (IOI07_sails)C++11
100 / 100
103 ms3924 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; struct ura { ll h, k; }; ll n, tam; ura masts[100005]; ll ST[400009]; bool cmp(const ura &a, const ura &b) { return a.h < b.h; } void actualizar(ll pos, int val, ll nodo=1, ll ini=1, ll fin=100001) { if (pos < ini || pos > fin) return; if (ini == fin) { ST[nodo] += val; return; } ll mid = (ini+fin) / 2; actualizar(pos, val, nodo*2, ini, mid); actualizar(pos, val, nodo*2+1, mid+1, fin); ST[nodo] = ST[nodo*2] + ST[nodo*2+1]; } ll suma(ll pos, ll nodo=1, ll ini=1, ll fin=100001) { if (pos < ini) return 0; if (pos >= fin) return ST[nodo]; ll s=0; ll mid = (ini + fin) / 2; s += suma(pos, nodo*2, ini, mid); s += suma(pos, nodo*2+1, mid+1, fin); return s; } ll posicion_menor(ll num, ll sum=0, int nodo=1, int ini=1, int fin=100001) { if (ini == fin) return ini; ll mid = (ini+fin) / 2; if (sum+ST[nodo*2] >= num) { return posicion_menor(num, sum+ST[nodo*2], nodo*2+1, mid+1, fin); } return posicion_menor(num, sum, nodo*2, ini, mid); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; for(ll i=0; i<n; i++) { cin >> masts[i].h >> masts[i].k; tam = max(tam, masts[i].h); } sort(masts, masts+n, cmp); ll pos_menor, pos_igual, s; for(ll i=0; i<n; i++) { s = suma(masts[i].h - masts[i].k + 1); pos_menor = posicion_menor(s); pos_igual = posicion_menor(s+1); if (s != 0) { ///para pos_menor: actualizar(pos_menor, 1); actualizar(masts[i].h + 1, -1); masts[i].k -= masts[i].h + 1 - pos_menor; } ///para pos_igual: actualizar(pos_igual, 1); actualizar(pos_igual + masts[i].k, -1); } ll resp=0; for(ll i=0; i<=masts[n-1].h; i++) { s = suma(i); resp += (s * (s - 1)) / 2; } cout << resp; 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...