Submission #877119

#TimeUsernameProblemLanguageResultExecution timeMemory
877119MarwenElarbiSails (IOI07_sails)C++17
100 / 100
80 ms3988 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using ii = pair<int, int>; #define foru(i, l, r) for(int i=(l); i<=(r); ++i) #define ford(i, l, r) for(int i=(l); i>=(r); --i) #define fore(x, v) for(auto &x : v) #define fi first #define se second void setIO(string name) { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); if (!name.empty()) { freopen((name + ".in").c_str(), "r", stdin); freopen((name + ".out").c_str(), "w", stdout); } } const int N = 1e5+5, V = 1e5; const int LOG = 17; int n; ll ans, bit[2][N]; ii mast[N]; void modify(int t, int i, ll v) { for(; i<=V; i+=i&-i) bit[t][i] += v; } ll get(int t, int i) { ll ans = 0; for(; i>=1; i-=i&-i) ans += bit[t][i]; return ans; } void inc(int l, int r, ll v) { modify(0, l, v); modify(0, r+1, -v); modify(1, l, v * (l-1)); modify(1, r+1, - v * r); } ll sum_range(ll i) { return get(0, i) * i - get(1, i); } ll sum_range(int l, int r) { return sum_range(r) - sum_range(l-1); } int lst(int val) { int cur = 0, till = 0; for(int i=LOG-1; i>=0; --i) if (cur+(1<<i) <= V && till+bit[0][cur+(1<<i)] <= val) cur += 1 << i, till += bit[0][cur]; return cur; } int main() { cin >> n; foru(i, 1, n) { cin >> mast[i].fi >> mast[i].se; } sort(mast+1, mast+n+1); foru(i, 1, n) { int hei = mast[i].fi, cnt = mast[i].se; int lb = V-hei+1, alpha = get(0, min(V, lb+cnt-1)); int rb = lst(alpha), rx = max(lb-1, lst(alpha-1)), lx = max(rx+1, rb-(cnt-(rx-lb+1))+1); ans += sum_range(lb, rx); ans += sum_range(lx, rb); inc(lb, rx, 1); inc(lx, rb, 1); } cout << ans; }

Compilation message (stderr)

sails.cpp: In function 'void setIO(std::string)':
sails.cpp:16:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |     freopen((name + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sails.cpp:17:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |     freopen((name + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...