답안 #402888

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
402888 2021-05-12T13:14:07 Z Fidisk Mountains (NOI20_mountains) C++14
24 / 100
457 ms 9176 KB
#include <bits/stdc++.h>
using namespace std;

#define oo 1e15
#define fi first
#define se second
#define sp(iiii) setprecision(iiii)
#define IO ios_base::sync_with_stdio(false); cin.tie(0)
#define ms(aaaa,xxxx) memset(aaaa,xxxx,sizeof(aaaa))
#define cntbit(xxxx) __builtin_popcount(xxxx)
#define getbit(xxxx,aaaa) ((xxxx>>(aaaa-1))&1)

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pair<int,int>,int> piii;
typedef pair<long long,long long> pll;
typedef pair<pair<long long,long long>,long long> plll;
typedef pair<pair<long long,long long>,pair<long long,long long>> pllll;
typedef pair<pair<long long,long long>,bool> pllb;

const ll base=361;
const ll mod=998244353;
const ld eps=1e-5;
const ll maxn=1e6;

struct segtree_ele{
    int val,l,r;
} segtree[10000009];

ll res;
int sizet,l[400009],a[400009],n,i,cnt;
vector<pii> g;

int getnode(int &x) {
    if (x==0) {
        sizet++;
        x=sizet;
        segtree[x]={0,0,0};
    }
    return x;
}

void update(int id,int l,int r,int u) {
    if (l>r||r<u||l>u) {
        return;
    }
    if (l==u&&r==u) {
        segtree[id].val++;
        return;
    }
    int mid=(r+l)/2;
    if (mid<u) {
        update(getnode(segtree[id].r),mid+1,r,u);
    }
    else {
        update(getnode(segtree[id].l),l,mid,u);
    }
    segtree[id].val=segtree[getnode(segtree[id].l)].val+segtree[getnode(segtree[id].r)].val;
}

int get(int id,int l,int r,int u,int v) {
    if (l>r||r<u||l>v) {
        return 0;
    }
    if (u<=l&&r<=v) {
        return segtree[id].val;
    }
    int mid=(r+l)/2;
    return get(getnode(segtree[id].l),l,mid,u,v)+get(getnode(segtree[id].r),mid+1,r,u,v);
}

