QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#671248 | #7078. Tower of the Sorcerer | Soestx | RE | 0ms | 21712kb | C++23 | 2.1kb | 2024-10-24 11:57:57 | 2024-10-24 11:57:58 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pll pair<int,int>
#define fi first
#define se second
#define lowbit(x) (x&(-x))
typedef long long LL;
typedef unsigned long long ull;
int n,m,k;
int res;
const int N=1e6+10,M=1e5,mod=998244353;
const double eps=1e-6,inf=1e8;
int bit[N],dap[N];
int sum[N];
int dp[N];
struct stu
{
int hp,ad;
bool operator<(const stu &B) const
{
if(ad==B.ad) return hp<B.hp;
else return ad<B.ad;
}
}st[N];
void modify(int id,int x)
{
if(bit[id]<x) return;
bit[id]=dap[id]=x;
while(id<=M)
{
bit[id]=x;
for(int i=1;i<lowbit(id);i<<=1)
{
bit[id]=min(bit[id],bit[id-1]);
}
id+=lowbit(id);
}
}
int quer(int l,int r)
{
int res=dap[r];
while(l<=r)
{
int lr=r-(r&-r)+1;
if(lr>=l) res=min(res,bit[r]),r=lr-1;
else res=min(res,dap[r]),r--;
}
return res;
}
int qes(int id)
{
//cout<<id<<"---------------------------"<<endl;
int ma=1e18;
for(int i=m;i<st[id].ad;i++)
{
int t=st[id].hp/i;
int j=st[id].hp/t;
j=max(j,st[i].ad-1);
if(i!=j&&st[id].hp%j==0) j--;
else if(i==j&&st[id].hp%i==0) t--;
//cout<<i<<" "<<j<<" "<<quer(i,j)<<" "<<t<<" "<<quer(i,j)+t*st[id].ad<<endl;
if(ma>quer(i,j)+t*st[id].ad)
{
ma=quer(i,j)+t*st[id].ad;
}
}
return ma+sum[id-1];
}
void solve() {
memset(bit,0x3f,sizeof bit);
memset(dap,0x3f,sizeof dap);
cin>>n>>m;
for(int i=1;i<=n;i++) cin>>st[i].ad>>st[i].hp;
sort(st+1,st+1+n);
//for(int i=1;i<=n;i++) cout<<"---"<<st[i].ad<<" "<<st[i].hp<<endl;
int mx=max(m,st[n].ad);
for(int i=1;i<=n;i++)
{
sum[i]=(st[i].hp/mx)*st[i].ad;
if(st[i].hp%mx==0) sum[i]-=st[i].ad;
sum[i]+=sum[i-1];
}
int fro=0;
while(fro<n&&st[fro].ad<=m) fro++;
modify(m,0);
for(int i=fro;i<=n;i++)
{
dp[i]=qes(i);
//cout<<i<<" "<<dp[i]<<"----"<<dp[i]-sum[i]<<endl;
modify(st[i].ad,dp[i]-sum[i]);
}
cout<<dp[n]<<endl;
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int T=1;
//cin>>T;
while(T--)
{
solve();
}
return 0;
}
/*
4 1
3 2
4 4
5 6
1 6
3 1
3 2
4 4
1 6
*/
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 21712kb
input:
4 1 3 2 4 4 5 6 1 6
output:
9
result:
ok single line: '9'
Test #2:
score: -100
Runtime Error
input:
5000 679 84191 46042 81916 66659 74636 72443 10252 57443 21838 54620 84896 58466 20832 29643 45949 20576 50399 51434 56472 90759 68909 94348 39459 1731 81207 17614 26465 11775 93861 24936 25017 64663 21042 37570 32903 68583 68840 58347 93849 10841 10190 77131 10595 1959 57163 59047 16066 89850 73741...