Submission #773297

#TimeUsernameProblemLanguageResultExecution timeMemory
773297rominanafuSails (IOI07_sails)C++11
45 / 100
227 ms2448 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; struct ura { int h, k; }; int n, tam; ura masts[100005]; int ST[400005]; int diferencias[100005]; bool cmp(const ura &a, const ura &b) { return a.h < b.h; } void actualizar(int pos, int val, int nodo=1, int ini=1, int fin=100000) { if (pos < ini || pos > fin) return; if (ini == fin) { ST[nodo] += val; diferencias[ini] += val; return; } int 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(int pos, int nodo=1, int ini=1, int fin=100000) { if (pos < ini) return 0; if (pos >= fin) return ST[nodo]; ll s=0; int mid = (ini + fin) / 2; s += suma(pos, nodo*2, ini, mid); s += suma(pos, nodo*2+1, mid+1, fin); return s; } int pos_primer_num_menor(ll &num) { int izq=1, der=100000, mid, r=0; while (izq <= der) { mid = (izq+der) / 2; if (suma(mid) < num) { r = mid; der = mid-1; } else { izq = mid+1; } } return r; } int pos_primer_num_igual(ll &num) { int izq=1, der=100000; int mid, r=0; while (izq <= der) { mid = (izq+der) / 2; if (suma(mid) > num) { izq = mid+1; } else { der = mid-1; r = mid; } } return r; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; for(int i=0; i<n; i++) { cin >> masts[i].h >> masts[i].k; tam = max(tam, masts[i].h); } sort(masts, masts+n, cmp); actualizar(1, 1); actualizar(masts[0].k+1, -1); ll s; int pos1, pos2; for(int i=1; i<n; i++) { if (diferencias[masts[i].h - masts[i].k + 1] < 0) { actualizar(masts[i].h - masts[i].k + 1, 1); actualizar(masts[i].h + 1, -1); } else { s = suma(masts[i].h - masts[i].k + 1); pos1 = pos_primer_num_igual(s); pos2 = pos_primer_num_menor(s); masts[i].k -= masts[i].h - pos2; actualizar(pos1, 1); actualizar(pos1 + masts[i].k - 1, -1); //--------- actualizar(pos2, 1); actualizar(masts[i].h + 1, -1); } } ll resp=0; for(int i=1; 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...