QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#431544#8718. 保区间最小值一次回归问题A_zjzjWA 464ms27164kbC++142.2kb2024-06-05 18:16:402024-06-05 18:16:41

Judging History

你现在查看的是最新测评结果

  • [2024-06-05 18:16:41]
  • 评测
  • 测评结果:WA
  • 用时:464ms
  • 内存:27164kb
  • [2024-06-05 18:16:40]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#include"debug.h"
#else
#define debug(...) void()
#endif
#define all(x) (x).begin(),(x).end()
template<class T>
auto ary(T *a,int l,int r){
	return vector<T>{a+l,a+1+r};
}
using ll=long long;
using ull=unsigned ll;
const int N=5e5+10;
int T,n,m,a[N],lim[N];
struct opts{
	int l,r,v;
}o[N];
namespace SGT1{
	int t[N<<2];
	void build(int l=1,int r=n,int rt=1){
		t[rt]=1;
		if(l==r)return;
		int mid=(l+r)>>1;
		build(l,mid,rt<<1);
		build(mid+1,r,rt<<1|1);
	}
	void update(int L,int R,int x,int l=1,int r=n,int rt=1){
		if(L<=l&&r<=R)return t[rt]=max(t[rt],x),void();
		int mid=(l+r)>>1;
		if(L<=mid)update(L,R,x,l,mid,rt<<1);
		if(mid<R)update(L,R,x,mid+1,r,rt<<1|1);
	}
	void push(int l=1,int r=n,int rt=1,int x=1){
		x=max(x,t[rt]);
		if(l==r)return lim[l]=x,void();
		int mid=(l+r)>>1;
		push(l,mid,rt<<1,x);
		push(mid+1,r,rt<<1|1,x);
	}
}
namespace SGT2{
	bool cmp(int x,int y){
		return lim[x]^lim[y]?lim[x]<lim[y]:a[x]<a[y];
	}
	int t[N<<2];
	void pushup(int rt){
		t[rt]=min(t[rt<<1],t[rt<<1|1],cmp);
	}
	void build(int l=1,int r=n,int rt=1){
		if(l==r)return t[rt]=l,void();
		int mid=(l+r)>>1;
		build(l,mid,rt<<1);
		build(mid+1,r,rt<<1|1);
		pushup(rt);
	}
	int query(int L,int R,int l=1,int r=n,int rt=1){
		if(L<=l&&r<=R)return t[rt];
		int mid=(l+r)>>1;
		if(R<=mid)return query(L,R,l,mid,rt<<1);
		if(mid<L)return query(L,R,mid+1,r,rt<<1|1);
		return min(query(L,R,l,mid,rt<<1),query(L,R,mid+1,r,rt<<1|1),cmp);
	}
}
int b[N];
void get(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	SGT1::build();
	for(int i=1;i<=m;i++){
		scanf("%d%d%d",&o[i].l,&o[i].r,&o[i].v);
		SGT1::update(o[i].l,o[i].r,o[i].v);
	}
	SGT1::push();
	SGT2::build();
	fill(b+1,b+1+n,0);
	for(int i=1;i<=m;i++){
		int cur=SGT2::query(o[i].l,o[i].r);
		if(lim[cur]!=o[i].v)return puts("-1"),void();
		b[cur]=o[i].v;
	}
	ll ans=0;
	for(int i=1;i<=m;i++){
		if(!b[i]){
			if(a[i]<lim[i])ans+=lim[i]-a[i];
		}else ans+=abs(a[i]-b[i]);
	}
	printf("%lld\n",ans);
}
int main(){
	for(scanf("%d",&T);T--;)get();
	return 0;
}
#ifdef DEBUG
#include"debug.hpp"
#endif

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 14096kb

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: 464ms
memory: 27164kb

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:

49
46
43
39
48
47
50
46
46
48
48
56
917
53
50
55
46
62
57
46
49
51
43
56
51
57
50
41
42
44
41
53
57
45
59
45
49
44
37
48
43
52
46
50
910
910
43
50
50
50
38
43
54
53
42
46
56
52
51
48
38
48
43
41
55
41
48
47
32
51
54
46
44
47
46
45
43
48
42
45
47
32
42
45
53
46
48
41
42
45
48
40
49
54
44
43
46
50
49
...

result:

wrong answer 7th numbers differ - expected: '49', found: '50'