QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#572750 | #9313. Make Max | YoruKiri | RE | 0ms | 3504kb | C++20 | 1.3kb | 2024-09-18 16:13:25 | 2024-09-18 16:13:26 |
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 mem(a, b) memset(a,b,sizeof(a))
#define pii pair<int,int>
#define lson (p<<1)
#define rson (p<<1|1)
#define int long long
#define enter putchar('\n')
#define space putchar(' ')
const int mod=998244353, NMAX=1e5+5, INF=0x3f3f3f3f3f3f3f3f;
using namespace std;
inline int read() {
int x = 0, f = 1;
char c = getchar();
while (c < '0' || c > '9') f = c == '-' ? -1 : f, c = getchar();
while (c >= '0' && c <= '9') x = (x<<3)+(x<<1)+(c^48), c = getchar();
return x*f;
}
inline void write(int x) {
if (x < 0) x = -x, putchar('-');
if (x > 9) write(x/10);
putchar('0' + x%10);
}
int a[NMAX];
void solve() {
int n=read(), top=0, ans=0;
vector <int> stk(n+1), b(n+1);
rep(i, 1, n) a[i]=read();
rep(i, 1, n) {
while(top && a[ stk[top] ] < a[i]) top --;
if(top == 0)
ans += i-1;
else if(a[ stk[top] ] == a[i])
b[i] = b[ stk[top] ], ans += b[i], top --;
else
ans += i-stk[top]+b[ stk[top] ], b[i] = b[ stk[top] ] + 1;
stk[++ top] = i;
}
write(ans), enter;
}
signed main() {
int _ = 1;
_ = read();
while(_ --) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3504kb
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
Runtime Error
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...