#include <iostream>
#include <array>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
constexpr ll VMAX = 1e5 + 1;
array<pair<ll, ll>, VMAX * 4> aint;
pair<ll, ll> combine(pair<ll, ll> a, pair<ll, ll> b) {
if (a.first == b.first) {
a.second += b.second;
return a;
}
return min(a, b);
}
void build(ll nod, ll st, ll dr) {
if (st == dr) {
aint[nod] = {0, 1};
return;
}
ll mij = (st + dr) / 2;
build(nod * 2, st, mij);
build(nod * 2 + 1, mij + 1, dr);
aint[nod] = combine(aint[nod * 2], aint[nod * 2 + 1]);
}
void update(ll x, ll y, ll &cnt, ll val, ll nod, ll st, ll dr) {
if (dr < x || y < st || cnt == 0) return;
if (st == dr) {
aint[nod].first += val;
--cnt;
return;
}
ll mij = (st + dr) / 2;
if (x <= st && dr <= y) {
if (aint[nod].first == aint[nod * 2 + 1].first)
update(x, y, cnt, val, nod * 2 + 1, mij + 1, dr);
if (aint[nod].first == aint[nod * 2].first)
update(x, y, cnt, val, nod * 2, st, mij);
aint[nod] = combine(aint[nod * 2], aint[nod * 2 + 1]);
return;
}
update(x, y, cnt, val, nod * 2 + 1, mij + 1, dr);
update(x, y, cnt, val, nod * 2, st, mij);
aint[nod] = combine(aint[nod * 2], aint[nod * 2 + 1]);
}
ll query(ll nod, ll st, ll dr) {
if (st == dr) {
return aint[nod].first * (aint[nod].first - 1) / 2LL;
}
ll mij = (st + dr) / 2;
ll q_st = query(nod * 2, st, mij);
ll q_dr = query(nod * 2 + 1, mij + 1, dr);
return q_st + q_dr;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll n;
cin >> n;
build(1, 1, VMAX - 1);
vector<pair<ll, ll> > v(n);
for (auto &[k, h]: v)
cin >> h >> k;
sort(v.begin(), v.end());
for (auto &[k, h]: v) {
while (k) {
update(1, h, k, 1, 1, 1, VMAX - 1);
}
}
cout << query(1, 1, VMAX - 1);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
4696 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4444 KB |
Output is correct |
2 |
Incorrect |
2 ms |
4444 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
4444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
4444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
41 ms |
4444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
672 ms |
4700 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1055 ms |
5212 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1055 ms |
5724 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1042 ms |
6492 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1033 ms |
7000 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1038 ms |
7260 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |