제출 #1279275

#제출 시각아이디문제언어결과실행 시간메모리
1279275wedonttalkanymoreSails (IOI07_sails)C++20
0 / 100
118 ms8276 KiB
#include <bits/stdc++.h> /* Wake up, I'm wake up Thu sang roi, em thay khong? */ using namespace std; using ll = long long; #define int long long #define pii pair<ll, ll> #define fi first #define se second const ll N = 2e5 + 5, inf = 1e18, mod = 1e9 + 7, block = 320, lim = 19; int n; pii a[N]; struct ST { vector<int> st, lz; ST (int _n = 0) { if (_n <= 0) _n = 1; st.assign(4 * (_n + 1), 0); lz.assign(4 * (_n + 1), 0); } void lazy(int i, int l, int r) { if (lz[i] != 0) { if (l < r) { st[2 * i] += lz[i]; st[2 * i + 1] += lz[i]; lz[2 * i] += lz[i]; lz[2 * i + 1] += lz[i]; } lz[i] = 0; } } void update(int i, int l, int r, int u, int v, int val) { if (u > r || v < l) return; if (u <= l && r <= v) { st[i] += val; lz[i] += val; return; } lazy(i, l, r); int mid = (l + r) / 2; update(2 * i, l, mid, u, v, val); update(2 * i + 1, mid + 1, r, u, v, val); st[i] = min(st[2 * i], st[2 * i + 1]); } int get(int i, int l, int r, int u, int v) { if (u > r || v < l) return inf; lazy(i, l, r); if (u <= l && r <= v) return st[i]; int mid = (l + r) / 2; return min(get(2 * i, l, mid, u, v), get(2 * i + 1, mid + 1, r, u, v)); } int findL(int i, int l, int r, int ql, int qr, int val) { if (ql > r || qr < l) return -1; lazy(i, l, r); if (st[i] > val) return -1; if (l == r) return l; int mid = (l + r) / 2; int ans = findL(2 * i, l, mid, ql, qr, val); if (ans != -1) return ans; return findL(2 * i + 1, mid + 1, r, ql, qr, val); } }; signed main() { ios::sync_with_stdio(false); cin.tie(0); if (fopen(".inp", "r")) { freopen(".inp", "r", stdin); freopen(".out", "w", stdout); } cin >> n; for (int i = 1; i <= n; i++) cin >> a[i].fi >> a[i].se; sort(a + 1, a + n + 1); int maxx = 0; for (int i = 1; i <= n; i++) maxx = max(maxx, a[i].fi); if (maxx <= 0) { cout << 0; return 0; } ST st(maxx); for (int i = 1; i <= n; i++) { int rbound = a[i].fi; if (rbound < 1) continue; int value = st.get(1, 1, maxx, 1, rbound); int L = st.findL(1, 1, maxx, 1, rbound, value); if (L == -1) continue; int R = min(a[i].fi, L + a[i].se - 1); if (L <= R) st.update(1, 1, maxx, L, R, 1); if (L + a[i].se - 1 > a[i].fi) { int remain = (L + a[i].se - 1) - a[i].fi; int rightBound = L - remain; if (rightBound >= 1) { value = st.get(1, 1, maxx, 1, rightBound); int nxtL = st.findL(1, 1, maxx, 1, rightBound, value); if (nxtL != -1) st.update(1, 1, maxx, nxtL, nxtL + remain - 1, 1); } } } int ans = 0; for (int i = 1; i <= maxx; i++) { int val = st.get(1, 1, maxx, i, i); ans += val * (val - 1) / 2; } cout << ans; return 0; }

컴파일 시 표준 에러 (stderr) 메시지

sails.cpp: In function 'int main()':
sails.cpp:73:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   73 |         freopen(".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~
sails.cpp:74:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   74 |         freopen(".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
#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...