답안 #331390

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
331390 2020-11-28T09:32:31 Z Sho10 Mountains (NOI20_mountains) C++14
100 / 100
537 ms 36572 KB
#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho10
#define ll long long
#define double long double
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 1000007
#define PI 3.14159265359
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005ll
#define CODE_START  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll n,pref[300005],suf[300005],a[300005],bit[300005];
vector<ll>v;
map<ll,ll>m;
void update(ll pos,ll val){
for(;pos<=n;pos+=pos&(-pos)){
    bit[pos]+=val;
}
}
ll query(ll pos){
ll res=0;
for(;pos;pos-=pos&(-pos)){
    res+=bit[pos];
}
return res;
}
int32_t main(){
CODE_START
cin>>n;
for(ll i=1;i<=n;i++)
{
    cin>>a[i];
    v.pb(a[i]);
}
sort(v.begin(),v.end());
ll s1=1;
for(ll i=0;i<v.size();i++)
if(i==0){
    m[v[i]]=s1++;
}else if(v[i]==v[i-1]){
continue;
}else {
m[v[i]]=s1++;
}
for(ll i=1;i<=n;i++)
{
a[i]=m[a[i]];
}
for(ll i=1;i<=n;i++){
    pref[i]=query(a[i]-1);
    update(a[i],1ll);
}
memset(bit,0,sizeof(bit));
for(ll i=n;i>=1;i--)
{
    suf[i]=query(a[i]-1);
    update(a[i],1ll);
}
ll ans=0;
for(ll i=1;i<=n;i++)
{
    ans+=pref[i]*suf[i];
}
rc(ans);
}

Compilation message

Mountains.cpp: In function 'int32_t main()':
Mountains.cpp:46:13: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 | for(ll i=0;i<v.size();i++)
      |            ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Correct 200 ms 36444 KB Output is correct