int main(){
    IO;
    cin>>n;
    g.push_back({-1,0});
    for (i=1;i<=n;i++) {
        cin>>a[i];
        g.push_back({a[i],i});
    }
    sort(g.begin(),g.end());
    for (i=1;i<=n;i++) {
        if (g[i].fi!=g[i-1].fi) {
            cnt++;
        }
        a[g[i].se]=cnt;
    }
    sizet=0;
    getnode(a[0]);
    for (i=1;i<=n;i++) {
        //cout<<a[i]<<' ';
        l[i]=get(1,1,maxn,1,a[i]-1);
        update(1,1,maxn,a[i]);
    }
    //cout<<'\n';
    sizet=0;
    a[0]=0;
    getnode(a[0]);
    for (i=n;i>=1;i--) {
        //cout<<l[i]<<' '<<get(1,1,maxn,1,a[i]-1)<<'\n';
        res+=ll(l[i])*ll(get(1,1,maxn,1,a[i]-1));
        update(1,1,maxn,a[i]);
    }
    cout<<res<<'\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 124 ms 5092 KB Output is correct
3 Correct 132 ms 5080 KB Output is correct
4 Correct 134 ms 5040 KB Output is correct
5 Correct 130 ms 5136 KB Output is correct
6 Correct 127 ms 5128 KB Output is correct
7 Correct 125 ms 5052 KB Output is correct
8 Correct 128 ms 5128 KB Output is correct
9 Correct 128 ms 5164 KB Output is correct
10 Correct 129 ms 5044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 219 ms 6172 KB Output is correct
2 Correct 260 ms 6140 KB Output is correct
3 Correct 218 ms 6104 KB Output is correct
4 Correct 221 ms 6192 KB Output is correct
5 Correct 249 ms 6084 KB Output is correct
6 Correct 212 ms 6168 KB Output is correct
7 Correct 242 ms 6144 KB Output is correct
8 Correct 197 ms 6100 KB Output is correct
9 Correct 195 ms 6080 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 219 ms 6172 KB Output is correct
2 Correct 260 ms 6140 KB Output is correct
3 Correct 218 ms 6104 KB Output is correct
4 Correct 221 ms 6192 KB Output is correct
5 Correct 249 ms 6084 KB Output is correct
6 Correct 212 ms 6168 KB Output is correct
7 Correct 242 ms 6144 KB Output is correct
8 Correct 197 ms 6100 KB Output is correct
9 Correct 195 ms 6080 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 311 ms 6436 KB Output is correct
12 Correct 298 ms 6464 KB Output is correct
13 Correct 332 ms 6328 KB Output is correct
14 Correct 340 ms 6452 KB Output is correct
15 Correct 339 ms 6384 KB Output is correct
16 Correct 299 ms 6468 KB Output is correct
17 Correct 297 ms 6396 KB Output is correct
18 Correct 243 ms 6324 KB Output is correct
19 Correct 243 ms 6428 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 219 ms 6172 KB Output is correct
2 Correct 260 ms 6140 KB Output is correct
3 Correct 218 ms 6104 KB Output is correct
4 Correct 221 ms 6192 KB Output is correct
5 Correct 249 ms 6084 KB Output is correct
6 Correct 212 ms 6168 KB Output is correct
7 Correct 242 ms 6144 KB Output is correct
8 Correct 197 ms 6100 KB Output is correct
9 Correct 195 ms 6080 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 311 ms 6436 KB Output is correct
12 Correct 298 ms 6464 KB Output is correct
13 Correct 332 ms 6328 KB Output is correct
14 Correct 340 ms 6452 KB Output is correct
15 Correct 339 ms 6384 KB Output is correct
16 Correct 299 ms 6468 KB Output is correct
17 Correct 297 ms 6396 KB Output is correct
18 Correct 243 ms 6324 KB Output is correct
19 Correct 243 ms 6428 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 405 ms 9080 KB Output is correct
22 Correct 457 ms 9052 KB Output is correct
23 Correct 416 ms 9116 KB Output is correct
24 Correct 450 ms 9068 KB Output is correct
25 Correct 406 ms 9096 KB Output is correct
26 Correct 405 ms 9008 KB Output is correct
27 Correct 449 ms 8996 KB Output is correct
28 Correct 318 ms 9088 KB Output is correct
29 Correct 295 ms 9176 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 124 ms 5092 KB Output is correct
3 Correct 132 ms 5080 KB Output is correct
4 Correct 134 ms 5040 KB Output is correct
5 Correct 130 ms 5136 KB Output is correct
6 Correct 127 ms 5128 KB Output is correct
7 Correct 125 ms 5052 KB Output is correct
8 Correct 128 ms 5128 KB Output is correct
9 Correct 128 ms 5164 KB Output is correct
10 Correct 129 ms 5044 KB Output is correct
11 Correct 219 ms 6172 KB Output is correct
12 Correct 260 ms 6140 KB Output is correct
13 Correct 218 ms 6104 KB Output is correct
14 Correct 221 ms 6192 KB Output is correct
15 Correct 249 ms 6084 KB Output is correct
16 Correct 212 ms 6168 KB Output is correct
17 Correct 242 ms 6144 KB Output is correct
18 Correct 197 ms 6100 KB Output is correct
19 Correct 195 ms 6080 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 311 ms 6436 KB Output is correct
22 Correct 298 ms 6464 KB Output is correct
23 Correct 332 ms 6328 KB Output is correct
24 Correct 340 ms 6452 KB Output is correct
25 Correct 339 ms 6384 KB Output is correct
26 Correct 299 ms 6468 KB Output is correct
27 Correct 297 ms 6396 KB Output is correct
28 Correct 243 ms 6324 KB Output is correct
29 Correct 243 ms 6428 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Incorrect 1 ms 332 KB Output isn't correct
32 Halted 0 ms 0 KB -