Submission #957970

# Submission time Handle Problem Language Result Execution time Memory
957970 2024-04-04T15:17:28 Z Nika533 Rice Hub (IOI11_ricehub) C++14
Compilation error
0 ms 0 KB
#pragma GCC diagnostic warning "-std=c++11"
#include <bits/stdc++.h>
#include "ricehub.h"
#define pb push_back
#define f first
#define s second
#define MOD 1000000007
#define flush fflush(stdout)
#define all(x) (x).begin(),(x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define pii pair<int,int>
using namespace std;
int m,T,k;

int besthub(int n, int L, int X[], long long B){
	set<pair<long long,long long>> s;
	long long pref[n+1]; pref[0]=0;
	for (int i=0; i<n; i++) {
		s.insert({X[i],i});
		pref[i+1]=pref[i]+X[i];
	}
	int ans=0;
	for (int i=0; i<n; i++) {
		int l=0,r=L+5,val;
		while (l<=r) {
			int mid=(l+r)/2;
			set<pii> :: iterator it2=s.upper_bound({X[i]+mid,n}),it1=s.lower_bound({X[i]-mid,0});
			it2--;
			long long a=(*it1).s,b=(*it2).s;
			int num=b-a+1;
			long long sum=(pref[b+1]-pref[i+1])-(pref[i]-pref[a])-(b+a-2*i)*X[i];
			if (sum<=B) {
				l=mid+1; val=num;
			}
			else {
				r=mid-1;
			}
			//cout<<"MID "<<mid<<" "<<num<<" "<<sum<<" "<<a<<" "<<b<<" "<<c<<" "<<d<<endl;
		} 
		//cout<<"I "<<val<<endl;
		ans=max(ans,val);
	}
	return ans;
}

Compilation message

ricehub.cpp:1:32: warning: '-std=c++11' is not an option that controls warnings [-Wpragmas]
    1 | #pragma GCC diagnostic warning "-std=c++11"
      |                                ^~~~~~~~~~~~
ricehub.cpp: In function 'int besthub(int, int, int*, long long int)':
ricehub.cpp:27:42: error: conversion from '_Rb_tree_const_iterator<pair<long long int,long long int>>' to non-scalar type '_Rb_tree_const_iterator<pair<int,int>>' requested
   27 |    set<pii> :: iterator it2=s.upper_bound({X[i]+mid,n}),it1=s.lower_bound({X[i]-mid,0});
      |                                          ^
ricehub.cpp:27:74: error: conversion from '_Rb_tree_const_iterator<pair<long long int,long long int>>' to non-scalar type '_Rb_tree_const_iterator<pair<int,int>>' requested
   27 |    set<pii> :: iterator it2=s.upper_bound({X[i]+mid,n}),it1=s.lower_bound({X[i]-mid,0});
      |                                                                          ^