Submission #320652

# Submission time Handle Problem Language Result Execution time Memory
320652 2020-11-09T12:01:57 Z LifeHappen__ Mountains (NOI20_mountains) C++14
100 / 100
207 ms 18020 KB
#include<bits/stdc++.h>
#define int long long
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
typedef unsigned long long ull;
#define forinc(a,b,c) for(int a=b, _c=c; a<=_c; ++a)
#define fordec(a,b,c) for(int a=b, _c=c; a>=_c; --a)
#define forv(a,b) for(auto &a:b)
#define fasty ios_base::sync_with_stdio(false),cin.tie(0)
#define ar array
#define ii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define all(a) begin(a),end(a)
#define reset(f,x) memset(f,x,sizeof(f))
#define bit(x,i) (x>>(i-1)&1ll)
#define on(x,i) (x|(1ll<<(i-1)))
#define off(x,i) (x&~(1ll<<(i-1)))

const int N=3e5+5;
int n,a[N];
int it[N];
int f[N],g[N];

void upd(int i,int val){
   for(; i<=n; i+=i&-i) it[i]+=val;
}
int get(int i){
   int b=0;
   for(; i; i-=i&-i) b+=it[i];
   return b;
}

int32_t main(){
   fasty;

   cin>>n;
   forinc(i,1,n) cin>>a[i];
   vector<int> val;
   forinc(i,1,n) val.pb(a[i]); sort(all(val)); val.erase(unique(all(val)), end(val));
   forinc(i,1,n) a[i]=lower_bound(all(val),a[i])-begin(val)+1;

   forinc(i,1,n){
      f[i]=get(a[i]-1);
      upd(a[i],1);
   }
   reset(it,0);
   fordec(i,n,1){
      g[i]=get(a[i]-1);
      upd(a[i],1);
   }
   int ans=0;
   forinc(i,1,n) ans+=g[i]*f[i];
   cout<<ans<<'\n';
}

Compilation message

Mountains.cpp: In function 'int32_t main()':
Mountains.cpp:7:23: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
    7 | #define forinc(a,b,c) for(int a=b, _c=c; a<=_c; ++a)
      |                       ^~~
Mountains.cpp:43:4: note: in expansion of macro 'forinc'
   43 |    forinc(i,1,n) val.pb(a[i]); sort(all(val)); val.erase(unique(all(val)), end(val));
      |    ^~~~~~
Mountains.cpp:43:32: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   43 |    forinc(i,1,n) val.pb(a[i]); sort(all(val)); val.erase(unique(all(val)), end(val));
      |                                ^~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Correct 109 ms 15696 KB Output is correct
