QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#19314 | #1877. Matryoshka Dolls | wyzwyz | Compile Error | / | / | C++14 | 2.3kb | 2022-01-29 01:00:46 | 2022-05-18 04:06:33 |
Judging History
你现在查看的是最新测评结果
- [2023-08-10 23:21:45]
- System Update: QOJ starts to keep a history of the judgings of all the submissions.
- [2022-05-18 04:06:33]
- 评测
- 测评结果:Compile Error
- 用时:0ms
- 内存:0kb
- [2022-01-29 01:00:46]
- 提交
answer
#include<cstdio>
#include<cctype>
#include<set>
#include<cmath>
#include<algorithm>
#define maxn 505505
template<class T>
inline T read(){
T r=0,f=0;
char c;
while(!isdigit(c=getchar()))f|=(c=='-');
while(isdigit(c))r=(r<<1)+(r<<3)+(c^48),c=getchar();
return f?-r:r;
}
template<class T>
inline T abs(T a){
return a<0?-a:a;
}
template<class T>
inline T max(T a,T b){
return a>b?a:b;
}
int n,m,a[maxn],num[maxn],pos[maxn];
struct Q{
int l,r,num;
bool operator <(const Q &q) const{
return pos[l]^pos[q.l]?l<q.l:r>q.r;
}
}q[maxn];
int id[maxn],lst[maxn],nxt[maxn],pre[maxn],suf[maxn];
long long Sum,sum,ans[maxn];
inline bool cmp(int x,int y){
return a[x]<a[y];
}
int top,sta[maxn][3];
inline void Del(int x){
int Pre=lst[x],Suf=nxt[x];
if(Pre&&Suf)Sum+=abs(Pre-Suf);
if(Pre)Sum-=abs(x-Pre);
if(Suf)Sum-=abs(x-Suf);
nxt[Pre]=Suf,lst[Suf]=Pre;
}
int main(){
n=read<int>();
m=read<int>();
for(int i=1;i<=n;i++)
a[i]=read<int>(),num[a[i]]=i;
int B=max((int)(n/sqrt(2m))-20,1);
for(int i=1;i<=n;i++)
pos[i]=(i-1)/B+1,id[i]=i;
for(int i=1;i<=m;i++){
q[i].l=read<int>();
q[i].r=read<int>();
q[i].num=i;
}
std::sort(q+1,q+1+m);
std::sort(id+1,id+1+n,cmp);
for(int i=1;i<=n;i++){
lst[id[i]]=id[i-1];
nxt[id[i-1]]=id[i];
sum+=abs(id[i]-id[i+1]);
}
sum-=id[n],Sum=sum;
for(int i=1,j=1;j<=pos[n];j++){
if(pos[q[i].l]==j){
sum=Sum;
int L=(j-1)*B+1,l=L,r=n;
for(int k=l;k<=n;k++)
pre[k]=lst[k],suf[k]=nxt[k];
for(;pos[q[i].l]==j;i++){
while(r>q[i].r){
int Pre=pre[r],Suf=suf[r];
sum+=Pre&&Suf?abs(Pre-Suf):0;
sum-=Pre?abs(Pre-r):0;
sum-=Suf?abs(Suf-r):0;
suf[Pre]=Suf,pre[Suf]=Pre;
r--;
}
long long lstsum=sum;
top=0;
while(l<q[i].l){
int Pre=pre[l],Suf=suf[l];
sum+=Pre&&Suf?abs(Pre-Suf):0;
sum-=Pre?abs(Pre-l):0;
sum-=Suf?abs(Suf-l):0;
suf[Pre]=Suf,pre[Suf]=Pre;
top++,sta[top][1]=l++;
sta[top][0]=Pre;
sta[top][2]=Suf;
}
ans[q[i].num]=sum;
sum=lstsum,l=L;
while(top){
int Pre=sta[top][0];
int x=sta[top][1];
int Suf=sta[top][2];
suf[Pre]=x,pre[Suf]=x;
top--;
}
}
}
for(int k=(j-1)*B+1;k<=j*B;k++)Del(k);
}
for(int i=1;i<=m;i++)
printf("%lld\n",ans[i]);
return 0;
}
详细
answer.code: In function ‘int main()’: answer.code:63:32: error: unable to find numeric literal operator ‘operator""m’ 63 | int B=max((int)(n/sqrt(2m))-20,1); | ^~ answer.code:63:32: note: use ‘-fext-numeric-literals’ to enable more built-in suffixes