3 Correct 200 ms 36444 KB Output is correct
4 Correct 205 ms 36464 KB Output is correct
5 Correct 199 ms 36444 KB Output is correct
6 Correct 199 ms 36444 KB Output is correct
7 Correct 212 ms 36572 KB Output is correct
8 Correct 203 ms 36444 KB Output is correct
9 Correct 166 ms 27356 KB Output is correct
10 Correct 164 ms 27484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 72 ms 12764 KB Output is correct
2 Correct 71 ms 12764 KB Output is correct
3 Correct 72 ms 12764 KB Output is correct
4 Correct 72 ms 12764 KB Output is correct
5 Correct 70 ms 12764 KB Output is correct
6 Correct 81 ms 12848 KB Output is correct
7 Correct 74 ms 12764 KB Output is correct
8 Correct 66 ms 12764 KB Output is correct
9 Correct 69 ms 12764 KB Output is correct
10 Correct 2 ms 2668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 72 ms 12764 KB Output is correct
2 Correct 71 ms 12764 KB Output is correct
3 Correct 72 ms 12764 KB Output is correct
4 Correct 72 ms 12764 KB Output is correct
5 Correct 70 ms 12764 KB Output is correct
6 Correct 81 ms 12848 KB Output is correct
7 Correct 74 ms 12764 KB Output is correct
8 Correct 66 ms 12764 KB Output is correct
9 Correct 69 ms 12764 KB Output is correct
10 Correct 2 ms 2668 KB Output is correct
11 Correct 83 ms 13020 KB Output is correct
12 Correct 83 ms 13040 KB Output is correct
13 Correct 83 ms 13020 KB Output is correct
14 Correct 84 ms 13020 KB Output is correct
15 Correct 81 ms 13020 KB Output is correct
16 Correct 85 ms 13020 KB Output is correct
17 Correct 84 ms 13148 KB Output is correct
18 Correct 65 ms 13020 KB Output is correct
19 Correct 64 ms 13148 KB Output is correct
20 Correct 2 ms 2668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2796 KB Output is correct
2 Correct 2 ms 2796 KB Output is correct
3 Correct 2 ms 2796 KB Output is correct
4 Correct 2 ms 2796 KB Output is correct
5 Correct 2 ms 2796 KB Output is correct
6 Correct 2 ms 2796 KB Output is correct
7 Correct 3 ms 2796 KB Output is correct
8 Correct 2 ms 2796 KB Output is correct
9 Correct 2 ms 2796 KB Output is correct
10 Correct 2 ms 2668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2796 KB Output is correct
2 Correct 2 ms 2796 KB Output is correct
3 Correct 2 ms 2796 KB Output is correct
4 Correct 2 ms 2796 KB Output is correct
5 Correct 2 ms 2796 KB Output is correct
6 Correct 2 ms 2796 KB Output is correct
7 Correct 3 ms 2796 KB Output is correct
8 Correct 2 ms 2796 KB Output is correct
9 Correct 2 ms 2796 KB Output is correct
10 Correct 2 ms 2668 KB Output is correct
11 Correct 8 ms 3820 KB Output is correct
12 Correct 9 ms 3948 KB Output is correct
13 Correct 8 ms 3820 KB Output is correct
14 Correct 9 ms 3820 KB Output is correct
15 Correct 11 ms 3820 KB Output is correct
16 Correct 9 ms 3820 KB Output is correct
17 Correct 8 ms 3820 KB Output is correct
18 Correct 7 ms 3436 KB Output is correct
19 Correct 5 ms 3180 KB Output is correct
20 Correct 2 ms 2668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 72 ms 12764 KB Output is correct
2 Correct 71 ms 12764 KB Output is correct
3 Correct 72 ms 12764 KB Output is correct
4 Correct 72 ms 12764 KB Output is correct
5 Correct 70 ms 12764 KB Output is correct
6 Correct 81 ms 12848 KB Output is correct
7 Correct 74 ms 12764 KB Output is correct
8 Correct 66 ms 12764 KB Output is correct
9 Correct 69 ms 12764 KB Output is correct
10 Correct 2 ms 2668 KB Output is correct
11 Correct 83 ms 13020 KB Output is correct
12 Correct 83 ms 13040 KB Output is correct
13 Correct 83 ms 13020 KB Output is correct
14 Correct 84 ms 13020 KB Output is correct
15 Correct 81 ms 13020 KB Output is correct
16 Correct 85 ms 13020 KB Output is correct
17 Correct 84 ms 13148 KB Output is correct
18 Correct 65 ms 13020 KB Output is correct
19 Correct 64 ms 13148 KB Output is correct
20 Correct 2 ms 2668 KB Output is correct
21 Correct 264 ms 19960 KB Output is correct
22 Correct 265 ms 19804 KB Output is correct
23 Correct 261 ms 19820 KB Output is correct
24 Correct 266 ms 19824 KB Output is correct
25 Correct 270 ms 19804 KB Output is correct
26 Correct 263 ms 19808 KB Output is correct
27 Correct 273 ms 19804 KB Output is correct
28 Correct 112 ms 19804 KB Output is correct
29 Correct 112 ms 19804 KB Output is correct
30 Correct 2 ms 2668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Correct 200 ms 36444 KB Output is correct
3 Correct 200 ms 36444 KB Output is correct
4 Correct 205 ms 36464 KB Output is correct
5 Correct 199 ms 36444 KB Output is correct
6 Correct 199 ms 36444 KB Output is correct
7 Correct 212 ms 36572 KB Output is correct
8 Correct 203 ms 36444 KB Output is correct
9 Correct 166 ms 27356 KB Output is correct
10 Correct 164 ms 27484 KB Output is correct
11 Correct 72 ms 12764 KB Output is correct
12 Correct 71 ms 12764 KB Output is correct
13 Correct 72 ms 12764 KB Output is correct
14 Correct 72 ms 12764 KB Output is correct
15 Correct 70 ms 12764 KB Output is correct
16 Correct 81 ms 12848 KB Output is correct
17 Correct 74 ms 12764 KB Output is correct
18 Correct 66 ms 12764 KB Output is correct
19 Correct 69 ms 12764 KB Output is correct
20 Correct 2 ms 2668 KB Output is correct
21 Correct 83 ms 13020 KB Output is correct
22 Correct 83 ms 13040 KB Output is correct
23 Correct 83 ms 13020 KB Output is correct
24 Correct 84 ms 13020 KB Output is correct
25 Correct 81 ms 13020 KB Output is correct
26 Correct 85 ms 13020 KB Output is correct
27 Correct 84 ms 13148 KB Output is correct
28 Correct 65 ms 13020 KB Output is correct
29 Correct 64 ms 13148 KB Output is correct
30 Correct 2 ms 2668 KB Output is correct
31 Correct 2 ms 2796 KB Output is correct
32 Correct 2 ms 2796 KB Output is correct
33 Correct 2 ms 2796 KB Output is correct
34 Correct 2 ms 2796 KB Output is correct
35 Correct 2 ms 2796 KB Output is correct
36 Correct 2 ms 2796 KB Output is correct
37 Correct 3 ms 2796 KB Output is correct
38 Correct 2 ms 2796 KB Output is correct
39 Correct 2 ms 2796 KB Output is correct
40 Correct 2 ms 2668 KB Output is correct
41 Correct 8 ms 3820 KB Output is correct
42 Correct 9 ms 3948 KB Output is correct
43 Correct 8 ms 3820 KB Output is correct
44 Correct 9 ms 3820 KB Output is correct
45 Correct 11 ms 3820 KB Output is correct
46 Correct 9 ms 3820 KB Output is correct
47 Correct 8 ms 3820 KB Output is correct
48 Correct 7 ms 3436 KB Output is correct
49 Correct 5 ms 3180 KB Output is correct
50 Correct 2 ms 2668 KB Output is correct
51 Correct 264 ms 19960 KB Output is correct
52 Correct 265 ms 19804 KB Output is correct
53 Correct 261 ms 19820 KB Output is correct
54 Correct 266 ms 19824 KB Output is correct
55 Correct 270 ms 19804 KB Output is correct
56 Correct 263 ms 19808 KB Output is correct
57 Correct 273 ms 19804 KB Output is correct
58 Correct 112 ms 19804 KB Output is correct
59 Correct 112 ms 19804 KB Output is correct
60 Correct 2 ms 2668 KB Output is correct
61 Correct 518 ms 36572 KB Output is correct
62 Correct 509 ms 36444 KB Output is correct
63 Correct 521 ms 36444 KB Output is correct
64 Correct 537 ms 36476 KB Output is correct
65 Correct 519 ms 36364 KB Output is correct
66 Correct 528 ms 36364 KB Output is correct
67 Correct 517 ms 36444 KB Output is correct
68 Correct 405 ms 27356 KB Output is correct
69 Correct 326 ms 22108 KB Output is correct
70 Correct 2 ms 2668 KB Output is correct