QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#554507 | #8218. 水镜 | 275307894a | 0 | 1ms | 10196kb | C++14 | 2.0kb | 2024-09-09 11:38:06 | 2024-09-09 11:38:07 |
Judging History
answer
#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define eb emplace_back
#define all(x) x.begin(),x.end()
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;
const int N=1e6+5,M=N*60+5,K=1e7+5,mod=998244353,Mod=mod-1;const db eps=1e-9;const ll INF=1e13+7;mt19937 rnd(263082);
#define Tp template<typename T>
#define Ts template<typename T,typename... Ar>
namespace Debug{
Tp void _debug(char* f,T t){cerr<<f<<'='<<t<<endl;}
Ts void _debug(char* f,T x,Ar... y){while(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);}
#ifdef LOCAL
#define gdb(...) _debug((char*)#__VA_ARGS__,__VA_ARGS__)
#else
#define gdb(...) void()
#endif
}using namespace Debug;
int n;ll A[N];
ll ans=0;
ll L[N],R[N],ns[N],nh;
namespace Tree{
int A[N];
void add(int x,int y,int w){
for(int i=x;i<=y;i++) A[i]+=w;
}
int qry(){
int ans=n;
for(int i=1;i<nh;i++) ans=min(ans,A[i]);
return ans;
}
}
void add(int x,int w){
Tree::add(L[x],R[x],w);
}
void Solve(){
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%lld",&A[i]),A[i]*=2;
ns[++nh]=-INF;ns[++nh]=INF+1;
for(int i=2;i<n;i++){
L[i]=-INF;R[i]=INF;
for(int o:{i-1,i+1}){
if(A[o]<A[i]) R[i]=min(R[i],A[o]+A[i]>>1);
if(A[o]>A[i]) L[i]=max(L[i],A[o]+A[i]>>1);
}
ns[++nh]=L[i];ns[++nh]=R[i]+1;
}
sort(ns+1,ns+nh+1);nh=unique(ns+1,ns+nh+1)-ns-1;
for(int i=2;i<n;i++) L[i]=LB(ns+1,ns+nh+1,L[i])-ns,R[i]=LB(ns+1,ns+nh+1,R[i]+1)-ns-1;
int pt=1;
for(int i=1;i<=n;i++){
if(i-pt>=2) add(i-1,1);
while(Tree::qry()) i-pt>=2&&(add(pt+1,-1),0),pt++;
ans+=i-pt;
}
printf("%lld\n",ans);
}
int main(){
int t=1;
// scanf("%d",&t);
while(t--) Solve();
cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 7
Accepted
time: 1ms
memory: 6012kb
input:
2 2 1
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 7
Accepted
time: 1ms
memory: 10196kb
input:
10 2 2 2 2 1 4 5 3 3 2
output:
20
result:
ok 1 number(s): "20"
Test #3:
score: 7
Accepted
time: 1ms
memory: 10128kb
input:
10 2 2 1 2 2 2 1 4 1 4
output:
17
result:
ok 1 number(s): "17"
Test #4:
score: 0
Wrong Answer
time: 1ms
memory: 10172kb
input:
10 1 5 2 2 5 4 4 4 1 3
output:
18
result:
wrong answer 1st numbers differ - expected: '20', found: '18'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #1:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
0%
Subtask #5:
score: 0
Skipped
Dependency #1:
0%