# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
392890 |
2021-04-22T07:37:25 Z |
Aldas25 |
Sails (IOI07_sails) |
C++14 |
|
99 ms |
2656 KB |
#include <bits/stdc++.h>
using namespace std;
#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr)
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define REP(n) FOR(O, 1, (n))
#define f first
#define s second
#define pb push_back
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef long long ll;
const int MAXN = 100100;
int n;
vii seq;
ll fen[MAXN];
void upd (int p, ll x) {
for (int i = p; i < MAXN; i += i&(-i))
fen[i] += x;
}
void upd (int fr, int to, ll x) {
upd (fr, x);
upd (to+1, -x);
}
ll get (int p) {
ll ret = 0;
for (int i = p; i > 0; i -= i&(-i))
ret += fen[i];
return ret;
}
int main()
{
FAST_IO;
cin >> n;
REP(n) {
int h, k; cin >> h >> k;
seq.pb({h, k});
}
sort(seq.begin(), seq.end());
ll ans = 0;
FOR(i, 0, n-1) {
int h = seq[i].f;
int k = seq[i].s;
ll lo = get(h - k + 1);
int rem = k;
if (get(h) < lo) {
int fr = h+1, to = h;
int le = h-k+1, ri = h;
while (le < ri) {
int mid = (le+ri)/2;
if (get(mid) >= lo) le = mid+1;
else ri = mid;
}
fr = le;
rem -= (to-le+1);
upd (fr, to, +1);
}
int le = 1, ri = h;
while (le < ri) {
int mid = (le+ri)/2;
if (get(mid) > lo) le = mid+1;
else ri = mid;
}
int fr = le, to = le + rem-1;
upd (fr, to, +1);
}
FOR(i, 0, MAXN-1) {
ll g = get(i);
if (g == 0) continue;
ans += (g * (g-1))/2;
}
cout << ans << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
332 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
332 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
360 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
332 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
332 KB |
Output is correct |
2 |
Correct |
4 ms |
1116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
676 KB |
Output is correct |
2 |
Correct |
24 ms |
1028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
47 ms |
1228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
74 ms |
1804 KB |
Output is correct |
2 |
Correct |
67 ms |
2656 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
77 ms |
1896 KB |
Output is correct |
2 |
Correct |
49 ms |
2496 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
99 ms |
1944 KB |
Output is correct |
2 |
Correct |
55 ms |
2464 KB |
Output is correct |