QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#559684 | #8218. 水镜 | zhulexuan | 0 | 2ms | 15928kb | C++14 | 3.5kb | 2024-09-12 08:22:49 | 2024-09-12 08:22:49 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf INT_MAX
#define fr(i,l,r) for (i=(l); i<=(r); i++)
#define rfr(i,l,r) for (i=(l); i>=(r); i--)
template<typename T>inline void read(T &n){
T w=1; n=0; char ch=getchar();
while (!isdigit(ch) && ch!=EOF){ if (ch=='-') w=-1; ch=getchar(); }
while (isdigit(ch) && ch!=EOF){ n=(n<<3)+(n<<1)+(ch&15); ch=getchar(); }
n*=w;
}
template<typename T>inline void write(T x){
if (x==0){ putchar('0'); return ; }
T tmp;
if (x>0) tmp=x;
else tmp=-x;
if (x<0) putchar('-');
char F[105];
long long cnt=0;
while (tmp){
F[++cnt]=tmp%10+48;
tmp/=10;
}
while (cnt) putchar(F[cnt--]);
}
#define Min(x,y) x = min(x,y)
#define Max(x,y) x = max(x,y)
//基础配置=================================================================================
const ll N = 500005;
ll n,m,ans=0,x,y,l,r,s,z;
ll h[N];
struct seg{
ll l,r;
seg(ll _l=0,ll _r=0){
l = _l; r = _r;
}
};
seg operator + (seg x,seg y){
Max(x.l,y.l);
Min(x.r,y.r);
return x;
}
seg f[N];
struct Uni{
ll cnt,p[N+N+N+N];
void clear(){
cnt = 0;
}
void insert(ll x){
p[++cnt] = x;
}
void Unique(){
if (!cnt) return ;
sort(p+1,p+1+cnt);
ll i, len = 1;
fr(i,2,cnt)
if (p[i]!=p[len]) p[++len] = p[i];
cnt = len;
}
ll find(ll x){
ll l = 1, r = cnt, mid;
while (l<=r){
mid = (l+r)>>1;
if (p[mid]==x) return mid;
if (p[mid]<x) l = mid+1;
else r = mid-1;
}
return -1;
}
}un;
seg calc(ll x,ll y){//p_i>=p_{i+1}的区间L
if (x>=y) return seg(-inf,(x+y)/2);
else return seg((x+y)/2,inf);
}
struct Tree{
struct node{
ll l,r;
ll v,tag;//最小值,覆盖标记
}t[16*N];
void build(ll s,ll l,ll r){
t[s].l = l; t[s].r = r;
t[s].v = 1; t[s].tag = -1;
if (l==r) return ;
ll mid = (l+r)>>1;
build(s*2,l,mid);
build(s*2+1,mid+1,r);
}
void chg(ll s,ll v){
t[s].v = t[s].tag = v;
}
void down(ll s){
if (t[s].tag==-1) return ;
chg(s*2,t[s].tag);
chg(s*2+1,t[s].tag);
t[s].tag = -1;
}
void change(ll s,ll l,ll r,ll v){
if (t[s].l>=l && t[s].r<=r){ chg(s,v); return ; }
down(s);
if (t[s*2].r>=l) change(s*2,l,r,v);
if (t[s*2+1].l<=r) change(s*2+1,l,r,v);
t[s].v = min(t[s*2].v,t[s*2+1].v);
}
}tr;
int main(){
// freopen("a.in","r",stdin);
// freopen(".out","w",stdout);
ll i,j;
read(n);
fr(i,1,n) read(h[i]), h[i]*=2;
fr(i,2,n) f[i] = calc(h[i],h[i-1]) + calc(h[i],h[i+1]);
un.clear();
un.insert(-2*inf); un.insert(2*inf);
fr(i,2,n) un.insert(f[i].l), un.insert(f[i].r), un.insert(f[i].l+1), un.insert(f[i].r+1);
// fr(i,2,n) printf("%lld : ban %lld ~ %lld\n",i,f[i].l,f[i].r);
un.Unique();
fr(i,2,n)
f[i].l = un.find(f[i].l),
f[i].r = un.find(f[i].r);
// fr(i,2,n) printf("%lld : ban %lld ~ %lld\n",i,f[i].l,f[i].r);
tr.build(1,1,un.cnt);
ll ans = 0;
fr(i,2,n){
if (f[i].l<=f[i].r) tr.change(1,f[i].l,f[i].r,i);
ll lf = tr.t[1].v;
// printf("i = %lld , lf = %lld\n",i,lf);
ans += i-lf;
}
write(ans);
return 0;
}
//g++ a.cpp -o a -Wall -Wl,--stack=512000000 -std=c++11 -O2
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 7
Accepted
time: 2ms
memory: 15892kb
input:
2 2 1
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Wrong Answer
time: 2ms
memory: 15928kb
input:
10 2 2 2 2 1 4 5 3 3 2
output:
45
result:
wrong answer 1st numbers differ - expected: '20', found: '45'
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%