QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#116922 | #149. Peru | Irisu# | 0 | 82ms | 43120kb | C++17 | 2.9kb | 2023-06-30 10:50:27 | 2024-09-10 16:36:02 |
Judging History
answer
#include "peru.h"
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a),i##end=(b);i<=i##end;++i)
#define per(i,a,b) for(int i=(a),i##end=(b);i>=i##end;--i)
mt19937 Rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
template<typename T>void chkmax(T&x,const T&y){if(x<y)x=y;}
template<typename T>void chkmin(T&x,const T&y){if(y<x)x=y;}
#define pb push_back
#define ALL(x) (x).begin(),(x).end()
#define mem(x) memset((x),0,sizeof(x))
typedef double db;
typedef long long ll;
typedef vector<int>vi;
typedef pair<int,int>pii;
typedef unsigned u32;
typedef unsigned uint;
typedef unsigned long long u64;
const int P=1e9+7;
const ll inf=1e18;
const int maxn=2.5e6+10;
int a[maxn];
ll dp[maxn];
struct node{
ll f;
int v,pos;
ll get()const{
return f+v;
}
bool operator<(const node&o)const{
return get()<o.get()||(get()==o.get()&&pos>o.pos);
}
};
struct zzh{
vector<node>lef,l_pre,rig,r_pre;
bool empty()const{
return lef.empty()&&rig.empty();
}
node front()const{
return lef.empty()?rig[0]:lef.back();
}
node back()const{
return rig.empty()?lef[0]:rig.back();
}
void push_front(node o){
lef.pb(o);
l_pre.pb(l_pre.empty()?o:min(l_pre.back(),o));
}
void push_back(node o){
rig.pb(o);
r_pre.pb(r_pre.empty()?o:min(r_pre.back(),o));
}
vector<node>buf;
void rebuild(){
int cnt=buf.size()/2;
rep(i,0,cnt-1){
lef.pb(buf[iend-i]);
l_pre.pb(i?min(l_pre.back(),buf[iend-i]):buf[iend-i]);
}
rep(i,cnt,buf.size()-1){
rig.pb(buf[i]);
r_pre.pb(i>cnt?min(r_pre.back(),buf[i]):buf[i]);
}
}
void pop_back(){
if(!rig.empty()){
rig.pop_back(),r_pre.pop_back();return;
}
buf.resize(lef.size()-1);
rep(i,0,lef.size()-2)buf[i]=lef[iend-i+1];
lef.clear(),l_pre.clear();
rebuild();
}
void pop_front(){
if(!lef.empty()){
lef.pop_back(),l_pre.pop_back();return;
}
buf.resize(rig.size()-1);
rep(i,0,rig.size()-2)buf[i]=rig[i+1];
rig.clear(),r_pre.clear();
rebuild();
}
ll ask()const{
return min(l_pre.empty()?inf:l_pre.back().get(),r_pre.empty()?inf:r_pre.back().get());
}
}q;
int solve(int n, int k, int* v){
rep(i,1,n)a[i]=v[i-1],dp[i]=inf;
rep(i,1,n){
ll ths=dp[i-1];
while(!q.empty()&&q.back().v<=a[i]){
chkmin(ths,q.back().f);
q.pop_back();
}
q.push_back({ths,a[i],i});
if(i-q.front().pos>=k){
q.pop_front();
}
node lst=q.front();
q.pop_front();
q.push_front({dp[i-k],lst.v,lst.pos});
dp[i]=q.ask();
// printf("%d : %lld\n",i,dp[i]);
// int mx=0;
// per(j,i-1,max(0,i-k)){
// chkmax(mx,a[j+1]);
// chkmin(dp[i],dp[j]+mx);
// }
}
int res=0;
rep(i,1,n)res=(23ll*res+dp[i])%P;
return res;
}
//#include"grader.cpp"
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 8044kb
input:
2000 170 1054018657 1037445664 1011691297 1009972317 1006506677 1002579733 999792775 999477541 975467893 970302369 968173111 957735623 953086083 938540451 932313113 930563895 924682633 917831575 913506401 908739591 905368525 899452913 894354220 890127447 885923007 583391543 880642788 878397752 87822...
output:
368567703
result:
wrong answer 1st lines differ - expected: '559335223', found: '368567703'
Subtask #2:
score: 0
Wrong Answer
Test #15:
score: 0
Wrong Answer
time: 8ms
memory: 16292kb
input:
400000 1000 1999989721 1999987224 1999984551 1999977673 1999977545 1999976801 1999975837 1999972607 1999956301 1999952801 1999942489 1999940593 1999940337 1999936353 1999936273 1999926073 1999925513 1999922980 1999918301 1999912501 1999909301 1999906125 1999902913 1999895622 1999893617 1999885490 19...
output:
391694705
result:
wrong answer 1st lines differ - expected: '677928817', found: '391694705'
Subtask #3:
score: 0
Wrong Answer
Test #34:
score: 0
Wrong Answer
time: 82ms
memory: 43120kb
input:
2500000 2000 1073315871 1073250349 1072791751 1072104046 1072071097 1071841833 1071809381 1071710686 1071580105 1071482003 1071383725 1071154701 1070499431 1070335288 1070334157 1069943617 1069681476 1069584279 1069581771 1069322519 1069189353 1069125955 1068832186 1068797487 1068662939 1068565681 1...
output:
967730475
result:
wrong answer 1st lines differ - expected: '12623259', found: '967730475'