#include<bits/stdc++.h>
using namespace std;
struct AintNode{
int nl, nr;
int val;
AintNode *l, *r;
AintNode(){
nl = nr = val = 0;
l = r = NULL;
}
AintNode(int _l, int _r, int _val);
};
AintNode *NIL = new AintNode;
AintNode :: AintNode(int _l,int _r, int _val){
nl = _l, nr = _r;
val = _val;
l = r= NIL;
}
AintNode* update(AintNode *nod,int upoz,int uval){
int l = nod->nl, r = nod->nr;
if(r < upoz || upoz < l || uval == 0)
return nod;
if(l == r){
return new AintNode(l, r, uval);
}
AintNode *newnode = new AintNode;
*newnode = *nod;
int mid = (l + r)/2;
if(upoz <= mid){
if(nod->l == NIL)
nod->l = new AintNode(l, mid, 0);
newnode->l = update(nod->l, upoz, uval);
}
else{
if(nod->r == NIL)
nod->r = new AintNode(mid+1, r, 0);
newnode->r = update(nod->r, upoz, uval);
}
newnode->val = newnode->l->val + newnode->r->val;
return newnode;
}
int query(AintNode* node,int ql,int qr){
int l = node->nl, r = node->nr;
if(r < ql || l > qr)
return 0;
if(ql<=l && r<=qr)
return node->val;
int ans = 0;
if(node->l != NIL)
ans += query(node->l, ql, qr);
if(node->r != NIL)
ans += query(node->r, ql, qr);
return ans;
}
const int N = 3*1e5 + 5;
long long v[N];
vector<int> poz[N];
AintNode *persist[N];
int main()
{
//freopen(".in","r",stdin);
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int n;
cin>>n;
map<long long, int> id;
for(int i=1;i<=n;i++){
cin>>v[i];
id[v[i]] = 1;
}
int cnt = 0;
for(auto &x:id){
x.second = ++ cnt;
}
for(int i=1;i<=n;i++){
v[i] = id[v[i]];
poz[v[i]].push_back(i);
}
AintNode *croot = new AintNode(1, n, 0);
persist[0] = croot;
for(int i = 1;i< N ; i++){
for(auto pz:poz[i]){
AintNode *newroot = update(croot, pz, 1);
croot = newroot;
}
persist[i] = croot;
}
long long ans = 0;
for(int i=2;i<n;i++){
int val = v[i];
int lval = query(persist[val - 1], 1, i -1);
int rval = query(persist[val - 1], i+1, n);
ans += 1LL * lval * rval;
}
cout<<ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
9708 KB |
Output is correct |
2 |
Runtime error |
490 ms |
262148 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
354 ms |
262148 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
354 ms |
262148 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
10092 KB |
Output is correct |
2 |
Correct |
7 ms |
10092 KB |
Output is correct |
3 |
Correct |
9 ms |
10092 KB |
Output is correct |
4 |
Correct |
8 ms |
10092 KB |
Output is correct |
5 |
Correct |
9 ms |
10092 KB |
Output is correct |
6 |
Correct |
9 ms |
10092 KB |
Output is correct |
7 |
Correct |
8 ms |
10092 KB |
Output is correct |
8 |
Correct |
7 ms |
10092 KB |
Output is correct |
9 |
Correct |
8 ms |
10092 KB |
Output is correct |
10 |
Correct |
7 ms |
9708 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
10092 KB |
Output is correct |
2 |
Correct |
7 ms |
10092 KB |
Output is correct |
3 |
Correct |
9 ms |
10092 KB |
Output is correct |
4 |
Correct |
8 ms |
10092 KB |
Output is correct |
5 |
Correct |
9 ms |
10092 KB |
Output is correct |
6 |
Correct |
9 ms |
10092 KB |
Output is correct |
7 |
Correct |
8 ms |
10092 KB |
Output is correct |
8 |
Correct |
7 ms |
10092 KB |
Output is correct |
9 |
Correct |
8 ms |
10092 KB |
Output is correct |
10 |
Correct |
7 ms |
9708 KB |
Output is correct |
11 |
Correct |
30 ms |
18412 KB |
Output is correct |
12 |
Correct |
38 ms |
18412 KB |
Output is correct |
13 |
Correct |
36 ms |
18412 KB |
Output is correct |
14 |
Correct |
32 ms |
18412 KB |
Output is correct |
15 |
Correct |
35 ms |
18496 KB |
Output is correct |
16 |
Correct |
31 ms |
18412 KB |
Output is correct |
17 |
Correct |
32 ms |
18412 KB |
Output is correct |
18 |
Correct |
37 ms |
18028 KB |
Output is correct |
19 |
Correct |
30 ms |
17772 KB |
Output is correct |
20 |
Correct |
7 ms |
9708 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
354 ms |
262148 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
9708 KB |
Output is correct |
2 |
Runtime error |
490 ms |
262148 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |