Submission #369966

# Submission time Handle Problem Language Result Execution time Memory
369966 2021-02-22T20:15:47 Z ivan_tudor Mountains (NOI20_mountains) C++14
64 / 100
482 ms 262148 KB
#include<bits/stdc++.h>
using namespace std;
struct AintNode{
  int nl, nr;
  int val;
  AintNode *l, *r;
  AintNode(int _l,int _r, int _val){
    nl = _l, nr = _r;
    val = _val;
    l = r= NULL;
  }
};
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(l, r, 0);
  int mid = (l + r)/2;
  if(nod->l == NULL)
    nod->l = new AintNode(l, mid, 0);
  newnode->l = update(nod->l, upoz, uval);
  if(nod->r == NULL)
    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 != NULL)
    ans += query(node->l, ql, qr);
  if(node->r != NULL)
    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;
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 9856 KB Output is correct
2 Runtime error 482 ms 262148 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 381 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 381 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 10220 KB Output is correct
2 Correct 7 ms 10092 KB Output is correct
3 Correct 7 ms 10092 KB Output is correct
4 Correct 8 ms 10092 KB Output is correct
5 Correct 8 ms 10092 KB Output is correct
6 Correct 7 ms 10092 KB Output is correct
7 Correct 7 ms 10092 KB Output is correct
8 Correct 7 ms 10092 KB Output is correct
9 Correct 7 ms 10092 KB Output is correct
10 Correct 7 ms 9708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 10220 KB Output is correct
2 Correct 7 ms 10092 KB Output is correct
3 Correct 7 ms 10092 KB Output is correct
4 Correct 8 ms 10092 KB Output is correct
5 Correct 8 ms 10092 KB Output is correct
6 Correct 7 ms 10092 KB Output is correct
7 Correct 7 ms 10092 KB Output is correct
8 Correct 7 ms 10092 KB Output is correct
9 Correct 7 ms 10092 KB Output is correct
10 Correct 7 ms 9708 KB Output is correct
11 Correct 32 ms 18668 KB Output is correct
12 Correct 31 ms 18668 KB Output is correct
13 Correct 31 ms 18668 KB Output is correct
14 Correct 32 ms 18668 KB Output is correct
15 Correct 33 ms 18668 KB Output is correct
16 Correct 32 ms 18668 KB Output is correct
17 Correct 32 ms 18668 KB Output is correct
18 Correct 31 ms 18156 KB Output is correct
19 Correct 25 ms 17644 KB Output is correct
20 Correct 6 ms 9708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 381 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 9856 KB Output is correct
2 Runtime error 482 ms 262148 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -