QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#571273 | #9313. Make Max | ConsW | WA | 63ms | 11612kb | C++20 | 2.6kb | 2024-09-17 21:38:21 | 2024-09-17 21:38:21 |
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()]) {
fa[i] = max(fa[i], stk.top());
stk.pop();
}
stk.push(i);
}
i64 ans[n],anss = 0;
memset(ans,0,sizeof ans);
for (int i = n - 1; i >= 0; --i) {
if (fa[sta[i].idx]!=-1) ans[i] = 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;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3876kb
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: 63ms
memory: 11612kb
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:
340595 328123
result:
wrong answer 1st numbers differ - expected: '4084978', found: '340595'