Submission #1095569

#TimeUsernameProblemLanguageResultExecution timeMemory
1095569susanthenerdSails (IOI07_sails)C++17
0 / 100
1055 ms7260 KiB
#include <iostream> #include <array> #include <vector> #include <algorithm> using namespace std; using ll = long long; constexpr ll VMAX = 1e5 + 1; array<pair<ll, ll>, VMAX * 4> aint; pair<ll, ll> combine(pair<ll, ll> a, pair<ll, ll> b) { if (a.first == b.first) { a.second += b.second; return a; } return min(a, b); } void build(ll nod, ll st, ll dr) { if (st == dr) { aint[nod] = {0, 1}; return; } ll mij = (st + dr) / 2; build(nod * 2, st, mij); build(nod * 2 + 1, mij + 1, dr); aint[nod] = combine(aint[nod * 2], aint[nod * 2 + 1]); } void update(ll x, ll y, ll &cnt, ll val, ll nod, ll st, ll dr) { if (dr < x || y < st || cnt == 0) return; if (st == dr) { aint[nod].first += val; --cnt; return; } ll mij = (st + dr) / 2; if (x <= st && dr <= y) { if (aint[nod].first == aint[nod * 2 + 1].first) update(x, y, cnt, val, nod * 2 + 1, mij + 1, dr); if (aint[nod].first == aint[nod * 2].first) update(x, y, cnt, val, nod * 2, st, mij); aint[nod] = combine(aint[nod * 2], aint[nod * 2 + 1]); return; } update(x, y, cnt, val, nod * 2 + 1, mij + 1, dr); update(x, y, cnt, val, nod * 2, st, mij); aint[nod] = combine(aint[nod * 2], aint[nod * 2 + 1]); } ll query(ll nod, ll st, ll dr) { if (st == dr) { return aint[nod].first * (aint[nod].first - 1) / 2LL; } ll mij = (st + dr) / 2; ll q_st = query(nod * 2, st, mij); ll q_dr = query(nod * 2 + 1, mij + 1, dr); return q_st + q_dr; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); ll n; cin >> n; build(1, 1, VMAX - 1); vector<pair<ll, ll> > v(n); for (auto &[k, h]: v) cin >> h >> k; sort(v.begin(), v.end()); for (auto &[k, h]: v) { while (k) { update(1, h, k, 1, 1, 1, VMAX - 1); } } cout << query(1, 1, VMAX - 1); }
#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...