QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#568178 | #9313. Make Max | TwindT | WA | 29ms | 5552kb | C++20 | 2.0kb | 2024-09-16 15:29:09 | 2024-09-16 15:29:10 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int INF = 0x3f3f3f3f;
const int Mod = 1000000007;
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
bool prime(int x)
{
if (x == 2) return true;
else if (x == 1 || x % 2 == 0) return false;
for (int i = 3; i <= sqrt(x) + 1; i++) if (x % i == 0) return false;
return true;
}
void get_primes(int n,ll N)
{
vector<int>primes(N);
vector<bool>st(N); // 质数为fasle
int cnt = 0;
for (int i = 2; i <= n; i ++ )
{
if (!st[i]) primes[cnt++] = i;
for (int j = 0; primes[j] <= n / i; j ++ )
{
st[primes[j] * i] = true;
if (i % primes[j] == 0) break;
}
}
}
ll qmi(int a, int b, int p) // a ^ b % p
{
ll res = 1 % p;
while (b)
{
if (b & 1) res = res * a % p;
a = a * (ll)a % p;
b >>= 1;
}
return res;
}
int gcd(int a, int b)
{
if (b == 0)
{
return a;
}
else
{
return gcd(b, a % b);
}
}
int lcm(int a, int b)
{
return (a / gcd(a, b)) * b;
}
void XJT___solve()
{
int n;
cin>>n;
vector<int>v(n + 1),l(n + 1),r(n + 1);
for(int i = 1;i <= n;i++) cin>>v[i];
stack<int>st;
for(int i = 1;i <= n;i++)
{
while(st.size() && v[i] > v[st.top()]) st.pop();
if(!st.size()) l[i] = 1;
else l[i] = st.top() + 1;
st.push(i);
}
for(int i = n;i >= 1;i--)
{
while(st.size() && v[i] > v[st.top()]) st.pop();
if(!st.size()) r[i] = n;
else r[i] = st.top() - 1;
if(v[r[i] + 1] == v[i]) r[i] = i;
st.push(i);
}
ll ans = 0;
for(int i = 1;i <= n;i++) ans += r[i] - l[i];
cout<<ans<<'\n';
}
int main()
{
cin.tie(0);
ios::sync_with_stdio(false);
cout.tie(0);
int t = 1;
cin >> t;
while (t--)
{
XJT___solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3660kb
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: 5552kb
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'