Submission #813071

#TimeUsernameProblemLanguageResultExecution timeMemory
813071vjudge1코알라 (JOI13_koala)C++98
100 / 100
79 ms6860 KiB
#include <bits/stdc++.h> #define fi first #define se second #define ll long long #define pii pair<int,int> #define pll pair<ll,ll> #define pill pair<int,ll> #define mem(a, b) memset(a, b, sizeof(a)) #define MASK(i) (1LL << (i)) #define BIT(x, i) (((x) >> (i)) & 1) #define name "test" using namespace std; const int N = 1e5 + 5; const int mod = 1e9 + 7; const ll oo = 1e18; template <typename T1, typename T2> bool maxi(T1 &a, T2 b){if (a < b){a = b; return 1;} return 0;} template <typename T1, typename T2> bool mini(T1 &a, T2 b){if (a > b){a = b; return 1;} return 0;} bool ok; struct SEGTREE{ ll val[N << 2]; SEGTREE(){ mem(val, -0x3f); }; void update(int id, int l, int r, int i, ll x){ if (l > i || r < i) return; if (l == r){ val[id] = max(val[id], x); return; } int m = (l + r) >> 1; if (m >= i) update(id << 1, l, m, i, x); else update(id << 1 | 1, m + 1, r, i, x); val[id] = max(val[id << 1], val[id << 1 | 1]); } ll get(int id, int l, int r, int u, int v){ if (l > v || r < u) return -oo; if (l >= u && r <= v) return val[id]; int m = (l + r) >> 1; return max(get(id << 1, l, m, u, v), get(id << 1 | 1, m + 1, r, u, v)); } } ST; int s, t; int limDis, downPower, n; int a[N]; int b[N]; ll ans = -oo; vector <int> value; void load(){ cin.tie(0)->sync_with_stdio(0); if (fopen(name".inp", "r")){ freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); } } void input(){ cin >> s >> t >> limDis >> downPower >> n; for (int i = 1; i <= n; i++) cin >> a[i] >> b[i]; } void solve(){ a[0] = s; a[n + 1] = t; for (int i = 0; i <= n + 1; i++){ int r = a[i] % limDis; if (r == 0) r = limDis; value.push_back(r); } sort(value.begin(), value.end()); int nSeg = value.size(); int r = s % limDis; ll k = (s + limDis - 1) / limDis; if (r == 0) r = limDis; int id = lower_bound(value.begin(), value.end(), r) - value.begin() + 1; ST.update(1, 1, nSeg, id, k * downPower); for (int i = 1; i <= n + 1; i++){ int r = a[i] % limDis; ll k = (a[i] + limDis - 1) / limDis; if (r == 0) r = limDis; int id = lower_bound(value.begin(), value.end(), r) - value.begin() + 1; ll tmp1 = ST.get(1, 1, nSeg, 1, id - 1) - k * downPower - downPower + b[i]; ll tmp2 = ST.get(1, 1, nSeg, id, nSeg) - k * downPower + b[i]; if (i == n + 1) maxi(ans, max(tmp1, tmp2)); ST.update(1, 1, nSeg, id, max(tmp1, tmp2) + k * downPower); } cout << ans; } int main(){ load(); input(); solve(); }

Compilation message (stderr)

koala.cpp: In function 'void load()':
koala.cpp:58:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   58 |   freopen(name".inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
koala.cpp:59:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |   freopen(name".out", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...