QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#576173 | #9313. Make Max | Licj | WA | 29ms | 7676kb | C++20 | 1.9kb | 2024-09-19 19:00:58 | 2024-09-19 19:00:58 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
//#define int unsigned long long
#define int long long
#define yyy cout<<"YES\n"
#define nnn cout<<"NO\n"
#define endl '\n'
typedef pair<int, int> PII;
#define MAP map<int,int>
#define ios ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define fi first
#define se second
#define rrr return
int dx[4] = {0, 0, 1,-1};
int dy[4] = {1, -1, 0, 0};
//void print(__int128_t x){if (x < 0){putchar('-');x = -x;}
//if (x > 9) print(x / 10);putchar(x % 10 + '0');}
int qmod(int a,int b,int mod){int ans=1; a=a%mod;
while(b){if(b&1==1) ans=ans*a%mod;a=a*a%mod;b>>=1;}return ans;}
int qpow(int a,int b){int ans=1;while(b)
{if(b&1==1) ans=ans*a;a=a*a;b>>=1;}return ans;}
int getor(int l, int r){if (l == r) return l;
return l | ((1 << ( __lg(l ^ r) + 1)) - 1);}
int getand(int l, int r){if (l == r) return l;
return l & ((1ll << ( __lg(l ^ r) + 1)) - 1);}
inline int lowbit(int x){return x&(-x);}
int gcd(int a,int b){return b==0?a:gcd(b,a%b);}
int lcm(int a,int b){return a*b/gcd(a,b);}
const double pi=acos(-1);
const int N=2e6+10;
const int mod=1e9+7;
int a[N],b[N];
void solve(){
int n;cin>>n;
for(int i=1;i<=n;i++) cin>>a[i];
stack<int> s1,s2;
int cnt1=0,cnt2=0,ans1=0,ans2=0;
for(int i=1;i<=n;i++){
int flag=0;
while(s1.size()&&s1.top()<a[i]) s1.pop(),cnt1++,flag=1;
if(flag==1)ans1+=cnt1;
else cnt1=0;
s1.push(a[i]);
}
//cout<<ans1<<endl;
for(int i=n;i>=1;i--){
int flag=0;
while(s2.size()&&s2.top()<a[i]) s2.pop(),cnt2++,flag=1;
/*if(s2.size()&&a[i]==s2.top()){
if(flag==0) cnt2=0;
s2.push(a[i]);
continue;
}*/
if(flag==1)ans2+=cnt2;
else cnt2=0;
s2.push(a[i]);
}
cout<<ans1+ans2<<endl;
}
signed main()
{
ios;
int t=1;
cin>>t;
while(t--){
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5620kb
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: 29ms
memory: 7676kb
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:
521791 501680
result:
wrong answer 1st numbers differ - expected: '4084978', found: '521791'