QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#337916 | #4077. 뚫기 | hotboy2703 | 0 | 82ms | 14036kb | C++14 | 4.6kb | 2024-02-25 16:02:55 | 2024-02-25 16:02:55 |
Judging History
answer
#include "breakthru.h"
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define pll pair <ll,ll>
#define fi first
#define se second
#define sz(a) (ll((a).size()))
#define BIT(mask,i) (((mask) >> (i))&1LL)
#define MASK(i) (1LL << (i))
#define MP make_pair
namespace{
const ll MAXN=1e4;
ll n,m;
pll a[MAXN+100];
ll eval(pll times,ll costX,ll costY){
return times.fi*costX+times.se*costY;
}
namespace seg{
const ll SZ = (MAXN*2+1)*4;
const ll INF=1e9;
ll A,B;
pll tree[SZ+100];
pair <pll,ll> lazy[SZ+100];
pair <pll,ll> default_lazy;
vector <ll> val;
void init_value(){
val.push_back(0);
for (ll i=1;i<=n;i++){
if (a[i].fi>0)val.push_back(a[i].fi-1);
if (a[i].se+1<m)val.push_back(a[i].se+1);
}
sort(val.begin(),val.end());
val.resize(unique(val.begin(),val.end())-val.begin());
}
void build(ll id,ll l,ll r){
tree[id] = MP(0,0);
lazy[id] = default_lazy;
if (l != r){
ll mid = (l + r) >> 1;
build(id<<1,l,mid);
build(id<<1|1,mid+1,r);
}
}
void reset(ll AA,ll BB){
A=AA,B=BB;
default_lazy = MP(MP(n,n),0);
build(1,0,sz(val)-1);
}
pll better(pll x,pll y){
if (eval(x,A,B) < eval(y,A,B))return x;
else return y;
}
void push_minimize(ll id,pll min1){
lazy[id].fi = better(lazy[id].fi,min1);
tree[id] = better(tree[id],min1);
}
void push_add(ll id,ll val){
lazy[id].se += val;
tree[id].se += val;
}
void push_all(ll id,pair <pll,ll> val){
push_add(id,val.se);
push_minimize(id,val.fi);
}
void lz(ll id){
if (lazy[id] != default_lazy){
push_all(id<<1,lazy[id]);
push_all(id<<1|1,lazy[id]);
lazy[id] = default_lazy;
}
}
void reupdate(ll id){
tree[id] = better(tree[id<<1],tree[id<<1|1]);
}
void update_add(ll id,ll l,ll r,ll l1,ll r1){
if (val[l] > r1 || l1 > val[r] || l1 > r1)return;
if (l1 <= val[l] && val[r] <= r1){
// cout<<"SUS "<<l<<' '<<r<<' '<<val[l]<<' '<<val[r]<<endl;
// cout<<"BEFORE "<<tree[id].fi<<' '<<tree[id].se<<endl;
push_add(id,1);
// cout<<"AFTER "<<tree[id].fi<<' '<<tree[id].se<<endl;
return;
}
lz(id);
ll mid = (l + r) >> 1;
update_add(id<<1,l,mid,l1,r1);
update_add(id<<1|1,mid+1,r,l1,r1);
reupdate(id);
}
void add(ll l,ll r){
update_add(1,0,sz(val)-1,l,r);
}
pll best(){
return tree[1];
}
void minimize(){
pll tmp = best();
tmp.fi++;
lazy[1].fi = better(lazy[1].fi,tmp);
}
}
vector <pll> hull;
pll solve(ll A,ll B){
// cout<<A<<' '<<B<<endl;
seg::reset(A,B);
for (ll i = 0;i < n;i ++){
// cout<<i<<endl;
seg::add(a[i].fi,a[i].se);
seg::minimize();
// cout<<i<<' '<<seg::best().fi<<' '<<seg::best().se<<endl;
}
return seg::best();
}
void dnc(pll L,pll R){
// cout<<L.fi<<' '<<L.se<<' '<<R.fi<<' '<<R.se<<endl;
ll Ex = R.se-L.se,Ey = L.fi-R.fi;
hull.push_back(L);
pll mid = solve(Ex,Ey);
if (eval(mid,Ex,Ey)!=eval(L,Ex,Ey)){
dnc(L,mid);
hull.push_back(mid);
dnc(mid,R);
}
hull.push_back(R);
}
}
void init(int N, int M, std::vector<int> Y1, std::vector<int> Y2)
{
n=N;
m=M;
for (ll i = 0;i < n;i ++){
a[i] = MP(Y1[i],Y2[i]);
}
// cout<<"DNC START"<<endl;
seg::init_value();
dnc(solve(1,N),solve(N,1));
// cout<<"INIT SUCCEED"<<endl;
}
long long minimize(int X, int Y)
{
ll l=1;
ll r=sz(hull)-1;
ll ans = 0;
while (l<=r){
ll mid = (l + r) >> 1;
if (eval(hull[mid],X,Y) < eval(hull[mid-1],X,Y)){
ans = mid;
l = mid + 1;
}
else{
r = mid - 1;
}
}
return eval(hull[ans],X,Y);
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 7
Accepted
time: 1ms
memory: 5584kb
input:
6 2 1 1 1 0 1 0 0 0 1 1 1 0 1 724642704 32998300
output:
131993200
result:
ok single line: '131993200'
Test #2:
score: -7
Wrong Answer
time: 1ms
memory: 5524kb
input:
10 3 1 1 2 1 2 0 2 1 2 2 2 0 2 1 1 0 2 0 1 1 2 686137157 255736273
output:
2058411471
result:
wrong answer 1st lines differ - expected: '1022945092', found: '2058411471'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Wrong Answer
Test #60:
score: 0
Wrong Answer
time: 82ms
memory: 14036kb
input:
500 10 1000000 2 9 2 7 3 6 1 6 3 5 0 5 3 4 6 8 4 8 1 6 1 5 6 7 7 7 6 9 0 7 4 5 0 6 0 2 4 6 0 6 1 7 2 8 0 9 0 9 0 9 0 7 3 6 8 8 2 4 4 4 0 5 2 5 1 6 0 9 2 7 0 8 9 9 1 4 0 9 2 4 1 9 2 8 2 6 0 4 5 9 4 5 3 9 2 6 1 9 0 6 6 8 2 9 4 9 7 9 2 7 1 5 1 8 0 6 0 9 2 9 3 9 0 2 4 4 5 9 4 7 8 9 4 9 1 8 3 8 2 9 6 6 3...
output:
28299860640 28868000000 610997792 4735705760 9679066496 11459054176 15716093088 22761646336 479907904 22094384032 932890272 2673337152 22346097248 6816985408 8029448160 14516961952 13256811232 22751843360 29723724352 30864665952 6942219872 30490740448 15527957792 15426623936 6412112416 2850351616 93...
result:
wrong answer 1st lines differ - expected: '109125435050', found: '28299860640'
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Skipped
Dependency #1:
0%