QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#557532 | #8218. 水镜 | piggy123 | 0 | 11ms | 161540kb | C++20 | 5.0kb | 2024-09-11 10:11:42 | 2024-09-11 10:11:43 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll h[500005],n;
struct node {
pair<ll,ll> rg[2][2];
ll lt,rt;
} tree[2000005];
inline bool emp(pair<ll,ll> a){
return a.first>a.second;
}
inline pair<ll,ll> jiao(pair<ll,ll> a,pair<ll,ll> b) {
if (emp(a)||emp(b))return {2e12,0};
return {max(a.first,b.first),min(a.second,b.second)};
}
inline pair<ll,ll> bing(pair<ll,ll> a,pair<ll,ll> b) {
if (emp(a))return b;
if (emp(b))return a;
return {min(a.first,b.first),max(a.second,b.second)};
}
inline node pushup(node X,node Y) {
node Z;
Z.lt=X.lt,Z.rt=Y.rt;
pair<ll,ll> trg1=(X.rt<Y.lt?make_pair(0.0,2e12):make_pair(2e12,0.0)),trg3=make_pair(0,X.rt+Y.lt),trg2=make_pair(X.rt+Y.lt,2e12),trg4=(X.rt>Y.lt?make_pair(0.0,2e12):make_pair(2e12,0.0));
Z.rg[0][0]=bing(bing(jiao(jiao(X.rg[0][0],Y.rg[0][0]),trg1),jiao(jiao(X.rg[0][0],Y.rg[1][0]),trg2)),bing(jiao(jiao(X.rg[0][1],Y.rg[0][0]),trg3),jiao(jiao(X.rg[0][1],Y.rg[1][0]),trg4)));
Z.rg[1][0]=bing(bing(jiao(jiao(X.rg[1][0],Y.rg[0][0]),trg1),jiao(jiao(X.rg[1][0],Y.rg[1][0]),trg2)),bing(jiao(jiao(X.rg[1][1],Y.rg[0][0]),trg3),jiao(jiao(X.rg[1][1],Y.rg[1][0]),trg4)));
Z.rg[0][1]=bing(bing(jiao(jiao(X.rg[0][0],Y.rg[0][1]),trg1),jiao(jiao(X.rg[0][0],Y.rg[1][1]),trg2)),bing(jiao(jiao(X.rg[0][1],Y.rg[0][1]),trg3),jiao(jiao(X.rg[0][1],Y.rg[1][1]),trg4)));
Z.rg[1][1]=bing(bing(jiao(jiao(X.rg[1][0],Y.rg[0][1]),trg1),jiao(jiao(X.rg[1][0],Y.rg[1][1]),trg2)),bing(jiao(jiao(X.rg[1][1],Y.rg[0][1]),trg3),jiao(jiao(X.rg[1][1],Y.rg[1][1]),trg4)));
return Z;
}
void build(ll root,ll l,ll r) {
if (l==r) {
tree[root].rg[0][0]=tree[root].rg[1][1]= {0,2e12};
tree[root].rg[1][0]=tree[root].rg[0][1]= {2e12,0};
tree[root].lt=h[l],tree[root].rt=h[l];
return;
}
ll mid=(l+r)>>1;
build(root<<1,l,mid);
build(root<<1|1,mid+1,r);
tree[root]=pushup(tree[root<<1],tree[root<<1|1]);
}
node query(ll root,ll l,ll r,ll L,ll R) {
if (L<=l&&r<=R)return tree[root];
ll mid=(l+r)>>1;
node pl,pr;
bool fl=0,fr=0;
if (L<=mid)fl=1,pl=query(root<<1,l,mid,L,R);
if (R>mid)fr=1,pr=query(root<<1|1,mid+1,r,L,R);
if (fl&&fr)return pushup(pl,pr);
else return (fl?pl:pr);
}
inline ll check(ll l,ll r) {
node Q=query(1,1,n,l,r);
bool fl=0;
for (ll a=0; a<=1; a++) {
for (ll b=0; b<=1; b++) {
fl|=Q.rg[a][b].first<Q.rg[a][b].second;
// cout<<l<<","<<r<<","<<a<<","<<b<<":"<<Q.rg[a][b].first<<" "<<Q.rg[a][b].second<< endl;
}
}
return fl;
}
int main() {
cin.tie(0);cout.tie(0);
ios::sync_with_stdio(false);
cin >> n;
for (ll i=1; i<=n; i++) {
cin >> h[i];
h[i]*=2;
}
build(1,1,n);
ll ans=0;
for (ll i=1,r=0; i<=n; i++) {
while (r+1<=n&&check(i,r+1)) {
r++;
}
ans+=r-i;
}
cout<< ans;
return 0;
}
/*
■■■■■ ■■ ■■■ ■■■ ■ ■ ■ ■■■■ ■■■■
■ ■■ ■■ ■ ■■ ■ ■■ ■ ■ ■■ ■ ■■ ■■ ■
■ ■ ■■ ■ ■ ■ ■ ■ ■ ■■■ ■■ ■■ ■ ■■
■ ■ ■■ ■ ■ ■ ■ ■ ■ ■■ ■ ■■ ■■
■ ■ ■■ ■ ■ ■■ ■■ ■■ ■
■ ■■ ■■ ■ ■■■ ■ ■■■ ■■ ■■ ■■ ■■■
■■■■■ ■■ ■ ■ ■ ■ ■■ ■■ ■■ ■■
■ ■■ ■ ■ ■ ■ ■■ ■■ ■■ ■
■ ■■ ■ ■ ■ ■ ■■ ■■ ■ ■ ■■
■ ■■ ■■ ■■ ■■ ■■ ■■ ■■ ■ ■■ ■■
■ ■■ ■■■■ ■■■■ ■■ ■■ ■■■■■■ ■■■■
*/
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 7
Accepted
time: 3ms
memory: 161312kb
input:
2 2 1
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 7
Accepted
time: 7ms
memory: 161176kb
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: 3ms
memory: 161540kb
input:
10 2 2 1 2 2 2 1 4 1 4
output:
17
result:
ok 1 number(s): "17"
Test #4:
score: 7
Accepted
time: 11ms
memory: 160184kb
input:
10 1 5 2 2 5 4 4 4 1 3
output:
20
result:
ok 1 number(s): "20"
Test #5:
score: 7
Accepted
time: 11ms
memory: 161064kb
input:
10 904418845477 67070474418 839309493679 528132965435 512894488193 602880026087 180594485896 804608714469 235337679831 584564033737
output:
33
result:
ok 1 number(s): "33"
Test #6:
score: 0
Wrong Answer
time: 7ms
memory: 160268kb
input:
10 2550179579 103777915839 144714526810 113623620429 670640709602 630479108288 925117980861 409440663027 851501568790 70823805701
output:
21
result:
wrong answer 1st numbers differ - expected: '24', found: '21'
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%