# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
372695 | 2021-03-01T10:03:17 Z | minhcool | 코알라 (JOI13_koala) | C++17 | 202 ms | 18764 KB |
#include<bits/stdc++.h> using namespace std; #define int long long #define fi first #define se second #define pb push_back #define mp make_pair typedef pair<int, int> ii; typedef pair<ii, int> iii; typedef pair<ii, ii> iiii; const int oo = 1e18 + 7, mod = 1e9 + 7; const int N = 1e5 + 5; int k, m, n, d, aa, a[N], b[N], dp[N]; set<int> remainders; unordered_map<int, int> uomp; struct it{ int n; int arr[N << 2], laz[N << 2]; it(int _n): n(_n){ for(int i = 1; i <= (4 * n); i++) arr[i] = laz[i] = -oo; } void lazy(int id){ if(laz[id] = -oo) return; arr[id << 1] = max(arr[id << 1], laz[id]); laz[id << 1] = max(laz[id << 1], laz[id]); arr[id << 1 | 1] = max(arr[id << 1 | 1], laz[id]); laz[id << 1 | 1] = max(laz[id << 1 | 1], laz[id]); laz[id] = -oo; } void update(int id, int l, int r, int L, int R, int val){ if(l > R || r < L || l > r) return; if(l >= L && r <= R){ //cout << id << " " << val << "\n"; arr[id] = max(arr[id], val); laz[id] = max(laz[id], val); return; } lazy(id); int mid = (l + r) >> 1; update(id << 1, l, mid, L, R, val); update(id << 1 | 1, mid + 1, r, L, R, val); arr[id] = max(arr[id << 1], arr[id << 1 | 1]); } int get(int id, int l, int r, int L, int R){ //cout << id << " " << l << " " << r << " " << arr[id] << "\n"; if(l > R || r < L) return -oo; if(l >= L && r <= R){ return arr[id]; } lazy(id); int mid = (l + r) >> 1; return max(get(id << 1, l, mid, L, R), get(id << 1 | 1, mid + 1, r, L, R)); } }; void input(){ cin >> k >> m >> d >> aa >> n; for(int i = 1; i <= n; i++){ cin >> a[i] >> b[i]; } } void process(){ remainders.insert(k % d); remainders.insert(m % d); for(int i = 1; i <= n; i++) remainders.insert(a[i] % d); int cnt = 0; for(auto it : remainders){ cnt++; uomp[it] = cnt; } for(int i = 1; i <= n + 1; i++) dp[i] = -oo; it tmp(cnt); a[n + 1] = m; tmp.update(1, 1, cnt, uomp[k % d], uomp[k % d], -((k / d) * aa)); for(int i = 1; i <= n + 1; i++){ int x = tmp.get(1, 1, cnt, 1, uomp[a[i] % d] - 1); int y = tmp.get(1, 1, cnt, uomp[a[i] % d], cnt); // cout << x << " " << y << "\n"; dp[i] = max(x - aa, y); //dp[i] += (a[i] / d) * aa; dp[i] -= (a[i] / d) * aa; dp[i] += b[i]; //cout << dp[i] << "\n"; tmp.update(1, 1, cnt, uomp[a[i] % d], uomp[a[i] % d], dp[i] + (a[i] / d) * aa); } } void output(){ cout << dp[n + 1]; } signed main(){ ios_base::sync_with_stdio(0); input(); process(); output(); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 620 KB | Output is correct |
2 | Correct | 2 ms | 620 KB | Output is correct |
3 | Incorrect | 2 ms | 492 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 54 ms | 3692 KB | Output is correct |
2 | Correct | 51 ms | 3692 KB | Output is correct |
3 | Incorrect | 22 ms | 2796 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 158 ms | 13712 KB | Output is correct |
2 | Correct | 202 ms | 18064 KB | Output is correct |
3 | Correct | 186 ms | 18704 KB | Output is correct |
4 | Correct | 161 ms | 18764 KB | Output is correct |
5 | Incorrect | 116 ms | 11512 KB | Output isn't correct |
6 | Halted | 0 ms | 0 KB | - |