//雪花飄飄北風嘯嘯
//天地一片蒼茫
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ii pair<int,int>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << ": " << x << endl
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define lb lower_bound
#define ub upper_bound
#define rep(x,start,end) for(int x=start;x!=end;x++)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
//change less to less_equal for non distinct pbds, but erase will bug
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
int n;
ii arr[200005];
ii brr[200005];
int cnt[1<<15];
int af=(1<<15)-1;
int delta[200005];
ll solve(vector<int> &v){
if (sz(v)==1) return 1;
v.pub(n+1);
vector<ii> ranges={ {0,-(v[0]-1)} };
rep(x,0,sz(v)-1){
ranges.pub({ranges.back().se+1,ranges.back().se-(v[x+1]-v[x])+2});
}
vector<int> imp={-(int)1e9};
rep(x,0,sz(ranges)) imp.pub(ranges[x].fi),imp.pub(ranges[x].fi-1);
sort(all(imp));
imp.erase(unique(all(imp)),imp.end());
rep(x,1,sz(imp)) delta[x]=0;
//for (auto it:ranges) cout<<it.fi<<"_"<<it.se<<" "; cout<<endl;
int pos=find(all(imp),ranges[0].fi)-imp.begin()-1;
int curr=0;
ll res=0;
for (auto it:ranges){
curr+=delta[pos];
pos++;
while (true){
res+=curr;
delta[pos]++;
if (imp[pos-1]<it.se) break;
pos--;
curr-=delta[pos];
}
}
//cout<<res<<endl;
return res;
}
void read(int &x){
x=0;
char ch=getchar_unlocked();
while (ch&16) x=x*10+(ch&15),ch=getchar_unlocked();
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin.exceptions(ios::badbit | ios::failbit);
read(n);
rep(x,0,n) read(arr[x].fi),arr[x].se=x+1;
rep(x,0,n) cnt[arr[x].fi&af]++;
rep(x,1,32768) cnt[x]+=cnt[x-1];
for (int x=n-1;x>=0;x--) brr[--cnt[arr[x].fi&af]]=arr[x];
memset(cnt,0,sizeof(cnt));
rep(x,0,n) cnt[(brr[x].fi>>15)&af]++;
rep(x,1,32768) cnt[x]+=cnt[x-1];
for (int x=n-1;x>=0;x--) arr[--cnt[(brr[x].fi>>15)&af]]=brr[x];
ll ans=0;
int curr=0;
vector<int> pos;
while (curr<n){
int nxt=curr+1;
while (arr[curr].fi==arr[nxt].fi) nxt++;
pos.clear();
rep(x,curr,nxt) pos.pub(arr[x].se);
ans+=solve(pos);
curr=nxt;
}
cout<<ans<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
460 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
460 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
1 ms |
460 KB |
Output is correct |
12 |
Correct |
1 ms |
460 KB |
Output is correct |
13 |
Correct |
1 ms |
460 KB |
Output is correct |
14 |
Correct |
1 ms |
460 KB |
Output is correct |
15 |
Correct |
1 ms |
460 KB |
Output is correct |
16 |
Correct |
1 ms |
460 KB |
Output is correct |
17 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
4872 KB |
Output is correct |
2 |
Correct |
23 ms |
5880 KB |
Output is correct |
3 |
Correct |
15 ms |
3508 KB |
Output is correct |
4 |
Correct |
27 ms |
6072 KB |
Output is correct |
5 |
Correct |
32 ms |
6288 KB |
Output is correct |
6 |
Correct |
26 ms |
6572 KB |
Output is correct |
7 |
Correct |
26 ms |
6572 KB |
Output is correct |
8 |
Correct |
36 ms |
6512 KB |
Output is correct |
9 |
Correct |
27 ms |
6588 KB |
Output is correct |
10 |
Correct |
26 ms |
6540 KB |
Output is correct |
11 |
Correct |
22 ms |
9032 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
460 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
1 ms |
460 KB |
Output is correct |
12 |
Correct |
1 ms |
460 KB |
Output is correct |
13 |
Correct |
1 ms |
460 KB |
Output is correct |
14 |
Correct |
1 ms |
460 KB |
Output is correct |
15 |
Correct |
1 ms |
460 KB |
Output is correct |
16 |
Correct |
1 ms |
460 KB |
Output is correct |
17 |
Correct |
1 ms |
460 KB |
Output is correct |
18 |
Correct |
21 ms |
4872 KB |
Output is correct |
19 |
Correct |
23 ms |
5880 KB |
Output is correct |
20 |
Correct |
15 ms |
3508 KB |
Output is correct |
21 |
Correct |
27 ms |
6072 KB |
Output is correct |
22 |
Correct |
32 ms |
6288 KB |
Output is correct |
23 |
Correct |
26 ms |
6572 KB |
Output is correct |
24 |
Correct |
26 ms |
6572 KB |
Output is correct |
25 |
Correct |
36 ms |
6512 KB |
Output is correct |
26 |
Correct |
27 ms |
6588 KB |
Output is correct |
27 |
Correct |
26 ms |
6540 KB |
Output is correct |
28 |
Correct |
22 ms |
9032 KB |
Output is correct |
29 |
Correct |
29 ms |
8948 KB |
Output is correct |
30 |
Correct |
5 ms |
972 KB |
Output is correct |
31 |
Correct |
9 ms |
1612 KB |
Output is correct |
32 |
Correct |
26 ms |
3404 KB |
Output is correct |
33 |
Correct |
8 ms |
1680 KB |
Output is correct |
34 |
Correct |
9 ms |
1740 KB |
Output is correct |
35 |
Correct |
5 ms |
1332 KB |
Output is correct |
36 |
Correct |
4 ms |
972 KB |
Output is correct |
37 |
Correct |
4 ms |
1100 KB |
Output is correct |
38 |
Correct |
24 ms |
5016 KB |
Output is correct |
39 |
Correct |
25 ms |
5100 KB |
Output is correct |
40 |
Correct |
27 ms |
5088 KB |
Output is correct |
41 |
Correct |
33 ms |
5112 KB |
Output is correct |
42 |
Correct |
29 ms |
5204 KB |
Output is correct |
43 |
Correct |
28 ms |
4344 KB |
Output is correct |
44 |
Correct |
26 ms |
4320 KB |
Output is correct |
45 |
Correct |
25 ms |
4320 KB |
Output is correct |
46 |
Correct |
26 ms |
4328 KB |
Output is correct |
47 |
Correct |
26 ms |
4316 KB |
Output is correct |
48 |
Correct |
18 ms |
3616 KB |
Output is correct |
49 |
Correct |
18 ms |
3532 KB |
Output is correct |
50 |
Correct |
18 ms |
3684 KB |
Output is correct |
51 |
Correct |
18 ms |
3684 KB |
Output is correct |
52 |
Correct |
17 ms |
3600 KB |
Output is correct |
53 |
Correct |
17 ms |
3532 KB |
Output is correct |
54 |
Correct |
28 ms |
3604 KB |
Output is correct |