QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#571910 | #9313. Make Max | ConsW | WA | 65ms | 11356kb | C++20 | 2.6kb | 2024-09-18 10:14:55 | 2024-09-18 10:14:56 |
Judging History
answer
#include<bits/stdc++.h>
#define i64 long long
#define ll long long
using namespace std;
typedef pair<i64, i64> pii;
const i64 MOD = 998244353;
inline i64 lowbit(i64 x) { return x & (-x); }
inline i64 highbit(i64 x) {
i64 cnt = 0;
do {
if (x == 1) return 1LL << cnt;
else ++cnt;
} while (x >>= 1);
}
inline i64 factory(i64 x) {
i64 cnt = 1;
while (x != 1) {
cnt *= x--;
cnt %= MOD;
}
return cnt;
}//阶乘(含模运算)
inline i64 gcd(i64 a, i64 b) {
while (b ^= a ^= b ^= a %= b);
return a;
}//最小公约数
inline bool isPrime(i64 x) {
for (int i = 2; i <= sqrt(x); ++i) {
if (x % i == 0) return false;
}
if (x != 1) return true;
else return false;
}
inline bool cmp(pii a, pii b) {
return a.first > b.first;
}
inline i64 query(i64 a, i64 b) {
i64 tmp;
cout << "? " << a << " " << b << endl;
cout.flush();
cin >> tmp;
return tmp;
}
inline i64 to_i64(string s) {
stringstream ss(s);
i64 tmp;
ss >> tmp;
return tmp;
}//字符串转long long
inline i64 LIS(i64 arr[], i64 n) {
i64 dp[n], len = 0;
dp[0] = arr[0];
for (int i = 1; i < n; ++i) {
if (arr[i] > dp[len]) dp[++len] = arr[i];
else *(lower_bound(dp, dp + len, arr[i])) = arr[i];
}
return len + 1;
}
struct st{
i64 num;
i64 idx;
};
bool cmpp(st a,st b){
return a.num > b.num;
}
void solve() {
i64 n;
cin>>n;
i64 a[n];
st sta[n];
for (int i = 0; i < n; ++i) {
cin>>a[i];
sta[i].num = a[i];
sta[i].idx = i;
}
sort(sta,sta+n, cmpp);
i64 fa[n];
stack<i64> stk;
for (int i = 0; i < n; ++i) {
while (!stk.empty()&&a[i]>a[stk.top()]) {
fa[stk.top()] = i;
stk.pop();
}
stk.push(i);
}
while (!stk.empty()) {
fa[stk.top()] = -1;
stk.pop();
}
for (int i = n - 1; i >= 0; --i) {
while (!stk.empty()&&a[i]>a[stk.top()]) {
if (a[i] < fa[i]) fa[stk.top()] = i;
stk.pop();
}
stk.push(i);
}
i64 ans[n],anss = 0;
memset(ans,0,sizeof ans);
for (int i = 0; i < n; ++i) {
if (fa[sta[i].idx]!=-1) ans[sta[i].idx] = ans[fa[sta[i].idx]] + 1;
}
for (int i = 0; i < n; ++i) anss += ans[i];
cout<<anss<<endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3624kb
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: 65ms
memory: 11356kb
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:
2069924 1909959
result:
wrong answer 1st numbers differ - expected: '4084978', found: '2069924'