Submission #670100

#TimeUsernameProblemLanguageResultExecution timeMemory
670100raypeng1729Sails (IOI07_sails)C++17
0 / 100
41 ms4296 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define all(v) v.begin(), v.end() const int N = 1e5 + 2, INF = 1e9 + 1, MOD = 1e9 + 7, K = __lg(N) + 1; struct BIT{ int n; vector<int> v; BIT(){v.assign(N, 0);} void add(int i, int x){ for(; i < N; i += i & (-i)) v[i] += x; } int qry(int i){ int ret = 0; for(; i > 0; i -= i & (-i)) ret += v[i]; return ret; } }; signed main(){ ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; int a[n], b[n], mx = 0; for(int i = 0; i < n; i++) cin >> a[i] >> b[i]; int st[n + 2]{}, en[n + 2]{}; st[0] = 1, en[0] = n; BIT bit; for(int i = 0; i < n; i++){ while(b[i]){ int x = bit.qry(a[i]); int y = min(b[i], a[i] - st[x] + 1); b[i] -= y; bit.add(st[x], 1), bit.add(st[x] + y, -1); if(st[x + 1] == 0) st[x + 1] = st[x]; en[x + 1] = max(en[x + 1], st[x] + y - 1); st[x] = st[x] + y; } } int ans = 0; for(int i = 0; i <= n; i++){ int x = bit.qry(i); ans += x * (x - 1) / 2; } cout << ans; }

Compilation message (stderr)

sails.cpp: In function 'int main()':
sails.cpp:22:21: warning: unused variable 'mx' [-Wunused-variable]
   22 |     int a[n], b[n], mx = 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...