# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
527506 |
2022-02-17T13:54:22 Z |
zaneyu |
Izbori (COCI22_izbori) |
C++14 |
|
211 ms |
26020 KB |
/*input
2
1 1
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
//#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
using ll = long long;
using ld = long double;
using pii = pair<ll,ll>;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define MP make_pair
const ll INF64=4e17;
const int INF=0x3f3f3f3f;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
out<<P.f<<' '<<P.s;
return out;
}
template<typename T>
ostream& operator<<(ostream& out,vector<T> V){
REP(i,sz(V)) out<<V[i]+1<<((i!=sz(V)-1)?" ":"");
return out;
}
ll mult(ll a,ll b){
return ((a%MOD)*(b%MOD))%MOD;
}
ll mypow(ll a,ll b){
if(b<=0) return 1;
ll res=1LL;
while(b){
if(b&1) res=mult(res,a);
a=mult(a,a);
b>>=1;
}
return res;
}
const int maxn=6e5+5;
int arr[maxn];
vector<pii> v[maxn];
int main(){
int n;
cin>>n;
map<int,int> mp;
REP(i,n) cin>>arr[i],mp[arr[i]]=0;
int cntt=0;
for(auto &x:mp) x.s=cntt++;
REP(i,n) arr[i]=mp[arr[i]];
for(int i=0;i<n;){
int p=i;
while(i<n and arr[i]==arr[p]) ++i;
v[arr[p]].pb({p,i});
}
ll ans=0;
REP(i,cntt){
int pv=0;
int cur=n,mn=n,tot=0,up=n;
v[i].pb({n,n});
mp.clear();
mp[cur]++;
for(auto x:v[i]){
int z=x.f-pv;
if(z){
while(cur-1>mn and z){
cur--;
tot-=mp[cur];
ans+=tot;
--z;
}
if(z){
tot=0,cur-=z,mn=cur;
}
mp[cur]++;
}
for(int j=x.f;j<x.s;j++){
++cur;
tot+=mp[cur-1];
ans+=tot;
if(j!=x.s-1) mp[cur]++;
else if(cur>=up) mp[cur]++;
if(cur<up) mp[cur]++;
MXTO(up,cur);
}
pv=x.s;
}
}
cout<<ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
14388 KB |
Output is correct |
2 |
Correct |
7 ms |
14304 KB |
Output is correct |
3 |
Correct |
8 ms |
14284 KB |
Output is correct |
4 |
Correct |
8 ms |
14284 KB |
Output is correct |
5 |
Correct |
9 ms |
14284 KB |
Output is correct |
6 |
Correct |
8 ms |
14388 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
14388 KB |
Output is correct |
2 |
Correct |
7 ms |
14304 KB |
Output is correct |
3 |
Correct |
8 ms |
14284 KB |
Output is correct |
4 |
Correct |
8 ms |
14284 KB |
Output is correct |
5 |
Correct |
9 ms |
14284 KB |
Output is correct |
6 |
Correct |
8 ms |
14388 KB |
Output is correct |
7 |
Correct |
9 ms |
14380 KB |
Output is correct |
8 |
Correct |
9 ms |
14284 KB |
Output is correct |
9 |
Correct |
8 ms |
14412 KB |
Output is correct |
10 |
Correct |
10 ms |
14376 KB |
Output is correct |
11 |
Correct |
9 ms |
14412 KB |
Output is correct |
12 |
Correct |
9 ms |
14384 KB |
Output is correct |
13 |
Correct |
9 ms |
14388 KB |
Output is correct |
14 |
Correct |
9 ms |
14396 KB |
Output is correct |
15 |
Correct |
8 ms |
14412 KB |
Output is correct |
16 |
Correct |
9 ms |
14404 KB |
Output is correct |
17 |
Correct |
9 ms |
14392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
42 ms |
16668 KB |
Output is correct |
2 |
Correct |
51 ms |
16748 KB |
Output is correct |
3 |
Correct |
32 ms |
15788 KB |
Output is correct |
4 |
Correct |
60 ms |
16820 KB |
Output is correct |
5 |
Correct |
54 ms |
16832 KB |
Output is correct |
6 |
Correct |
62 ms |
16936 KB |
Output is correct |
7 |
Correct |
56 ms |
16864 KB |
Output is correct |
8 |
Correct |
59 ms |
16944 KB |
Output is correct |
9 |
Correct |
57 ms |
16888 KB |
Output is correct |
10 |
Correct |
58 ms |
16896 KB |
Output is correct |
11 |
Correct |
100 ms |
24516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
14388 KB |
Output is correct |
2 |
Correct |
7 ms |
14304 KB |
Output is correct |
3 |
Correct |
8 ms |
14284 KB |
Output is correct |
4 |
Correct |
8 ms |
14284 KB |
Output is correct |
5 |
Correct |
9 ms |
14284 KB |
Output is correct |
6 |
Correct |
8 ms |
14388 KB |
Output is correct |
7 |
Correct |
9 ms |
14380 KB |
Output is correct |
8 |
Correct |
9 ms |
14284 KB |
Output is correct |
9 |
Correct |
8 ms |
14412 KB |
Output is correct |
10 |
Correct |
10 ms |
14376 KB |
Output is correct |
11 |
Correct |
9 ms |
14412 KB |
Output is correct |
12 |
Correct |
9 ms |
14384 KB |
Output is correct |
13 |
Correct |
9 ms |
14388 KB |
Output is correct |
14 |
Correct |
9 ms |
14396 KB |
Output is correct |
15 |
Correct |
8 ms |
14412 KB |
Output is correct |
16 |
Correct |
9 ms |
14404 KB |
Output is correct |
17 |
Correct |
9 ms |
14392 KB |
Output is correct |
18 |
Correct |
42 ms |
16668 KB |
Output is correct |
19 |
Correct |
51 ms |
16748 KB |
Output is correct |
20 |
Correct |
32 ms |
15788 KB |
Output is correct |
21 |
Correct |
60 ms |
16820 KB |
Output is correct |
22 |
Correct |
54 ms |
16832 KB |
Output is correct |
23 |
Correct |
62 ms |
16936 KB |
Output is correct |
24 |
Correct |
56 ms |
16864 KB |
Output is correct |
25 |
Correct |
59 ms |
16944 KB |
Output is correct |
26 |
Correct |
57 ms |
16888 KB |
Output is correct |
27 |
Correct |
58 ms |
16896 KB |
Output is correct |
28 |
Correct |
100 ms |
24516 KB |
Output is correct |
29 |
Correct |
137 ms |
24492 KB |
Output is correct |
30 |
Correct |
46 ms |
17332 KB |
Output is correct |
31 |
Correct |
96 ms |
19924 KB |
Output is correct |
32 |
Correct |
211 ms |
26020 KB |
Output is correct |
33 |
Correct |
93 ms |
20276 KB |
Output is correct |
34 |
Correct |
106 ms |
20400 KB |
Output is correct |
35 |
Correct |
71 ms |
18588 KB |
Output is correct |
36 |
Correct |
39 ms |
16936 KB |
Output is correct |
37 |
Correct |
54 ms |
17464 KB |
Output is correct |
38 |
Correct |
112 ms |
19836 KB |
Output is correct |
39 |
Correct |
87 ms |
19948 KB |
Output is correct |
40 |
Correct |
89 ms |
19964 KB |
Output is correct |
41 |
Correct |
84 ms |
19856 KB |
Output is correct |
42 |
Correct |
87 ms |
19852 KB |
Output is correct |
43 |
Correct |
144 ms |
19468 KB |
Output is correct |
44 |
Correct |
137 ms |
19420 KB |
Output is correct |
45 |
Correct |
157 ms |
19360 KB |
Output is correct |
46 |
Correct |
134 ms |
19696 KB |
Output is correct |
47 |
Correct |
130 ms |
19416 KB |
Output is correct |
48 |
Correct |
113 ms |
19268 KB |
Output is correct |
49 |
Correct |
103 ms |
19276 KB |
Output is correct |
50 |
Correct |
92 ms |
20296 KB |
Output is correct |
51 |
Correct |
91 ms |
20152 KB |
Output is correct |
52 |
Correct |
92 ms |
18632 KB |
Output is correct |
53 |
Correct |
102 ms |
18380 KB |
Output is correct |
54 |
Correct |
89 ms |
18760 KB |
Output is correct |