QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#665144 | #9313. Make Max | Faruk982 | WA | 426ms | 43368kb | C++23 | 2.6kb | 2024-10-22 06:13:42 | 2024-10-22 06:13:42 |
Judging History
answer
// gfsgfsdg
// ffff
// faruk
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fastio \
ios_base::sync_with_stdio(0); \
cin.tie(0)
#define YES cout << "Yes\n";
#define NO cout << "No\n";
#define SetBit(x, k) (x |= (1ll << k))
#define ClearBit(x, k) (x &= ~(1ll << k))
#define CheckBit(x, k) ((x >> k) & 1)
#define CC(x) cout << "Case " << ++x << ": ";
#define all(x) x.begin(), x.end()
#define INF 1e12 + 10
#define pi pair<ll, ll>
ll i, j, k, a, b, c, d, e, f, n, l, m, w;
vector<ll> vk;
// // PBDS start
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// template <class T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// template <class K, class V>
// using ordered_map = tree<K, V, less<K>, rb_tree_tag, tree_order_statistics_node_update>;
// // less<T> for uniqe elements ,, less_equal<T> for duplicate
// // PBDS end
const ll M = 1e9 + 7;
const int N = 4e5 + 10;
const int Ni = 1e6 + 10;
long long int binE(ll a, ll b)
{
ll res = 1;
while (b > 0)
{
if (b & 1)
res = (res * a) % M;
a = (a * a) % M;
b >>= 1;
}
return res;
}
map<ll, ll> vis, vis1;
bool cmp(pair<string, pi> p1, pair<string, pi> p2)
{
if (p1.second.first == p2.second.first)
{
return p1.second.second < p2.second.second;
}
else
return p1.second.first > p2.second.first;
}
ll tta;
ll arr[N];
void solve()
{
ll ans=0;
cin>>n;
vis.clear();
stack<pi>lefter,righter;
for(ll i=1;i<=n;i++)cin>>arr[i];
map<ll,ll>khise;
for(ll i=1;i<=n;i++){
ll cnt=0;
while (lefter.size()&&lefter.top().first<arr[i])
{
cnt+=(vis[lefter.top().second]+1);
khise[lefter.top().second]=arr[i];
lefter.pop();
}
vis[i]=cnt;
lefter.push({arr[i],i});
}
vis1.clear();
for(ll i=n;i>=1;i--){
ll cnt=0;
while (righter.size()&&righter.top().first<arr[i]&&(khise[righter.top().second]!=arr[i]))
{
cnt+=(vis1[righter.top().second]+1);
righter.pop();
}
vis1[i]=cnt;
righter.push({arr[i],i});
}
for(ll i=1;i<=n;i++)ans+=(vis[i]+vis1[i]);
cout<<ans<<endl;
}
int32_t main()
{
fastio;
int testcase = 1;
cin >> testcase;
ll x = 0;
// fact[0]=1;
// for(ll i=1;i<=N;i++){
// fact[i]=(i*fact[0])%M;
// if(fact[i]<0)fact[i]+=M;
// }
// cout<<testcase<<endl;
while (testcase--)
{
// cout<<testcase<<endl;
vk.clear();
// CC(x)
// memset(dp,-1,sizeof(dp));
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3528kb
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: 0
Accepted
time: 426ms
memory: 43368kb
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:
4084978 4130372
result:
ok 2 number(s): "4084978 4130372"
Test #3:
score: -100
Wrong Answer
time: 367ms
memory: 42652kb
input:
2 195768 3086 1582 7854 5577 5243 2734 8054 4805 5686 7065 5555 2410 6240 7589 2889 3745 8094 9147 9438 1252 5497 5786 6655 4437 3933 2579 5722 9512 3117 1742 5362 2068 1853 4069 9231 1126 3991 420 2571 5517 3063 7279 8085 6111 5503 5980 50 6003 244 9684 6343 6517 1598 5223 5520 982 3932 1093 1149 7...
output:
3192032 3120754
result:
wrong answer 1st numbers differ - expected: '3061429', found: '3192032'