Submission #320651

# Submission time Handle Problem Language Result Execution time Memory
320651 2020-11-09T12:01:24 Z LifeHappen__ Mountains (NOI20_mountains) C++14
64 / 100
21 ms 4224 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=1e5+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 1 ms 1132 KB Output is correct
2 Runtime error 21 ms 4224 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 10 ms 2544 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 10 ms 2544 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1132 KB Output is correct
2 Correct 1 ms 1152 KB Output is correct
3 Correct 1 ms 1144 KB Output is correct
4 Correct 1 ms 1132 KB Output is correct
5 Correct 1 ms 1132 KB Output is correct
6 Correct 1 ms 1132 KB Output is correct
7 Correct 1 ms 1132 KB Output is correct
8 Correct 1 ms 1152 KB Output is correct
9 Correct 1 ms 1132 KB Output is correct
10 Correct 1 ms 1132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1132 KB Output is correct
2 Correct 1 ms 1152 KB Output is correct
3 Correct 1 ms 1144 KB Output is correct
4 Correct 1 ms 1132 KB Output is correct
5 Correct 1 ms 1132 KB Output is correct
6 Correct 1 ms 1132 KB Output is correct
7 Correct 1 ms 1132 KB Output is correct
8 Correct 1 ms 1152 KB Output is correct
9 Correct 1 ms 1132 KB Output is correct
10 Correct 1 ms 1132 KB Output is correct
11 Correct 5 ms 1772 KB Output is correct
12 Correct 5 ms 1772 KB Output is correct
13 Correct 5 ms 1772 KB Output is correct
14 Correct 5 ms 1764 KB Output is correct
15 Correct 5 ms 1772 KB Output is correct
16 Correct 5 ms 1772 KB Output is correct
17 Correct 5 ms 1772 KB Output is correct
18 Correct 5 ms 1772 KB Output is correct
19 Correct 4 ms 1644 KB Output is correct
20 Correct 1 ms 1132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 10 ms 2544 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1132 KB Output is correct
2 Runtime error 21 ms 4224 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -