Submission #305497

#TimeUsernameProblemLanguageResultExecution timeMemory
305497AkashiSails (IOI07_sails)C++14
100 / 100
72 ms3068 KiB
#include <bits/stdc++.h> using namespace std; const int DIM = 1e5 + 5; struct poles{ int h, k; bool operator < (const poles &aux)const{ return h < aux.h; } }; poles a[DIM]; int n, mx, now; int sp[DIM], aib[DIM]; void update(int pos, int val) { sp[pos] += val; for (int i = pos; i <= mx ; i = i + (i & (-i))) aib[i] += val; } int query(int pos) { int ans = 0; for (int i = pos; i > 0 ; i = i - (i & (-i))) ans += aib[i]; return ans; } int find_left(int val) { int ans = 0, sum = 0; for (int bit = (1 << 30); bit >= 1 ; bit = bit >> 1) { if (ans + bit > now) continue ; if (sum + aib[ans | bit] > val) ans |= bit, sum += aib[ans]; } return ans + 1; } int find_right(int val) { int ans = 0, sum = 0; for (int bit = (1 << 30); bit >= 1 ; bit = bit >> 1) { if (ans + bit > now) continue ; if (sum + aib[ans | bit] >= val) ans |= bit, sum += aib[ans]; } return ans; } int main() { #ifdef HOME freopen("sails.in", "r", stdin); freopen("sails.out", "w", stdout); #endif // HOME scanf("%d", &n); for (int i = 1; i <= n ; ++i) { scanf("%d%d", &a[i].h, &a[i].k); mx = max(mx, a[i].h); } ++mx; sort(a + 1, a + n + 1); now = 1; for (int i = 1; i <= n ; ++i) { while (now < a[i].h) ++now; int ind = now - a[i].k + 1; int val = query(ind); int l = find_left(val), r = find_right(val); if (l == ind) { update(ind, 1); update(now + 1, -1); } else { int cnt = r - ind + 1; update(l, 1); update(l + cnt, -1); if (r + 1 <= now) { update(r + 1, 1); update(now + 1, -1); } } } long long Sol = 0; for (int i = 1; i <= mx ; ++i) { sp[i] += sp[i - 1]; Sol = Sol + 1LL * sp[i] * (sp[i] - 1) / 2; } printf("%lld", Sol); return 0; }

Compilation message (stderr)

sails.cpp: In function 'int main()':
sails.cpp:58:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   58 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
sails.cpp:60:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   60 |         scanf("%d%d", &a[i].h, &a[i].k);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#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...