제출 #428869

#제출 시각아이디문제언어결과실행 시간메모리
428869Keshi식물 비교 (IOI20_plants)C++17
0 / 100
74 ms21828 KiB
//In the name of God #include <bits/stdc++.h> #include "plants.h" using namespace std; typedef int ll; typedef pair<ll, ll> pll; const ll maxn = 2e5 + 100; const ll mod = 1e9 + 7; const ll inf = 1e9; #define fast_io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define Mp make_pair #define F first #define S second #define pb push_back #define all(x) (x).begin(), (x).end() #define Sz(x) ll((x).size()) #define lc (id << 1) #define rc (lc | 1) ll n, k, dd, a[maxn], b[maxn]; inline ll dis(ll i, ll j){ if(i < j) return j - i; return j - i + n; } struct node{ ll mn, lx, rx, lz; pll ok; node(){ mn = lx = inf; rx = -inf; ok = Mp(-1, -1); lz = 0; } }; node seg[maxn << 2]; void mrg(ll id){ seg[id] = node(); seg[id].mn = min(seg[lc].mn, seg[rc].mn); seg[id].ok = max(seg[lc].ok, seg[rc].ok); if(seg[id].mn != seg[lc].mn){ seg[id].lx = seg[rc].lx; seg[id].rx = seg[rc].rx; } else if(seg[id].mn != seg[rc].mn){ seg[id].lx = seg[lc].lx; seg[id].rx = seg[lc].rx; } else{ seg[id].lx = seg[lc].lx; seg[id].rx = seg[rc].rx; if(seg[rc].lx - seg[lc].rx >= dd){ seg[id].ok = Mp(seg[rc].lx, seg[lc].rx); } } } void shift(ll id){ seg[lc].mn += seg[id].lz; seg[lc].lz += seg[id].lz; seg[rc].mn += seg[id].lz; seg[rc].lz += seg[id].lz; seg[id].lz = 0; } void bld(ll id, ll s, ll e){ if(e - s == 1){ seg[id].lx = seg[id].rx = s; seg[id].mn = a[s]; return; } ll mid = (s + e) >> 1; bld(lc, s, mid); bld(rc, mid, e); mrg(id); return; } void upd(ll id, ll s, ll e, ll l, ll r, ll x){ if(r <= s || e <= l) return; if(l <= s && e <= r){ seg[id].mn += x; seg[id].lz += x; return; } shift(id); ll mid = (s + e) >> 1; upd(lc, s, mid, l, r, x); upd(rc, mid, e, l, r, x); mrg(id); return; } void init(int K, vector<int> R){ k = K; n = Sz(R); for(ll i = 0; i < n; i++){ a[i] = R[i]; } dd = n - k; bld(1, 0, n); for(ll i = n; i--;){ ll x; if(~seg[1].ok.F) x = seg[1].ok.F; else x = seg[1].lx; b[x] = i; ll y = x - dd; if(y < 0) y += n; upd(1, 0, n, x, x + 1, inf); if(y < x){ upd(1, 0, n, y, x, -1); } else{ upd(1, 0, n, 0, x, -1); upd(1, 0, n, y, n, -1); } } return; } int compare_plants(int x, int y){ if(b[x] > b[y]) return 1; return -1; }
#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...