QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#731822 | #8951. 澡堂 | int_R | 0 | 294ms | 512916kb | C++14 | 3.0kb | 2024-11-10 11:35:15 | 2024-11-10 11:35:15 |
Judging History
answer
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<vector>
#define ll long long
using namespace std;
const int MAXN=1e6+10;
const ll INF=1e18;
int n,m,q,t[MAXN],top,s[MAXN];
ll T;__int128 S,now,ans;
struct node
{
int I,n;vector <int> t,f[20];
vector <ll> w,h[20];vector <__int128> g[20];
inline ll 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=(l-I)/m+((l-I)%m!=0),r=(r-I)/m;
if(l>r) 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(ll 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();
for(int x,y;q;--q)
{
cin>>x>>y;--x,ans=0;
int k=upper_bound(t,t+n,y)-t-1;
if(x==k)
{
for(int i=0;i<m;++i)
{
now=-INF,o[i].calc(0,x-1);
if(x%m==i) calc(y-1ll*(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,-1);
if((k-1)%m==i) calc(y-1ll*((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-1ll*(k/m)*T);
o[(i+m-1)%m].calc(k,x-1,+1);
o[i].calc(x+1,n-1);
}
}
write(ans-(S-t[x]+y)),cout<<'\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 5900kb
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:
144389506914 144316774580 144320117758 144361337807 144355307613 144353348038 144321611979 144370520087 144377063413 144374874567 144349790793 144376222537 144318072013 144277478292 144403028642 144368167333 144342577109 144285276200 144300883513 144308772568 144431158915 144353733430 144387542963 1...
result:
wrong answer 1st lines differ - expected: '145473107761', found: '144389506914'
Subtask #2:
score: 0
Memory Limit Exceeded
Test #6:
score: 0
Memory Limit Exceeded
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:
532526465394304 532526382684731 532526432382169 532526335149396 532526336776485 532526441654485 532526419072018 532526448365904 532526461590885 532526446716107 532526451559614 532526448428416 532526467783803 532526436578785 532526455446447 532526418608776 532526437618228 532526421765463 532526361938...
result:
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: 294ms
memory: 512916kb
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:
138783873196785 138783888417540 138783955288683 138783834805955 138783848981991 138783842939772 138783789843353 138783814957779 138783859262009 138783802297397 138783820489937 138783904312477 138783934551912 138783919050582 138783861289086 138783860784186 138783834460040 138783893781295 138783857159...
result:
wrong answer 1st lines differ - expected: '138785143191754', found: '138783873196785'
Subtask #6:
score: 0
Skipped
Dependency #3:
0%