Submission #294600

#TimeUsernameProblemLanguageResultExecution timeMemory
294600DovranMeetings (IOI18_meetings)C++11
0 / 100
0 ms384 KiB
#include <bits/stdc++.h>
#include "meetings.h"
#define N 100009
#define LL 1000000009
#define pii pair <int, int>
#define ff first
#define ss second
#define sz size
#define pb push_back
#define ll long long

using namespace std;

int n, t[N], c[N], v[N];

void gur(int nd, int l, int r){
	if(l==r){
		t[nd]=v[l];
		return;
	}
	
	int md=(l+r)/2;
	gur(nd*2, l, md);
	gur(nd*2+1, md+1, r);

	t[nd]=max(t[nd*2], t[nd*2+1]);
}

int tap(int nd, int l, int r, int x, int y){
	if(l>=x and r<=y)
		return t[nd];
	if(l>y or r<x) return 0;

	int md=(l+r)/2;
	return max(tap(nd*2, l, md, x, y), tap(nd*2+1, md+1, r, x, y));
}

std::vector<ll> minimum_costs(std::vector<int>H, std::vector<int>L, std::vector<int>R){
	n=H.sz();
	for(int i=0; i<n; i++)
		v[i]=H[i];
	gur(1, 0, n-1);
	vector<ll>e;
	for(int i=0; i<L.sz(); i++){
		int l=L[i], r=R[i];
		for(int j=0; j<n; j++)
			c[j]=1e9;
		for(int j=l; j<=r; j++){
			int ans=0;
			for(int h=l; h<=r; h++){
				if(h<=j) ans+=tap(1, 0, n-1, h, j);
				else ans+=tap(1, 0, n-1, j, h);
			}
			c[j]=ans;
		}
		int mn=1e9, in;
		for(int h=0; h<n; h++){
			mn=min(mn, c[h]);
			if(mn==c[h])
				in=h;
		}
		e.pb(in);
	}
	return e;
}

Compilation message (stderr)

meetings.cpp: In function 'std::vector<long long int> minimum_costs(std::vector<int>, std::vector<int>, std::vector<int>)':
meetings.cpp:44:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |  for(int i=0; i<L.sz(); i++){
      |               ~^~~~~~~
meetings.cpp:62:8: warning: 'in' may be used uninitialized in this function [-Wmaybe-uninitialized]
   62 |   e.pb(in);
      |        ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...