CSES - Datatähti 2017 alku - Results
Submission details
Task:Järjestys
Sender:ollpu
Submission time:2016-10-05 16:06:52 +0300
Language:C++
Status:COMPILE ERROR

Compiler report

input/code.cpp:4:12: error: array bound is not an integer constant before ']' token
 int sp[N<<1];
            ^
input/code.cpp: In function 'int main()':
input/code.cpp:18:22: error: 'sp' was not declared in this scope
    if (a%2) cur_i -= sp[a++];
                      ^
input/code.cpp:19:25: error: 'sp' was not declared in this scope
    if (!(b%2)) cur_i -= sp[b--];
                         ^
input/code.cpp:24:4: error: 'sp' was not declared in this scope
    sp[j]++;
    ^

Code

#include <iostream>
static long N = 1<<17;
using namespace std;
int sp[N<<1];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  int t[n];
  int mloc[n+1];
  for (int i = 0; i < n; ++i) cin >> t[i], mloc[t[i]] = i;
  cout << 4*n << endl;
  for (int i = 0; i < n; ++i) {
    int cur_i = mloc[n-i];
    int a = N, b = N+cur_i;
    while (a <= b) {
			if (a%2) cur_i -= sp[a++];
			if (!(b%2)) cur_i -= sp[b--];
			a >>= 1; b >>= 1;
		}
    int j = N+mloc[n-i];
		for (; j >= 1; j >>= 1) {
			sp[j]++;
		}
    cout << cur_i+1 << ' ' << n-i << ' ' << max(n-i-1, 1) << ' ' << max(cur_i, 1) << ' ';
  }
}