Submission #897221

#TimeUsernameProblemLanguageResultExecution timeMemory
897221trMatherzSails (IOI07_sails)C++17
100 / 100
106 ms3972 KiB
#include <iostream> //cin, cout /* #include <fstream> std::ifstream cin ("ex.in"); std::ofstream cout ("ex.out"); */ // includes #include <cmath> #include <set> #include <map> #include <queue> #include <string> #include <vector> #include <array> #include <algorithm> #include <numeric> #include <iomanip> #include <unordered_set> #include <stack> #include <ext/pb_ds/assoc_container.hpp> #include <random> #include <chrono> //usings using namespace std; using namespace __gnu_pbds; // misc #define ll long long #define pb push_back #define pq priority_queue #define ub upper_bound #define lb lower_bound template<typename T, typename U> bool emin(T &a, const U &b){ return b < a ? a = b, true : false; } template<typename T, typename U> bool emax(T &a, const U &b){ return b > a ? a = b, true : false; } typedef uint64_t hash_t; // vectors #define vi vector<int> #define vvi vector<vi> #define vvvi vector<vvi> #define vpii vector<pair<int, int>> #define vvpii vector<vector<pair<int, int>>> #define vppipi vector<pair<int, pair<int, int>>> #define vl vector<ll> #define vvl vector<vl> #define vvvl vector<vvl> #define vpll vector<pair<ll, ll>> #define vb vector<bool> #define vvb vector<vb> #define vs vector<string> #define sz(x) (int)x.size() #define rz(x,y) x.resize(y) #define all(x) x.begin(), x.end() // pairs #define pii pair<int, int> #define pll pair<ll, ll> #define mp make_pair #define f first #define s second // sets #define si set<int> #define sl set<ll> #define ss set<string> #define in insert template <class T> using iset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // maps #define mii map<int, int> #define mll map<ll, ll> // loops #define FR(x, z, y) for (int x = z; x < y; x++) #define FRe(x, z, y) FR(x, z, y + 1) #define F(x, y) FR(x, 0, y) #define Fe(x, y) F(x, y + 1) #define A(x, y) for(auto &x : y) int m; vi arr, tre; void add(int x, int v){ if(x == m) return; arr[x++] += v; for(;x <= m; x += x & -x) tre[x] += v; } int sum(int x){ int ret = 0; for(x++; x > 0; x -= x & -x) ret += tre[x]; return ret; } int lfind(int x){ int l = 0, r = m - 1; while(l < r){ int m = l + (r - l - 1) / 2; if(sum(m) >= x) r = m; else l = m + 1; } return l; } int rfind(int x){ int l = 0, r = m - 1; while(l < r){ int m = l + (r - l + 1) / 2; if(sum(m) > x) r = m - 1; else l = m; } return l; } int main(){ int n; cin >> n; vpii a(n); m = 0; vi v; vpii input(n); A(u, input) {cin >> u.f >> u.s; emax(m, u.f);} F(i, n){ int x = input[i].f, y = input[i].s; a[i] = {x, y}; v.pb(m - x); } arr = vi(m, 0); tre = vi(m + 1, 0); F(i, n) add(v[i], 1); sort(all(a), [](auto a, auto b){return a.f < b.f;}); F(i, n){ int d = a[i].f - a[i].s - 1; if(d == -1) continue; int lp = lfind(sum(m - d - 1)); int rp = rfind(sum(m - d - 1)); add(rp + 1, -1); add(lp, -1); add(d - (m - rp - 1) + lp + 1, 1); } ll an = 0; ll cur = -1; A(u, arr){ cur += u; an += cur * (cur + 1) / 2; } cout << an; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...