# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
521206 | cadmiumsky | Sails (IOI07_sails) | C++14 | 1095 ms | 5168 KiB |
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>
using namespace std;
const int nmax = 1e5 + 5;
#define ll long long
namespace Slope {
multiset<int> slope;
int val0;
int last;
void init() {
slope.insert(0);
val0 = 1;
last = 0;
return;
}
void insert(int l, int k) {
//cout << l << ' ' << k << '\n';
if(k == 0)
return;
if(last < l) {
while(slope.size() < val0) {
slope.insert(last + 1);
}
last = l;
}
auto it = upper_bound(slope.begin(), slope.end(), l - k), lst = it;
lst--;
bool ok = 0;
if(*lst == 0) {
val0++;
ok = 1;
}
int decr = k;
if(it != slope.end())
decr = *it - (l - k);
int temp = *lst;
slope.erase(lst);
if(it != slope.end())
slope.erase(it), slope.insert(l);
slope.insert(temp + decr);
if(ok)
slope.insert(0);
//cout << val0 << '\n';
//for(auto x : slope)
//cout << x << ' ';
//cout << '\n';
}
void calculate() {
ll sum = 0;
for(int i = 1; i <= last; i++) {
while(slope.size() && *slope.begin() < i)
val0--, slope.erase(slope.begin());
//cout << i << ' ' << val0 << '\n';
sum += (ll)val0 * (val0 - 1) / 2LL;
}
#undef it
cout << sum << '\n';
return;
}
}
vector<int> v[nmax];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
int maxx = 0;
for(int i = 0,a ,b; i < n; i++) {
cin >> a >> b;
maxx = max(maxx, a);
v[a].push_back(b);
}
Slope::init();
for(int i = 1; i <= maxx; i++) {
for(auto r : v[i])
Slope::insert(i, r);
}
Slope::calculate();
return 0;
}
Compilation message (stderr)
# | 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... |