제출 #295826

#제출 시각아이디문제언어결과실행 시간메모리
295826caoashSails (IOI07_sails)C++14
100 / 100
103 ms2296 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; #define pb push_back #define rsz resize #define all(x) begin(x), end(x) #define sz(x) (int)(x).size() using pi = pair<int,int>; #define f first #define s second #define mp make_pair const int MX = 100005; template<int SZ> struct BIT { int bit[SZ]; void upd(int i, int x) { // cerr << "CHANGING: " << i << " " << x << '\n'; for (; i < SZ; i += (i & -i)) { // cerr << "UPD: " << i << '\n'; bit[i] += x; } } ll qry(int i) { // cerr << "QUERY: " << i << '\n'; ll ret = 0; for (; i > 0; i -= (i & -i)) { // cerr << "GOTO: " << i << '\n'; ret += bit[i]; } // cerr << ret << '\n'; return ret; } }; BIT<MX + 5> orz; void upd(int l, int r) { l++, r++; orz.upd(l, 1); orz.upd(r + 1, -1); } int get(int x) { return orz.qry(x + 1); } int main(){ ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<pi> sails(n); for (int i = 0; i < n; i++) { cin >> sails[i].f >> sails[i].s; } sort(all(sails)); // cerr << '\n'; auto getl = [&](int val) { int lo = 0; int hi = MX - 1; int ans = 0; while(lo <= hi) { int mid = (lo + hi) / 2; int curr = get(mid); if (curr < val) { lo = mid + 1; } else { ans = mid; hi = mid - 1; } } return ans; }; auto getr = [&](int val) { int lo = 0; int hi = MX - 1; int ans = 0; while(lo <= hi) { int mid = (lo + hi) / 2; int curr = get(mid); if (curr <= val) { lo = mid + 1; ans = mid; } else { hi = mid - 1; } } return ans; }; for (int i = 0; i < n; i++) { int cl = MX - sails[i].f, cr = cl + sails[i].s - 1; int val = get(cr); int cf = max(cl, getl(val)), cs = getr(val); int rem = sails[i].s; if (cf > cl) { upd(cl, cf - 1); rem -= (cf - cl); } upd(cs - rem + 1, cs); } ll ans = 0; for (int i = 0; i < MX; i++) { ll cv = get(i); ans += ((cv - 1) * cv) / 2; } cout << ans << '\n'; }
#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...