Submission #963740

#TimeUsernameProblemLanguageResultExecution timeMemory
963740IcelastSails (IOI07_sails)C++17
70 / 100
1043 ms9532 KiB
#include <iostream> #include <bits/stdc++.h> #define ll long long using namespace std; const ll maxn = 1e5+5, INF = 4e18+9; ll n; struct mast{ ll h, k; }; mast a[maxn]; bool cmp(mast a, mast b){ return a.h < b.h; } void inp(){ cin >> n; for(int i = 1; i <= n; i++){ cin >> a[i].h >> a[i].k; } } ll N, T[4*maxn], lz[4*maxn]; void build_segtree(){ N = 1; while(N < 1e5){ N*=2; } } void down(int node, int len){ for(int child = node*2; child <= node*2+1; child++){ if(child >= 2*N) continue; lz[child] += lz[node]; } T[node]+=lz[node]*len; lz[node] = 0; } void upd(int node, int low, int high, int l, int r, ll x){ if(r < l) return; down(node, high-low+1); if(low > r || l > high){ return; } if(low >= l && r >= high){ lz[node] += x; down(node, high-low+1); return; } int mid = (low+high)/2; upd(node*2, low, mid, l, r, x); upd(node*2+1, mid+1, high, l, r, x); T[node] = T[node*2]+T[node*2+1]; } ll get_sum(int node, int low, int high, int l, int r){ if(r < l) r = l; down(node, high-low+1); if(low > r || l > high){ return 0; } if(low >= l && r >= high){ return T[node]; } int mid = (low+high)/2; return get_sum(node*2, low, mid, l, r)+get_sum(node*2+1, mid+1, high, l, r); } int get_pos(ll k, ll M){ ll l = 1, r = M, mid; while(l <= r){ mid = (l+r)/2; if(get_sum(1, 1, N, mid, N)-get_sum(1, 1, N, mid+1, N) >= k){ l = mid+1; }else{ r = mid-1; } } return l-1; } void solve(){ sort(a+1, a+1+n, cmp); build_segtree(); ll M, k; for(int i = 1; i <= n; i++){ M = a[i].h; k = a[i].k; ll x = get_sum(1, 1, N, M-k+1, M-k+1); int u = get_pos(x, M); int d = get_pos(x+1, M)+1; upd(1, 1, N, u+1, M, 1); upd(1, 1, N, d, d+u-(M-k+1), 1); } ll ans = 0; for(int i = 1; i <= M; i++){ ll x = get_sum(1, 1, N, i, i); ans += x*(x-1)/2; } cout << ans; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); inp(); solve(); }

Compilation message (stderr)

sails.cpp: In function 'void solve()':
sails.cpp:90:22: warning: 'M' may be used uninitialized in this function [-Wmaybe-uninitialized]
   90 |     for(int i = 1; i <= M; i++){
      |                    ~~^~~~
#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...