QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#454425 | #8718. 保区间最小值一次回归问题 | Andyqian7 | WA | 893ms | 23040kb | C++14 | 2.4kb | 2024-06-24 21:33:24 | 2024-06-24 21:33:24 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int, int>
const int MAX = 5e5 + 10;
int n, m, a[MAX], T, fa[MAX];
struct tup
{
int l, r, v;
friend bool operator<(const tup &a, const tup &b)
{
if (a.v != b.v)
return a.v > b.v;
return a.r < b.r;
}
} tu[MAX];
int Find(int x)
{
return x == fa[x] ? x : (fa[x] = Find(fa[x]));
}
signed main()
{
cin >> T;
while (T--)
{
cin >> n >> m;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
fa[i] = i;
}
for (int i = 1; i <= m; i++)
{
cin >> tu[i].l >> tu[i].r >> tu[i].v;
}
sort(tu + 1, tu + m + 1);
int sum = 0;
for (int l = 1, r = 1; l <= m; r = l = r + 1)
{
while (r <= m && tu[r].v == tu[l].v)
{
r++;
}
r--;
vector<int> v; // points to choose from
for (int i = l; i <= r; i++)
{
int x = Find(tu[i].r);
while (x >= tu[i].l)
{
if (a[x] < tu[r].v)
{
sum += tu[r].v - a[x];
a[x] = tu[r].v;
}
v.push_back(x);
fa[x] = x - 1;
x = Find(x);
}
}
deque<pii> Q;
int L = 0, R = 0;
auto j = v.begin();
for (int i = l; i <= r; i++)
{
L = max(L, tu[i].l);
while (Q.size() && Q.front().first < L)
{
Q.pop_front();
}
for (; j < v.end() && *j <= tu[i].r; j++)
{
while (Q.size() && Q.back().second > sum + a[*j] - tu[r].v)
{
Q.pop_back();
}
Q.push_back({*j, sum + a[*j] - tu[r].v});
}
if (Q.empty())
{
cout << "-1" << endl;
goto fail;
}
else
sum = Q.front().second;
R = tu[i].r;
}
}
cout << sum << endl;
fail:
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7680kb
input:
1 3 2 2023 40 41 1 1 2022 2 3 39
output:
2
result:
ok 1 number(s): "2"
Test #2:
score: -100
Wrong Answer
time: 893ms
memory: 23040kb
input:
1000 100 100 1 35141686 84105222 84105220 7273527 178494861 178494861 112519027 77833654 77833656 261586535 278472336 278472336 261586536 416361017 416361017 426649080 323519513 278472337 420127821 420127823 420127823 482516531 434108818 420127821 631535744 615930922 546346921 546346920 546346920 70...
output:
-1 46 43 -1 48 47 -1 46 46 -1 -1 56 -1 53 50 55 46 -1 57 46 49 -1 42 -1 51 57 50 43 41 -1 41 53 57 -1 -1 45 48 44 37 48 43 52 -1 50 -1 -1 48 50 50 -1 45 42 54 -1 42 46 55 52 51 48 38 48 -1 41 55 41 -1 47 38 51 -1 -1 -1 47 46 -1 43 48 42 45 47 36 43 45 53 46 48 45 42 -1 48 -1 49 54 44 43 -1 48 -1 43 ...
result:
wrong answer 1st numbers differ - expected: '49', found: '-1'