Submission #777854

#TimeUsernameProblemLanguageResultExecution timeMemory
777854OrazBXylophone (JOI18_xylophone)C++17
100 / 100
68 ms384 KiB
#include <bits/stdc++.h>
#include "xylophone.h"
using namespace std;
#define wr cout << "Continue debugging\n";
#define all(x) (x).begin(), (x).end()
#define ll long long int
#define pii pair <int, int>
#define pb push_back
#define ff first
#define ss second

int F(int n){
	int l = 1, r = n-1, pos;
	while(l <= r){
		int md = (l+r)>>1;
		int x = query(md, n);
		if (x != n-1) r = md - 1;
		else{
			pos = md;
			l = md + 1;
		}
	}
	return pos;
}

void solve(int n){
	int pos = F(n);
	vector<int> a(n+1), vis(n+2, 0);
	vis[1] = 1;
	a[pos] = 1;
	a[pos+1] = 1+query(pos, pos+1);
	vis[a[pos+1]] = 1;
	if (pos > 1){
		a[pos-1] = 1+query(pos-1, pos);
		vis[a[pos-1]] = 1;
	}
	for (int i = pos-2; i >= 1; i--){
		a[i] = a[i+1];
		int x = query(i, i+1);
		if (a[i]+x > n or vis[a[i]+x]){a[i] -= x; vis[a[i]] = 1; continue;}
		if (a[i]-x <= 0 or vis[a[i]-x]){a[i] += x; vis[a[i]] = 1; continue;} 
		int y = query(i, i+2);
		if (x == y){
			if (a[i+1] > a[i+2]) a[i] -= x;
			else a[i] += x;
		}else{
			if (abs(a[i+1]-a[i+2]) != y){
				if (a[i+1] > a[i+2]) a[i] += x;
				else a[i] -= x;
			}else{
				if (a[i+1] > a[i+2]) a[i] -= x;
				else a[i] += x;
			}
		}
		vis[a[i]] = 1;
	}
	for (int i = pos+2; i <= n; i++){
		a[i] = a[i-1];
		int x = query(i-1, i);
		if (a[i]+x > n or vis[a[i]+x]){a[i] -= x;continue;}
		if (a[i]-x <= 0 or vis[a[i]-x]){a[i] += x;continue;}
		int y = query(i-2, i);
		if (x == y){
			if (a[i-1] > a[i-2]) a[i] -= x;
			else a[i] += x;
		}else{
			if (abs(a[i-1]-a[i-2]) != y){
				if (a[i-1] > a[i-2]) a[i] += x;
				else a[i] -= x;
			}else{
				if (a[i-1] > a[i-2]) a[i] -= x;
				else a[i] += x;
			}
		}
		vis[a[i]] = 1;
	}
	for (int i = 1; i <= n; i++) answer(i, a[i]);
}

Compilation message (stderr)

xylophone.cpp: In function 'int F(int)':
xylophone.cpp:23:9: warning: 'pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
   23 |  return pos;
      |         ^~~
xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:34:21: warning: 'pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
   34 |   a[pos-1] = 1+query(pos-1, pos);
      |                ~~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...