QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#567810 | #9313. Make Max | MLK | WA | 23ms | 6764kb | C++14 | 1.4kb | 2024-09-16 14:02:34 | 2024-09-16 14:02:34 |
Judging History
answer
#include <bits/stdc++.h>
#define N (200000 + 10) /*------------------ #define ------------------*/
#define M (400000 + 10)
#define MOD (1000000000 + 7)
//#define MOD (998244353)
#define INF (0x3f3f3f3f)
#define LNF (3e18)
#define mod(a,b) (((a)%(b)+(b))%(b))
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define fi first
#define se second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
typedef pair<int,LL> PIL;
typedef pair<LL,int> PLI;
typedef pair<double,double> PDD;
int n,a[N];
int stk[N],tt;
int L[N],R[N];
auto solve(){
cin >> n;
for(int i = 1;i <= n;i ++ ) cin >> a[i];
tt = 0;
for(int i = 1;i <= n;i ++ ){
while(tt && a[stk[tt]] < a[i]) tt -- ;
if(tt) L[i] = stk[tt];
else L[i] = 0;
stk[++tt]=i;
}
tt = 0;
for(int i = n;i >= 1;i -- ){
while(tt && a[stk[tt]] < a[i]) tt -- ;
if(tt) R[i] = stk[tt];
else R[i] = n + 1;
stk[++tt]=i;
}
LL ans = 0;
for(int i = 1;i <= n;i ++ ){
ans += (i - L[i] - 1);
if(R[i] <= n && a[R[i]] != a[i]) ans += (R[i] - i - 1);
}
//for(int i = 1;i <= n;i ++ ) cout << i << ' ' << L[i] << ' ' << R[i] << '\n';
cout << ans << '\n';
}
signed main(){
IOS
int T = 1;
cin >> T;
while(T -- ) solve();
//while(T -- ) cout << (solve() ? "YES" : "NO") << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3724kb
input:
4 2 1 2 2 2 2 7 1 1 1 2 2 2 2 3 1 2 3
output:
1 0 3 3
result:
ok 4 number(s): "1 0 3 3"
Test #2:
score: -100
Wrong Answer
time: 23ms
memory: 6764kb
input:
2 198018 875421126 585870339 471894633 383529988 625397685 944061047 704695631 105113224 459022561 760848605 980735314 847376362 980571959 329939331 644635272 326439858 752879510 837384394 175179068 182094523 397239381 1199016 185143405 279638454 252374970 822030887 860312140 137248166 993229443 164...
output:
3878282 3690277
result:
wrong answer 1st numbers differ - expected: '4084978', found: '3878282'