이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 <int> h(n + 1), k(n + 1), ord(n + 1);
for(i = 1; i <= n; i++) {
cin >> h[i] >> k[i];
ord[i] = i;
}
sort(next(ord.begin()), ord.end(), [&](const int &a, const int &b) {
return h[a] < h[b];
});
vector <int> cnt(MAXH + 1);
for(i = 1; i <= n; i++) {
int val = cnt[h[ord[i]] - k[ord[i]] + 1];
int pos = h[ord[i]];
while(cnt[pos] != val) {
k[ord[i]]--;
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[ord[i]]--) {
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... |