# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
256815 | Bruteforceman | Arcade (NOI20_arcade) | C++11 | 1100 ms | 44580 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 10;
int dp[maxn];
int a[maxn], t[maxn];
map <int, int> cmp;
int bit[maxn];
int n, m;
struct node {
int idx;
int x, y;
node (int idx, int x, int y) : idx(idx), x(x), y(y) {}
node () {}
bool operator < (node p) const {
return x < p.x;
}
};
vector <node> v[maxn];
void update(int x, int val) {
for(int i = x; i <= m; i += i & (-i)) {
bit[i] = max(bit[i], val);
}
}
void remove(int x) {
for(int i = x; i <= m; i += i & (-i)) {
bit[i] = 0;
}
}
int query(int x) {
int ans = 0;
for(int i = x; i > 0; i -= i & (-i)) {
ans = max(ans, bit[i]);
}
return ans;
}
void solve(int l, int r) {
if(l == r) {
for(auto i : v[l]) dp[i.idx] = max(dp[i.idx], 1);
return ;
}
int mid = (l + r) >> 1;
solve(l, mid);
vector <node> left, right;
for(int i = l; i <= mid; i++) {
for(auto j : v[i]) left.push_back(j);
}
for(int i = mid + 1; i <= r; i++) {
for(auto j : v[i]) right.push_back(j);
}
sort(left.begin(), left.end());
sort(right.begin(), right.end());
int pt = 0;
for(auto i : right) {
while(pt < left.size() && left[pt].x < i.x) {
update(left[pt].y, dp[left[pt].idx]);
++pt;
}
dp[i.idx] = max(dp[i.idx], 1 + query(i.y - 1));
}
for(auto i : left) remove(i.y);
solve(mid + 1, r);
}
int main() {
scanf("%d %d", &n, &m);
for(int i = 0; i < m; i++) {
scanf("%d", &t[i]);
}
map <int, int> cmp, cmpY;
for(int i = 0; i < m; i++) {
scanf("%d", &a[i]);
cmp[a[i]];
cmpY[a[i] - t[i]];
}
int idx = 0;
for(auto &i : cmp) {
i.second = ++idx;
}
int idY = 0;
for(auto &i : cmpY) {
i.second = ++idY;
}
for(int i = 0; i < m; i++) {
v[cmp[a[i]]].emplace_back(i, a[i] + t[i], cmpY[a[i] - t[i]]);
}
solve(1, m);
printf("%d\n", *max_element(dp, dp + m));
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |