QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#732538 | #8951. 澡堂 | int_R | 0 | 135ms | 496028kb | C++23 | 3.1kb | 2024-11-10 15:03:47 | 2024-11-10 15:03:54 |
Judging History
answer
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<math.h>
#define int long long
using namespace std;
const int MAXN=1e6+10;
const int INF=1e18;
int n,m,q,t[MAXN],top,s[MAXN];
int T;__int128 S,now,ans;
struct node
{
int I,n;vector <int> t,f[20];
vector <int> w,h[20],g[20];
inline int Q(int l,int r)
{
int t=__lg(r-l+1);
return max(h[t][r],h[t][l+(1<<t)-1]);
}
inline void calc(int l,int r,int del=0)
{
l=ceil((l-I)*1.0/m),r=floor((r-I)*1.0/m);
if(l>r||l>=t.size()||r<0||!n) return ;del=-del*T;
if(Q(l,r)+del<=now){ans+=(r-l+1)*now;return ;}
int L=l,R=r;while(L<R)
{int m=(L+R)>>1;(Q(l,m)+del>now)?R=m:L=m+1;}
ans+=(L-l)*now;int tmp=L;
for(int i=__lg(n);~i;--i)
if(f[i][L]&&f[i][L]<=r) ans+=g[i][L],L=f[i][L];
ans+=(L-tmp)*del;
now=w[L]+del,ans+=(r-L+1)*now;return ;
}
inline void init()
{
n=t.size(),top=0,w.resize(n);
for(int i=0;i<=__lg(n);++i)
f[i].resize(n),g[i].resize(n),h[i].resize(n);
for(int i=0;i<n;++i)
{
S+=(h[0][i]=w[i]=t[i]-i*T);
for(int j=1;j<=__lg(i+1);++j)
h[j][i]=max(h[j-1][i],h[j-1][i-(1<<j-1)]);
}
for(int i=n-1;~i;--i)
{
while(top&&w[s[top]]<=w[i]) --top;
g[0][i]=w[i]*((f[0][i]=s[top])-i),s[++top]=i;
for(int j=1;f[j-1][i];++j)
f[j][i]=f[j-1][f[j-1][i]],
g[j][i]=g[j-1][i]+g[j-1][f[j-1][i]];
}
}
}o[5];
inline void calc(int num)
{if(num>now) now=num;ans+=now;}
inline void write(__int128 num)
{
if(!num) return ;write(num/10);
cout<<(int)(num%10);return ;
}
signed main()
{
#ifndef ONLINE_JUDGE
freopen("shuju.txt","r",stdin);
freopen("out.out","w",stdout);
#endif
cin.tie(0),cout.tie(0);
ios::sync_with_stdio(0);
cin>>n>>m>>q>>T;
for(int i=0;i<m;++i) o[i].I=i;
for(int i=0;i<n;++i)
cin>>t[i],o[i%m].t.push_back(t[i]);
for(int i=0;i<m;++i) o[i].init();
return 0;
for(int x,y;q;--q)
{
cin>>x>>y;--x,ans=0;
int k=upper_bound(t,t+n,y)-t;
if(x==k)
{
for(int i=0;i<m;++i)
{
now=-INF,o[i].calc(0,x-1);
if(x%m==i) calc(y-(x/m)*T);
o[i].calc(x+1,n-1);
}
}
else if(x<k)
{
for(int i=0;i<m;++i)
{
now=-INF,o[i].calc(0,x-1);
o[(i+1)%m].calc(x+1,k-1,-(i==m-1));
if((k-1)%m==i) calc(y-((k-1)/m)*T);
o[i].calc(k,n-1);
}
}
else
{
for(int i=0;i<m;++i)
{
now=-INF,o[i].calc(0,k-1);
if(k%m==i) calc(y-(k/m)*T);
o[(i+m-1)%m].calc(k,x-1,+(i==0));
o[i].calc(x+1,n-1);
}
}
write(ans-(S-t[x]+y)),cout<<'\n';
}
return 0;
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 5908kb
input:
1000 5 1000 1969617 59993 133807 154199 240894 438118 483699 540258 892751 922552 1049554 1092961 1153394 1287745 1315664 1372758 1550447 1634967 1817853 1825455 2023239 2064188 2117896 2250036 2453036 2492474 2794776 2917935 3047993 3153958 3163156 3237767 3443614 3664074 3716235 3801008 3822067 40...
output:
result:
wrong answer 1st lines differ - expected: '145473107761', found: ''
Subtask #2:
score: 0
Wrong Answer
Test #6:
score: 0
Wrong Answer
time: 135ms
memory: 496028kb
input:
1000000 1 100000 1165 83 197 266 277 299 529 538 601 629 760 792 1081 1208 1211 1387 1726 1873 1932 2198 2437 2448 2584 2715 2813 3113 3169 3207 3386 3934 4013 4032 4057 4137 4213 4396 4666 4754 4786 4856 4917 4966 5054 5124 5151 5196 5505 5548 5583 5730 5763 6031 6161 6169 6372 6446 6517 6712 6744 ...
output:
result:
wrong answer 1st lines differ - expected: '532526465394304', found: ''
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
0%
Subtask #5:
score: 0
Wrong Answer
Test #36:
score: 0
Wrong Answer
time: 135ms
memory: 450508kb
input:
1000000 5 100000 1887 112 168 223 393 535 558 577 631 631 678 682 1043 1099 1268 1337 1396 1437 1472 1510 1587 1804 1984 2013 2290 2294 2392 2474 2547 2694 2717 2742 2841 2880 2906 2985 3030 3047 3064 3108 3275 3375 3440 3451 3488 3950 3957 3963 4047 4086 4335 4378 4448 4490 4544 4622 4864 4875 4897...
output:
result:
wrong answer 1st lines differ - expected: '138785143191754', found: ''
Subtask #6:
score: 0
Skipped
Dependency #3:
0%