QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#573345 | #9313. Make Max | cute | WA | 0ms | 3656kb | C++14 | 1.1kb | 2024-09-18 18:18:05 | 2024-09-18 18:18:06 |
Judging History
answer
#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
#define ll long long
typedef pair<int, int> PII;
typedef long long LL;
const int N = 1e7+10;
const int MAX = 0x3f3f3f3f;
const int mod = 1e6+7;
void solve(){
int n;
cin >> n;
vector<int> a(n), l(n), r(n);
for(int i = 0; i < n; i++){
cin >> a[i];
}
vector<int> stk;
for(int i = 0; i < n; i++){
while(!stk.empty() && a[i] > a[stk.back()])stk.pop_back();
if(stk.empty())l[i] = 0;
else {
l[i] = stk.back()+1;
}
stk.push_back(i);
}
stk.clear();
reverse(a.begin(), a.end());
for(int i = 0; i < n; i ++){
while(!stk.empty() && a[i] > a[stk.back()])stk.pop_back();
if(stk.empty())r[i] =0;
else {
r[i] = stk.back()+1;
}
if(r[i] >= 1 && a[r[i]-1] == a[i])
r[i] = i;
stk.push_back(i);
}
reverse(r.begin(), r.end());
for(int i = 0; i < n; i++)r[i] = n-r[i]-1;
ll res = 0;
for(int i = 0; i < n; i++) {
res+= r[i]-l[i];
cout << l[i] << " " <<r[i]<<endl;
}
//cout << endl;
cout << res <<endl;
}
int main() {
int t;
cin >> t;
while(t--){
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3656kb
input:
4 2 1 2 2 2 2 7 1 1 1 2 2 2 2 3 1 2 3
output:
0 0 0 1 1 0 0 1 1 0 0 0 1 1 2 2 0 3 4 4 5 5 6 6 3 0 0 0 1 0 2 3
result:
wrong answer 1st numbers differ - expected: '1', found: '0'