QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#672368 | #1132. Financial Report | Wansur# | 0 | 137ms | 47496kb | C++23 | 3.1kb | 2024-10-24 16:37:21 | 2024-10-24 16:37:21 |
Judging History
answer
#include <bits/stdc++.h>
#define ent '\n'
#define int long long
using namespace std;
typedef long long ll;
const int maxn = 1e6 + 12;
const int mod = 998244353;
vector<int> g[maxn];
int t[maxn * 4];
int R[maxn];
int dp[maxn];
int a[maxn];
int n, m, k;
void upd(int v, int tl, int tr, int pos, int x) {
if(tl == tr) {
t[v] = x;
return;
}
int mid = tl + tr >> 1;
if(pos <= mid) {
upd(v * 2, tl, mid, pos, x);
}
else {
upd(v * 2 + 1, mid + 1, tr, pos, x);
}
t[v] = max(t[v * 2], t[v * 2 + 1]);
}
int get(int v, int tl, int tr, int l, int r) {
if(tl > r || l > tr) return 0;
if(tl >= l && tr <= r) return t[v];
int mid = tl + tr >> 1;
return max(get(v * 2, tl, mid, l, r), get(v * 2 + 1, mid + 1, tr, l, r));
}
void solve() {
cin >> n >> k;
vector<int> ord;
for(int i = 1; i <= n; i++) {
cin >> a[i];
ord.push_back(a[i]);
}
sort(ord.begin(), ord.end());
ord.resize(unique(ord.begin(), ord.end()) - ord.begin());
vector<int> p;
for(int i = 1; i <= n; i++) {
p.push_back(i);
a[i] = lower_bound(ord.begin(), ord.end(), a[i]) - ord.begin() + 1;
}
sort(p.begin(), p.end(), [](int i, int j) {
if(a[i] == a[j]) return i < j;
return a[i] < a[j];
});
set<pair<int, int>> s, bg;
s.insert({n, 1});
bg.insert({n, 1});
auto add = [&](int l, int r) -> void {
s.insert({r, l});
if(r - l + 1 >= k) {
bg.insert({r, l});
}
};
auto update = [&](int x) -> void {
auto [r, l] = *s.lower_bound({x, 0});
s.erase({r, l});
bg.erase({r, l});
if(x < r) {
add(x + 1, r);
}
if(x > l) {
add(l, x - 1);
}
};
for(int i : p) {
update(i);
auto it = bg.lower_bound({i, 0});
if(it == bg.end()) {
R[i] = n + 1;
}
else {
R[i] = it -> second + k - 1;
}
auto nxt = s.lower_bound({i, 0});
if(nxt != s.end()) {
g[nxt -> second].push_back(i);
}
}
vector<int> v;
int ans = 0;
for(int i = n; i; i--) {
dp[i] = max(dp[i], 1ll);
ans = max(ans, dp[i]);
while(v.size() && a[v.back()] >= a[i]) {
upd(1, 1, n, v.back(), 0);
v.pop_back();
}
upd(1, 1, n, i, dp[i]);
v.push_back(i);
for(int j : g[i]) {
int pos = v.size() - 1;
for(int l = 0, r = v.size() - 1; l <= r;) {
int mid = l + r >> 1;
if(a[v[mid]] > a[j] && v[mid] <= R[j]) {
pos = mid;
r = mid - 1;
}
else l = mid + 1;
}
dp[j] = get(1, 1, n, i, v[pos]) + 1;
}
}
cout << ans << '\n';
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
// cin >> t;
while(t--) {
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 14
Accepted
time: 0ms
memory: 7616kb
input:
1 1 314159265
output:
1
result:
ok single line: '1'
Test #2:
score: 14
Accepted
time: 2ms
memory: 7900kb
input:
1 1 0
output:
1
result:
ok single line: '1'
Test #3:
score: 14
Accepted
time: 0ms
memory: 7700kb
input:
1 1 1000000000
output:
1
result:
ok single line: '1'
Test #4:
score: 0
Wrong Answer
time: 2ms
memory: 7732kb
input:
2 1 299792458 299792458
output:
2
result:
wrong answer 1st lines differ - expected: '1', found: '2'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Wrong Answer
Test #62:
score: 0
Wrong Answer
time: 134ms
memory: 47496kb
input:
300000 1 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 2...
output:
300000
result:
wrong answer 1st lines differ - expected: '1', found: '300000'
Subtask #5:
score: 0
Wrong Answer
Test #76:
score: 0
Wrong Answer
time: 137ms
memory: 46184kb
input:
300000 300000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 ...
output:
300000
result:
wrong answer 1st lines differ - expected: '1', found: '300000'
Subtask #6:
score: 0
Skipped
Dependency #1:
0%