# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
799666 |
2023-07-31T18:23:41 Z |
Boomyday |
Sails (IOI07_sails) |
C++17 |
|
118 ms |
13504 KB |
//
// Created by adavy on 2/11/2023.
//
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
using ll = long long;
using ld = long double;
using db = double;
using str = string; // yay python!
using ii = pair<int,int>;
using pl = pair<ll,ll>;
using pd = pair<db,db>;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<ll>;
using vd = vector<db>;
using vs = vector<str>;
using vii = vector<ii>;
using vpl = vector<pl>;
using vpd = vector<pd>;
#define tcT template<class T
#define tcTU tcT, class U
tcT> using V = vector<T>;
tcT, size_t SZ> using AR = array<T,SZ>;
tcT> using PR = pair<T,T>;
// pairs
#define mp make_pair
#define f first
#define s second
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)
#define len(x) int((x).size())
#define bg(x) begin(x)
#define all(x) bg(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define sor(x) sort(all(x))
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define pb push_back
#define eb emplace_back
#define pf push_front
const int MOD = 1e9+7; // 998244353;
const int MX = 2e5+5;
const ll INF = 1e18; // not too close to LLONG_MAX
const ld PI = acos((ld)-1);
const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1}; // for every grid problem!!
int main(){
std::ios::sync_with_stdio(false); cin.tie(NULL);
int N; cin >> N;
vii fls(N); // height, number of sails
for(auto&[a,b]:fls){
cin >> a >> b;
}
sort(all(fls));
multiset<int> brksu = {0};
multiset<int, greater<int>> brksl = {0};
for(auto&[H,K]:fls){
brksu.insert(0); brksl.insert(0);
int hi = H, lo = H-K;
if (brksu.find(lo) == brksu.end()){
brksu.insert(hi); brksl.insert(hi);
//trav(i, brksu) cout << i << " ";
//cout << "brks" << endl;
auto lb=*brksl.lower_bound(lo), ub = *brksu.upper_bound(lo);
//cout << lb << " " << ub << hi << lo << endl;
brksu.erase(brksu.find(ub));
brksu.erase(brksu.find(lb));
brksu.insert(lb + (K - (hi-ub)));
brksl.erase(brksl.find(ub));
brksl.erase(brksl.find(lb));
brksl.insert(lb + (K - (hi-ub)));
}
else {
// this is the good case
brksu.insert(hi);
brksu.erase(brksu.find(lo));
brksl.insert(hi);
brksl.erase(brksl.find(lo));
}
//trav(i, brksu) cout << i << " ";
//cout << "brks" << endl;
}
//cout << "FOOBAR" << endl;
vl anses(100010, 0);
trav(i, brksu){
anses[0]++;
anses[i]--;
}
//cout << "FOOBAR" << endl;
vl anses2 = {0};
trav(i, anses){
anses2.pb(anses2.back()+i);
}
ll ans=0;
trav(i, anses2){
ans+=((i)*(i-1))/2;
}
cout << ans << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2260 KB |
Output is correct |
2 |
Correct |
2 ms |
2260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2260 KB |
Output is correct |
2 |
Correct |
2 ms |
2260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2260 KB |
Output is correct |
2 |
Correct |
2 ms |
2260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2260 KB |
Output is correct |
2 |
Correct |
2 ms |
2252 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2380 KB |
Output is correct |
2 |
Correct |
2 ms |
2380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
3012 KB |
Output is correct |
2 |
Correct |
31 ms |
5592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
5636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
57 ms |
7800 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
80 ms |
10700 KB |
Output is correct |
2 |
Correct |
87 ms |
10800 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
116 ms |
12360 KB |
Output is correct |
2 |
Correct |
118 ms |
12100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
118 ms |
13504 KB |
Output is correct |
2 |
Correct |
111 ms |
13380 KB |
Output is correct |