답안 #225230

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
225230 2020-04-19T18:28:16 Z PedroBigMan Mountains (NOI20_mountains) C++14
100 / 100
784 ms 71740 KB
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <deque>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define REP(i,a,b) for(ll i=a; i<b; i++)
#define pb push_back
#define mp make_pair
#define pl pair<ll,ll>
#define ff first
#define ss second
#define INF 100000000000000000LL
ll insig;
#define In(vecBRO, LENBRO) REP(IBRO,0,LENBRO) {cin>>insig; vecBRO.pb(insig);}
void Out(vector<ll> x) {REP(i,0,x.size()) {cout<<x[i]<<" ";} cout<<endl;}

class ST
{
    public:
    ll N; 
    
    class SV //segment values
    {
        public:
        ll a;
        SV() {a=0LL;}
        SV(ll x) {a=x;}
    };
    
    SV op(SV A, SV B)
    {
        SV X(A.a+B.a);
        return X;
    }
    
    SV neut;
    
    vector<SV> ar; vector<SV> p;
    
    ST(vector<ll> arr)
    {
        N = (ll) 1<<(ll) ceil(log2(arr.size()));
        REP(i,0,arr.size()) {SV X(arr[i]); ar.pb(X);} 
        REP(i,arr.size(),N) {ar.pb(neut);}
        REP(i,0,N) {p.pb(neut);}
        REP(i,0,N) {p.pb(ar[i]);}
        ll cur = N-1;
        while(cur>0)
        {
            p[cur]=op(p[2*cur],p[2*cur+1]);
            cur--;
        }
    }
    
    SV query(ll a,ll b, ll c, ll x, ll y) //c=current node, starting in 1, a,b=range of query, x,y=range of node c in the array down, x,y from 0 to N-1. query(a,b)->query(a,b,1,0,N-1)
    {
        if(y<a || x>b) {return neut;}
        if(x>=a && y<=b) {return p[c];}
        ll mid=(x+y)/2;
        return op(query(a,b,2*c,x,mid),query(a,b,2*c+1,mid+1,y));
    }
    
    void update(SV s, ll a, ll c, ll x, ll y) //position a in 0,N-1 gets +s
    {
        if(y<a || x>a) {return ;}
        p[c]=op(s,p[c]);
        if(c==a+N) {ar[a]=op(ar[a],s); return;}
        ll mid=(x+y)/2;
        update(s,a,2*c,x,mid); update(s,a,2*c+1,mid+1,y);
    }
};

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    ll N; cin>>N; vector<ll> h; In(h,N); 
    vector<ll> a=h; sort(a.begin(),a.end()); map<ll,ll> m; ll cnt=0LL;
    REP(i,0,N) 
    {
        if(i>0 && a[i]==a[i-1]) {continue;}
        m[a[i]]=cnt; cnt++;
    }
    REP(i,0,N) {h[i]=m[h[i]];}
    vector<ll> xx; REP(i,0,N) {xx.pb(0LL);}
    vector<ll> v1,v2; REP(i,0,N) {v1.pb(0LL); v2.pb(0LL);}
    ST S1(xx); 
    REP(i,0,N)
    {
        ST::SV X(1LL);
        S1.update(X,h[i],1,0,S1.N-1);
        if(h[i]>=1LL) {v1[i]=S1.query(0,h[i]-1,1,0,S1.N-1).a;}
    }
    ST S2(xx);
    for(ll i=N-1;i>=0;i--)
    {
        ST::SV X(1LL);
        S2.update(X,h[i],1,0,S2.N-1);
        if(h[i]>=1) {v2[i]=S2.query(0,h[i]-1,1,0,S2.N-1).a;}
    }
    ll ans=0LL;
    REP(i,0,N) {ans+=v1[i]*v2[i];}
    cout<<ans<<endl;
    return 0;
}

Compilation message

Mountains.cpp: In function 'void Out(std::vector<long long int>)':
Mountains.cpp:14:33: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define REP(i,a,b) for(ll i=a; i<b; i++)
Mountains.cpp:23:29:
 void Out(vector<ll> x) {REP(i,0,x.size()) {cout<<x[i]<<" ";} cout<<endl;}
                             ~~~~~~~~~~~~
