QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#437805 | #8718. 保区间最小值一次回归问题 | 233L | WA | 410ms | 32680kb | C++14 | 2.5kb | 2024-06-09 17:53:25 | 2024-06-09 17:53:26 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define uint unsigned int
#define ldb long double
#define pii pair<int,int>
#define mkp make_pair
#define mkt make_tuple
#define fr first
#define se second
#define uset unordered_set
#define umap unordered_map
#define pqueue priority_queue
#define all(_box) _box.begin(),_box.end()
#define ppc __builtin_popcount
#define ctz __builtin_ctz
#define clz __builtin_clz
#define lbd lower_bound
#define ubd upper_bound
#define deb(x) cerr<<#x<<'='<<(x)<<' '
using namespace std;
const int N=5e5+4;
int n,m;
int a[N],b[N];
struct node{
int l,r,x;
}c[N];
int mx[N];
ll f[N];
namespace MFS{
int fa[N];
void init(){
iota(fa+1,fa+n+2,1);
}
int find(int u){
return u==fa[u]?u:fa[u]=find(fa[u]);
}
void merge(int u,int v){
fa[find(v)]=find(u);
}
}
using MFS::find;
using MFS::merge;
bool solve(){
cin>>n>>m;
MFS::init();
fill(b+1,b+n+1,0);
for(int i=1;i<=n;i++)cin>>a[i];
map<int,vector<pii>>qy;
for(int i=1;i<=m;i++){
cin>>c[i].l>>c[i].r>>c[i].x;
qy[c[i].x].push_back({c[i].l,c[i].r});
}
sort(c+1,c+m+1,[](const node &u,const node &v){
return u.x<v.x;
});
ll ans=0;
map<int,vector<int>>pos;
for(int i=m;i>=1;i--)
for(int j=c[i].l;(j=find(j))<=c[i].r;j++){
pos[b[j]=c[i].x].push_back(j),merge(j+1,j);
if(a[j]<b[j])ans+=b[j]-a[j],a[j]=b[j];
}
for(const auto &i:qy)
if(pos[i.fr].empty())return 0;
for(const auto &i:pos){
auto &arr=i.se;
int len=arr.size();
fill(mx+1,mx+len+1,0);
for(const auto &j:qy[i.fr]){
int l=lbd(all(arr),j.fr)-arr.begin()+1;
int r=lbd(all(arr),j.se)-arr.begin()+1;
mx[r]=max(mx[r],l);
}
deque<int>q({0});
for(int j=1;j<=len;j++){
mx[j]=max(mx[j],mx[j-1]);
while(!q.empty()&&q.front()<mx[j-1])q.pop_front();
if(q.empty())return 0;
int pos=arr[q.front()];
f[j]=f[q.front()]+a[pos]-b[pos];
while(!q.empty()&&f[j]<f[q.back()])q.pop_back();
q.push_back(j);
}
ans+=*min_element(f+mx[len],f+len+1);
}
cout<<ans<<'\n';
return 1;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
int T;
cin>>T;
while(T--){
if(solve());
else cout<<-1<<'\n';
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 11744kb
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: 410ms
memory: 32680kb
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:
51 44 37 42 45 42 45 48 50 46 45 57 823 53 51 54 42 62 53 45 45 49 42 52 51 59 50 46 39 44 40 50 56 47 57 49 43 42 35 43 42 49 45 45 701 810 46 48 46 50 47 42 50 46 44 42 54 54 51 47 37 49 42 41 55 40 45 45 36 54 45 49 44 47 42 46 39 44 39 44 49 34 46 43 52 48 47 43 39 44 43 38 47 53 44 41 45 43 46 ...
result:
wrong answer 1st numbers differ - expected: '49', found: '51'