QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#414922 | #8718. 保区间最小值一次回归问题 | bulijiojiodibuliduo# | WA | 673ms | 76536kb | C++17 | 2.3kb | 2024-05-20 02:38:10 | 2024-05-20 02:38:12 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef basic_string<int> BI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head
const int N=501000;
int n,m,a[N],pl[N];
ll wt[N],dp[N];
array<int,3> op[N];
vector<PII> seg[N];
VI num[N];
void solve() {
scanf("%d%d",&n,&m);
set<int> po;
rep(i,1,n+1) {
scanf("%d",&a[i]);
po.insert(i);
}
VI val;
val.pb(0);
rep(i,0,m) {
int l,r,v;
scanf("%d%d%d",&l,&r,&v);
op[i]={l,r,v};
val.pb(v);
}
sort(all(val)); val.erase(unique(all(val)),val.end());
int s=SZ(val);
rep(i,1,s) seg[i].clear(),num[i].clear();
rep(i,0,m) {
auto [l,r,v]=op[i];
v=lower_bound(all(val),v)-val.begin();
seg[v].pb(mp(l,r));
}
per(i,1,s) {
for (auto [l,r]:seg[i]) {
while (1) {
auto it=po.lower_bound(l);
if (it!=po.end()&&*it<=r) {
num[i].pb(*it);
po.erase(it);
} else {
break;
}
}
}
}
ll ans=0;
rep(i,1,s) {
int z=0;
for (int x:num[i]) {
++z;
if (val[i]>a[x]) {
ans+=val[i]-a[x];
wt[z]=0;
} else {
wt[z]=a[x]-val[i];
}
}
wt[z+1]=0;
for (auto &[l,r]:seg[i]) {
l=lower_bound(all(num[i]),l)-num[i].begin()+1;
r=upper_bound(all(num[i]),r)-num[i].begin();
if (l>r) {
puts("-1");
return;
}
}
rep(i,1,z+1) pl[i]=0;
for (auto [l,r]:seg[i]) pl[r]=max(pl[r],l);
int op=0;
set<pair<ll,int>> ts;
ts.insert(mp(0,0));
rep(i,1,z+2) {
op=max(op,pl[i-1]);
while (!ts.empty()&&ts.begin()->se<op) ts.erase(ts.begin());
assert(!ts.empty());
dp[i]=ts.begin()->fi+wt[i];
ts.insert(mp(dp[i],i));
}
ans+=dp[z+1];
}
printf("%lld\n",ans);
}
int _;
int main() {
for (scanf("%d",&_);_;_--) {
solve();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 3ms
memory: 36568kb
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: 673ms
memory: 76536kb
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 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...
result:
wrong answer 1st numbers differ - expected: '49', found: '-1'