3 Correct 110 ms 17744 KB Output is correct
4 Correct 109 ms 17740 KB Output is correct
5 Correct 107 ms 17744 KB Output is correct
6 Correct 109 ms 17744 KB Output is correct
7 Correct 109 ms 17736 KB Output is correct
8 Correct 107 ms 17888 KB Output is correct
9 Correct 111 ms 18020 KB Output is correct
10 Correct 113 ms 18016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 81 ms 12496 KB Output is correct
2 Correct 72 ms 12880 KB Output is correct
3 Correct 72 ms 12880 KB Output is correct
4 Correct 71 ms 12884 KB Output is correct
5 Correct 72 ms 12904 KB Output is correct
6 Correct 72 ms 12880 KB Output is correct
7 Correct 72 ms 13008 KB Output is correct
8 Correct 67 ms 12752 KB Output is correct
9 Correct 67 ms 12880 KB Output is correct
10 Correct 2 ms 2668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 81 ms 12496 KB Output is correct
2 Correct 72 ms 12880 KB Output is correct
3 Correct 72 ms 12880 KB Output is correct
4 Correct 71 ms 12884 KB Output is correct
5 Correct 72 ms 12904 KB Output is correct
6 Correct 72 ms 12880 KB Output is correct
7 Correct 72 ms 13008 KB Output is correct
8 Correct 67 ms 12752 KB Output is correct
9 Correct 67 ms 12880 KB Output is correct
10 Correct 2 ms 2668 KB Output is correct
11 Correct 83 ms 13136 KB Output is correct
12 Correct 84 ms 13136 KB Output is correct
13 Correct 83 ms 13136 KB Output is correct
14 Correct 84 ms 13136 KB Output is correct
15 Correct 83 ms 13140 KB Output is correct
16 Correct 82 ms 13136 KB Output is correct
17 Correct 84 ms 13132 KB Output is correct
18 Correct 63 ms 13136 KB Output is correct
19 Correct 62 ms 13132 KB Output is correct
20 Correct 2 ms 2668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2796 KB Output is correct
2 Correct 2 ms 2668 KB Output is correct
3 Correct 2 ms 2668 KB Output is correct
4 Correct 2 ms 2668 KB Output is correct
5 Correct 2 ms 2668 KB Output is correct
6 Correct 2 ms 2668 KB Output is correct
7 Correct 2 ms 2668 KB Output is correct
8 Correct 2 ms 2668 KB Output is correct
9 Correct 2 ms 2668 KB Output is correct
10 Correct 2 ms 2668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2796 KB Output is correct
2 Correct 2 ms 2668 KB Output is correct
3 Correct 2 ms 2668 KB Output is correct
4 Correct 2 ms 2668 KB Output is correct
5 Correct 2 ms 2668 KB Output is correct
6 Correct 2 ms 2668 KB Output is correct
7 Correct 2 ms 2668 KB Output is correct
8 Correct 2 ms 2668 KB Output is correct
9 Correct 2 ms 2668 KB Output is correct
10 Correct 2 ms 2668 KB Output is correct
11 Correct 6 ms 3180 KB Output is correct
12 Correct 6 ms 3180 KB Output is correct
13 Correct 6 ms 3180 KB Output is correct
14 Correct 6 ms 3180 KB Output is correct
15 Correct 6 ms 3180 KB Output is correct
16 Correct 6 ms 3180 KB Output is correct
17 Correct 6 ms 3180 KB Output is correct
18 Correct 6 ms 3180 KB Output is correct
19 Correct 5 ms 3180 KB Output is correct
20 Correct 2 ms 2668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 81 ms 12496 KB Output is correct
2 Correct 72 ms 12880 KB Output is correct
3 Correct 72 ms 12880 KB Output is correct
4 Correct 71 ms 12884 KB Output is correct
5 Correct 72 ms 12904 KB Output is correct
6 Correct 72 ms 12880 KB Output is correct
7 Correct 72 ms 13008 KB Output is correct
8 Correct 67 ms 12752 KB Output is correct
9 Correct 67 ms 12880 KB Output is correct
10 Correct 2 ms 2668 KB Output is correct
11 Correct 83 ms 13136 KB Output is correct
12 Correct 84 ms 13136 KB Output is correct
13 Correct 83 ms 13136 KB Output is correct
14 Correct 84 ms 13136 KB Output is correct
15 Correct 83 ms 13140 KB Output is correct
16 Correct 82 ms 13136 KB Output is correct
17 Correct 84 ms 13132 KB Output is correct
18 Correct 63 ms 13136 KB Output is correct
19 Correct 62 ms 13132 KB Output is correct
20 Correct 2 ms 2668 KB Output is correct
21 Correct 132 ms 13912 KB Output is correct
22 Correct 135 ms 13904 KB Output is correct
23 Correct 131 ms 14160 KB Output is correct
24 Correct 132 ms 14032 KB Output is correct
25 Correct 134 ms 14032 KB Output is correct
26 Correct 133 ms 13904 KB Output is correct
27 Correct 133 ms 13904 KB Output is correct
28 Correct 81 ms 13904 KB Output is correct
29 Correct 80 ms 13904 KB Output is correct
30 Correct 2 ms 2668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Correct 109 ms 15696 KB Output is correct
3 Correct 110 ms 17744 KB Output is correct
4 Correct 109 ms 17740 KB Output is correct
5 Correct 107 ms 17744 KB Output is correct
6 Correct 109 ms 17744 KB Output is correct
7 Correct 109 ms 17736 KB Output is correct
8 Correct 107 ms 17888 KB Output is correct
9 Correct 111 ms 18020 KB Output is correct
10 Correct 113 ms 18016 KB Output is correct
11 Correct 81 ms 12496 KB Output is correct
12 Correct 72 ms 12880 KB Output is correct
13 Correct 72 ms 12880 KB Output is correct
14 Correct 71 ms 12884 KB Output is correct
15 Correct 72 ms 12904 KB Output is correct
16 Correct 72 ms 12880 KB Output is correct
17 Correct 72 ms 13008 KB Output is correct
18 Correct 67 ms 12752 KB Output is correct
19 Correct 67 ms 12880 KB Output is correct
20 Correct 2 ms 2668 KB Output is correct
21 Correct 83 ms 13136 KB Output is correct
22 Correct 84 ms 13136 KB Output is correct
23 Correct 83 ms 13136 KB Output is correct
24 Correct 84 ms 13136 KB Output is correct
25 Correct 83 ms 13140 KB Output is correct
26 Correct 82 ms 13136 KB Output is correct
27 Correct 84 ms 13132 KB Output is correct
28 Correct 63 ms 13136 KB Output is correct
29 Correct 62 ms 13132 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 2668 KB Output is correct
33 Correct 2 ms 2668 KB Output is correct
34 Correct 2 ms 2668 KB Output is correct
35 Correct 2 ms 2668 KB Output is correct
36 Correct 2 ms 2668 KB Output is correct
37 Correct 2 ms 2668 KB Output is correct
38 Correct 2 ms 2668 KB Output is correct
39 Correct 2 ms 2668 KB Output is correct
40 Correct 2 ms 2668 KB Output is correct
41 Correct 6 ms 3180 KB Output is correct
42 Correct 6 ms 3180 KB Output is correct
43 Correct 6 ms 3180 KB Output is correct
44 Correct 6 ms 3180 KB Output is correct
45 Correct 6 ms 3180 KB Output is correct
46 Correct 6 ms 3180 KB Output is correct
47 Correct 6 ms 3180 KB Output is correct
48 Correct 6 ms 3180 KB Output is correct
49 Correct 5 ms 3180 KB Output is correct
50 Correct 2 ms 2668 KB Output is correct
51 Correct 132 ms 13912 KB Output is correct
52 Correct 135 ms 13904 KB Output is correct
53 Correct 131 ms 14160 KB Output is correct
54 Correct 132 ms 14032 KB Output is correct
55 Correct 134 ms 14032 KB Output is correct
56 Correct 133 ms 13904 KB Output is correct
57 Correct 133 ms 13904 KB Output is correct
58 Correct 81 ms 13904 KB Output is correct
59 Correct 80 ms 13904 KB Output is correct
60 Correct 2 ms 2668 KB Output is correct
61 Correct 169 ms 17744 KB Output is correct
62 Correct 167 ms 17872 KB Output is correct
63 Correct 170 ms 17872 KB Output is correct
64 Correct 175 ms 17872 KB Output is correct
65 Correct 171 ms 17744 KB Output is correct
66 Correct 172 ms 17892 KB Output is correct
67 Correct 207 ms 17744 KB Output is correct
68 Correct 170 ms 17744 KB Output is correct
69 Correct 137 ms 14032 KB Output is correct
70 Correct 2 ms 2668 KB Output is correct