Mountains.cpp:23:25: note: in expansion of macro 'REP'
 void Out(vector<ll> x) {REP(i,0,x.size()) {cout<<x[i]<<" ";} cout<<endl;}
                         ^~~
Mountains.cpp: In constructor 'ST::ST(std::vector<long long int>)':
Mountains.cpp:14:33: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define REP(i,a,b) for(ll i=a; i<b; i++)
Mountains.cpp:51:13:
         REP(i,0,arr.size()) {SV X(arr[i]); ar.pb(X);} 
             ~~~~~~~~~~~~~~       
Mountains.cpp:51:9: note: in expansion of macro 'REP'
         REP(i,0,arr.size()) {SV X(arr[i]); ar.pb(X);} 
         ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 379 ms 71612 KB Output is correct
3 Correct 396 ms 71740 KB Output is correct
4 Correct 386 ms 71616 KB Output is correct
5 Correct 386 ms 71740 KB Output is correct
6 Correct 382 ms 71608 KB Output is correct
7 Correct 391 ms 71608 KB Output is correct
8 Correct 390 ms 71612 KB Output is correct
9 Correct 329 ms 62648 KB Output is correct
10 Correct 327 ms 62664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 177 ms 47924 KB Output is correct
2 Correct 180 ms 47928 KB Output is correct
3 Correct 174 ms 47924 KB Output is correct
4 Correct 172 ms 47920 KB Output is correct
5 Correct 172 ms 48052 KB Output is correct
6 Correct 171 ms 48016 KB Output is correct
7 Correct 169 ms 47924 KB Output is correct
8 Correct 153 ms 47924 KB Output is correct
9 Correct 168 ms 47932 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 177 ms 47924 KB Output is correct
2 Correct 180 ms 47928 KB Output is correct
3 Correct 174 ms 47924 KB Output is correct
4 Correct 172 ms 47920 KB Output is correct
5 Correct 172 ms 48052 KB Output is correct
6 Correct 171 ms 48016 KB Output is correct
7 Correct 169 ms 47924 KB Output is correct
8 Correct 153 ms 47924 KB Output is correct
9 Correct 168 ms 47932 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 261 ms 48216 KB Output is correct
12 Correct 258 ms 48184 KB Output is correct
13 Correct 254 ms 48180 KB Output is correct
14 Correct 252 ms 48188 KB Output is correct
15 Correct 261 ms 48316 KB Output is correct
16 Correct 266 ms 48184 KB Output is correct
17 Correct 255 ms 48184 KB Output is correct
18 Correct 203 ms 48188 KB Output is correct
19 Correct 200 ms 48184 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 512 KB Output is correct
4 Correct 5 ms 512 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 512 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 512 KB Output is correct
4 Correct 5 ms 512 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 512 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 19 ms 2684 KB Output is correct
12 Correct 18 ms 2684 KB Output is correct
13 Correct 20 ms 2684 KB Output is correct
14 Correct 18 ms 2684 KB Output is correct
15 Correct 22 ms 2812 KB Output is correct
16 Correct 18 ms 2812 KB Output is correct
17 Correct 18 ms 2812 KB Output is correct
18 Correct 16 ms 2216 KB Output is correct
19 Correct 13 ms 2044 KB Output is correct
20 Correct 4 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 177 ms 47924 KB Output is correct
2 Correct 180 ms 47928 KB Output is correct
3 Correct 174 ms 47924 KB Output is correct
4 Correct 172 ms 47920 KB Output is correct
5 Correct 172 ms 48052 KB Output is correct
6 Correct 171 ms 48016 KB Output is correct
7 Correct 169 ms 47924 KB Output is correct
8 Correct 153 ms 47924 KB Output is correct
9 Correct 168 ms 47932 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 261 ms 48216 KB Output is correct
12 Correct 258 ms 48184 KB Output is correct
13 Correct 254 ms 48180 KB Output is correct
14 Correct 252 ms 48188 KB Output is correct
15 Correct 261 ms 48316 KB Output is correct
16 Correct 266 ms 48184 KB Output is correct
17 Correct 255 ms 48184 KB Output is correct
18 Correct 203 ms 48188 KB Output is correct
19 Correct 200 ms 48184 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 471 ms 55004 KB Output is correct
22 Correct 460 ms 54968 KB Output is correct
23 Correct 469 ms 54968 KB Output is correct
24 Correct 467 ms 54964 KB Output is correct
25 Correct 454 ms 54960 KB Output is correct
26 Correct 484 ms 54972 KB Output is correct
27 Correct 449 ms 54972 KB Output is correct
28 Correct 278 ms 54964 KB Output is correct
29 Correct 268 ms 54968 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 379 ms 71612 KB Output is correct
3 Correct 396 ms 71740 KB Output is correct
4 Correct 386 ms 71616 KB Output is correct
5 Correct 386 ms 71740 KB Output is correct
6 Correct 382 ms 71608 KB Output is correct
7 Correct 391 ms 71608 KB Output is correct
8 Correct 390 ms 71612 KB Output is correct
9 Correct 329 ms 62648 KB Output is correct
10 Correct 327 ms 62664 KB Output is correct
11 Correct 177 ms 47924 KB Output is correct
12 Correct 180 ms 47928 KB Output is correct
13 Correct 174 ms 47924 KB Output is correct
14 Correct 172 ms 47920 KB Output is correct
15 Correct 172 ms 48052 KB Output is correct
16 Correct 171 ms 48016 KB Output is correct
17 Correct 169 ms 47924 KB Output is correct
18 Correct 153 ms 47924 KB Output is correct
19 Correct 168 ms 47932 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 261 ms 48216 KB Output is correct
22 Correct 258 ms 48184 KB Output is correct
23 Correct 254 ms 48180 KB Output is correct
24 Correct 252 ms 48188 KB Output is correct
25 Correct 261 ms 48316 KB Output is correct
26 Correct 266 ms 48184 KB Output is correct
27 Correct 255 ms 48184 KB Output is correct
28 Correct 203 ms 48188 KB Output is correct
29 Correct 200 ms 48184 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 5 ms 512 KB Output is correct
34 Correct 5 ms 512 KB Output is correct
35 Correct 5 ms 384 KB Output is correct
36 Correct 5 ms 512 KB Output is correct
37 Correct 5 ms 384 KB Output is correct
38 Correct 5 ms 384 KB Output is correct
39 Correct 5 ms 384 KB Output is correct
40 Correct 4 ms 384 KB Output is correct
41 Correct 19 ms 2684 KB Output is correct
42 Correct 18 ms 2684 KB Output is correct
43 Correct 20 ms 2684 KB Output is correct
44 Correct 18 ms 2684 KB Output is correct
45 Correct 22 ms 2812 KB Output is correct
46 Correct 18 ms 2812 KB Output is correct
47 Correct 18 ms 2812 KB Output is correct
48 Correct 16 ms 2216 KB Output is correct
49 Correct 13 ms 2044 KB Output is correct
50 Correct 4 ms 384 KB Output is correct
51 Correct 471 ms 55004 KB Output is correct
52 Correct 460 ms 54968 KB Output is correct
53 Correct 469 ms 54968 KB Output is correct
54 Correct 467 ms 54964 KB Output is correct
55 Correct 454 ms 54960 KB Output is correct
56 Correct 484 ms 54972 KB Output is correct
57 Correct 449 ms 54972 KB Output is correct
58 Correct 278 ms 54964 KB Output is correct
59 Correct 268 ms 54968 KB Output is correct
60 Correct 5 ms 384 KB Output is correct
61 Correct 778 ms 71740 KB Output is correct
62 Correct 784 ms 71736 KB Output is correct
63 Correct 772 ms 71740 KB Output is correct
64 Correct 762 ms 71612 KB Output is correct
65 Correct 752 ms 71740 KB Output is correct
66 Correct 761 ms 71608 KB Output is correct
67 Correct 773 ms 71612 KB Output is correct
68 Correct 664 ms 62740 KB Output is correct
69 Correct 578 ms 57220 KB Output is correct
70 Correct 5 ms 384 KB Output is correct