QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#546762 | #8218. 水镜 | chenxinyang2006 | 0 | 4ms | 11984kb | C++20 | 1.8kb | 2024-09-04 13:09:17 | 2024-09-04 13:09:18 |
Judging History
answer
#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=(j);i<=(k);i++)
#define per(i,j,k) for(int i=(j);i>=(k);i--)
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define db double
#define ldb long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mkp make_pair
#define eb emplace_back
#define SZ(S) (int)S.size()
//#define mod 998244353
//#define mod 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3f
using namespace std;
template <class T>
void chkmax(T &x,T y){
if(x < y) x = y;
}
template <class T>
void chkmin(T &x,T y){
if(x > y) x = y;
}
inline int popcnt(int x){
return __builtin_popcount(x);
}
inline int ctz(int x){
return __builtin_ctz(x);
}
/*ll power(ll p,int k = mod - 2){
ll ans = 1;
while(k){
if(k % 2 == 1) ans = ans * p % mod;
p = p * p % mod;
k /= 2;
}
return ans;
}*/
int n;
ll a[500005],_l[500005],_r[500005];
ll Mn[500005],Mx[500005];
int p;
int check(int l,int r){
if(p < l){
p = r;
Mn[r] = _l[r];
Mx[r] = _r[r];
per(i,r - 1,l){
Mn[i] = max(_l[i],Mn[i + 1]);
Mx[i] = min(_r[i],Mx[i + 1]);
}
}
if(p < r){
Mn[r] = _l[r];
Mx[r] = _r[r];
if(p + 1 < r){
chkmax(Mn[r],Mn[r - 1]);
chkmin(Mx[r],Mx[r - 1]);
}
return max(Mn[l],Mn[r]) < min(Mx[l],Mx[r]);
}
return Mn[l] < Mx[l];
}
int main(){
scanf("%d",&n);
rep(i,1,n) scanf("%lld",&a[i]);
rep(i,2,n - 1){
_r[i] = linf;_l[i] = 0;
if(a[i] <= min(a[i - 1],a[i + 1])) _r[i] = max(a[i] + a[i - 1],a[i] + a[i + 1]);
if(a[i] >= max(a[i - 1],a[i + 1])) _l[i] = min(a[i] + a[i - 1],a[i] + a[i + 1]);
}
ll answer = n - 1;
int l = 2;
rep(r,2,n - 1){
while(!check(l,r)) l++;
answer += r - l + 1;
}
printf("%lld\n",answer);
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: 1ms
memory: 5908kb
input:
2 2 1
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Wrong Answer
time: 4ms
memory: 11984kb
input:
10 2 2 2 2 1 4 5 3 3 2
output:
-8000099
result:
wrong answer 1st numbers differ - expected: '20', found: '-8000099'
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%