#include <bits/stdc++.h>
using namespace std;
//BIT Fenwick tree
int n ;
int bit[6000001]={0};
void add(int e,int v){
while(e<=n*4){
bit[e]+=v;
e+=e&-e;
}
}
long long sum(int e){
long long res = 0;
while(e>=1){
res+=bit[e];
e -= e&-e;
}
return res;
}
int main(){
cin>>n;
vector<int> v,w,so;v.push_back(2);
for(int i = 0;i<n;i++){
int x;cin>>x;
w.push_back(x);
so.push_back(x);
}
sort(so.begin(),so.end());
int z = 2;
map<int,int>cmp;
for(int i = 0;i<n;i++){
cmp[so[i]] = z++;
if(i&&so[i]==so[i-1])z--;
}
for(int i = 0;i<n;i++){
v.push_back(cmp[w[i]]*2);
}
for(int i = 0;i<n;i++){
if(v[i]<v[i+1]){
add(v[i+1],-1);
add(v[i],1);
}
}
long long ma = 0;
for(int i = 2;i<=cmp[so[n-1]]*2;i++){
ma = max(ma,sum(i));
}
cout<<ma<<"\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
2068 KB |
Output is correct |
2 |
Correct |
29 ms |
2112 KB |
Output is correct |
3 |
Correct |
25 ms |
2120 KB |
Output is correct |
4 |
Correct |
27 ms |
2144 KB |
Output is correct |
5 |
Correct |
28 ms |
2088 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
111 ms |
7888 KB |
Output is correct |
2 |
Correct |
91 ms |
7696 KB |
Output is correct |
3 |
Correct |
110 ms |
7948 KB |
Output is correct |
4 |
Correct |
101 ms |
7880 KB |
Output is correct |
5 |
Correct |
100 ms |
7776 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1076 ms |
65536 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1090 ms |
49760 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |