This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
// 217
// 44
using namespace std;
const int MAXH = (int) 1e5;
int main() {
//ifstream cin("A.in");
//ofstream cout("A.out");
int i, n;
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n;
vector < vector <int> > arr(MAXH + 1);
for(i = 1; i <= n; i++) {
int h, k;
cin >> h >> k;
arr[h].push_back(k);
}
vector <int> cnt(MAXH + 1);
for(int h = 1; h <= MAXH; h++) {
for(auto &k : arr[h]) {
int val = cnt[h - k + 1];
int pos = h;
while(cnt[pos] != val) {
k--;
cnt[pos--]++;
}
int res = 0;
for(int step = 1 << 16; step; step >>= 1) {
if(res + step <= MAXH && cnt[res + step] > val) {
res += step;
}
}
while(k--) {
cnt[++res]++;
}
}
}
ll ans = 0;
for(i = 1; i <= MAXH; i++) {
ans += 1LL * cnt[i] * (cnt[i] - 1) / 2;
}
cout << ans;
//cin.close();
//cout.close();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |