#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 |
1 |
Correct |
4 ms |
2944 KB |
Output is correct |
2 |
Correct |
4 ms |
3072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
3072 KB |
Output is correct |
2 |
Correct |
4 ms |
3072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
3072 KB |
Output is correct |
2 |
Correct |
6 ms |
3072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
3096 KB |
Output is correct |
2 |
Correct |
5 ms |
3072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
3200 KB |
Output is correct |
2 |
Correct |
11 ms |
3116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
191 ms |
3200 KB |
Output is correct |
2 |
Correct |
150 ms |
3424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1075 ms |
3968 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1063 ms |
4096 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1071 ms |
3712 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1065 ms |
4948 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1077 ms |
5176 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |