QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#568475 | #9313. Make Max | CheerRan | WA | 421ms | 19140kb | C++14 | 1.9kb | 2024-09-16 16:40:54 | 2024-09-16 16:40:54 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pb push_back
using ll =long long;
const int N=2e5+10;
const int mod=19260817;
const int p=1e9+7;
const int inf =0x3f3f3f3f;
const double PI=3.141592;
typedef pair<ll,ll> PII;
typedef vector<ll> vc;
int dx[]={-1,1,0,0},dy[]={0,0,-1,1};
ll fac[N],finv[N],inv[N];
void init()
{
fac[1]=fac[0]=finv[0]=finv[1]=inv[0]=inv[1]=1;
for(int i=2;i<N;i++)
{
fac[i]=fac[i-1]*i%p;
inv[i]=(p-p/i*inv[p%i]%p)%p;
finv[i]=finv[i-1]*inv[i]%p;
}
}
ll C(ll a,ll b)
{
if(a<b)
{
return 0;
}
if(b<0)
{
return 0;
}
return fac[a]*finv[b]%p+finv[a-b]%p;
}
ll n;
ll a[N];
void solve()
{
cin>>n;
map<ll,ll>mp;
stack<ll>st;
ll mx=0;
ll res=0;
for(int i=1;i<=n;i++)
{ cin>>a[i];
mx=max(mx,a[i]);
}
a[n+1]=mx;
st.push(a[1]);
mp[a[1]]++;
for(int i=2;i<=n+1;)
{
if(a[i]==st.top()) {mp[a[i]]++;i++;}
while((st.size()&&a[i]<st.top()))
{
st.push(a[i]);
mp[a[i]]++;
i++;
}
while(a[i]>st.top())
{
mp[a[i]]++;
ll x=st.top();
st.pop();
if(st.size()&&st.top()<=a[i])
{
res+=mp[x];
mp[st.top()]+=mp[x];
mp[x]=0;
}
else
{
// cout<<2<<":"<<mp[2]<<endl;
res+=mp[x];
st.push(a[i]);
mp[a[i]]+=mp[x];
// cout<<endl<<a[i]<<" "<<mp[a[i]]<<endl;
mp[x]=0;
i++;
break;
}
}
}
mp[mx]=0;
cout<<res<<endl;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int _=1;
cin>>_;
while(_--)
{
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5592kb
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: 421ms
memory: 19140kb
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:
5828262 5908581
result:
wrong answer 1st numbers differ - expected: '4084978', found: '5828262'