....

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include <bits/stdc++.h>
using namespace std;
int st[200005],p,l[200005],r[200005],ll[200005],rr[200005],pos,ans,js[200005];
struct tree
{
long long l,r,sum,f;
}t[400005];
struct node
{
int s,id;
}a[100005];
void build(int p,int l,int r)
{
t[p].l=l;
t[p].r=r;
t[p].sum=t[p].f=0;
if(t[p].l==t[p].r)
return;
int mid=(t[p].l+t[p].r)>>1;
build(p<<1,l,mid);
build(p<<1|1,mid+1,r);
}
void lazy(int p)
{
if(t[p].f)
{
t[p<<1].f+=t[p].f;
t[p<<1|1].f+=t[p].f;
t[p<<1].sum+=(t[p<<1].r-t[p<<1].l+1)*t[p].f;
t[p<<1|1].sum+=(t[p<<1|1].r-t[p<<1|1].l+1)*t[p].f;
t[p].f=0;
}
}
void change(int p,int x,int y,int z)
{
if(x<=t[p].l&&y>=t[p].r)
{
t[p].sum+=(t[p].r-t[p].l+1)*z;
t[p].f+=z;
return;
}
lazy(p);
int mid=(t[p].l+t[p].r)>>1;
if(x<=mid)
change(p<<1,x,y,z);
if(y>mid)
change(p<<1|1,x,y,z);
t[p].sum=t[p<<1].sum+t[p<<1|1].sum;
}
long long gs(int p,int x,int y)
{
if(x<=t[p].l&&y>=t[p].r)
return t[p].sum;
lazy(p);
int mid=(t[p].l+t[p].r)>>1;
long long ans=0;
if(x<=mid)
ans+=gs(p<<1,x,y);
if(y>mid)
ans+=gs(p<<1|1,x,y);
return ans;
}
bool cmp(node a,node b)
{
return a.s<b.s;
}
int main()
{
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&a[i].s),a[i].id=i;
for(int i=1;i<=n;i++)
{
while(p&&a[st[p]].s>=a[i].s)
p--;
l[i]=p?st[p]:0;
st[++p]=i;
}
p=0;
for(int i=n;i;i--)
{
while(p&&a[st[p]].s>=a[i].s)
p--;
r[i]=p?st[p]:n+1;
st[++p]=i;
}
p=0;
build(1,1,100001);
sort(a+1,a+1+n,cmp);
for(int i=1;i<=n;i++)
{
if(a[i].s-(gs(1,l[a[i].id]+1,r[a[i].id]-1)/(r[a[i].id]-(l[a[i].id]+1)))>=1)
{
ans+=a[i].s-(gs(1,l[a[i].id]+1,r[a[i].id]-1)/(r[a[i].id]-(l[a[i].id]+1)));
ll[++pos]=l[a[i].id]+1;
rr[pos]=r[a[i].id]-1;
js[pos]=a[i].s-(gs(1,l[a[i].id]+1,r[a[i].id]-1)/(r[a[i].id]-(l[a[i].id]+1)));
change(1,l[a[i].id]+1,r[a[i].id]-1,a[i].s-(gs(1,l[a[i].id]+1,r[a[i].id]-1)/(r[a[i].id]-(l[a[i].id]+1))));
}
}
printf("%d\n",ans);
for(int i=1;i<=pos;i++)
for(int j=1;j<=js[i];j++)
printf("%d %d\n",ll[i],rr[i]);
}
就算是一分钱,也是对作者极大的支持
------ 本文结束 ------

版权声明

Baccano by baccano is licensed under a Creative Commons BY-NC-ND 4.0 International License.
baccano创作并维护的Baccano博客采用创作共用保留署名-非商业-禁止演绎4.0国际许可证
本文首发于baccano 博客( http://baccano.fun ),版权所有,侵权必究。

小游戏

---小游戏:要不要来选择一下自己可能的老婆?---

简易发声器

---简易的七键钢琴插件---

可以使用鼠标点击琴键也可以使用主键盘1-7或者小键盘的1-7来操作

那么现在开始吧

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
0%