Submission #1114968

# Submission time Handle Problem Language Result Execution time Memory
1114968 2024-11-19T21:14:23 Z Marco_Escandon Rice Hub (IOI11_ricehub) C++11
0 / 100
19 ms 4300 KB
#include "ricehub.h"

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
 
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
struct st{
    vector<ll> cad;
    void update(ll a, ll b)
    {
        for(a; a<cad.size(); a+=(a&-a)) cad[a]+=b;
    }
    ll query(ll a)
    {
        ll s=0;
        for(a; a>0; a-=(a&-a)) s+=cad[a];
        return s;
    }
    ll query(ll a, ll b) {return query(b)-query(a-1);}
    st(ll n){ cad.resize(n+5);}
}asd(300000);
int besthub(int R, int L, int X[], long long B)
{
    ll n=R,k=B,c=1;
    ordered_set s;
    ll cad[n];
    vector<ll>asdf;
    map<ll,ll> mapa;
    for(int i=0; i<n; i++)
    {
        cin>>cad[i];        
        asdf.push_back(cad[i]);
    }
    sort(asdf.begin(),asdf.end());
    for(auto i:asdf){if(mapa[i]==0){mapa[i]=c++;}}
    ll z=0;
    ll bs=0;
    for(int i=0; i<n; i++)
    {
        s.insert(cad[i]);
        asd.update(mapa[cad[i]],cad[i]);
 
        ll mediana = *s.find_by_order((s.size()-1)/2);
        ll temp=s.order_of_key(mediana);
        
        while(temp*mediana-asd.query(mapa[mediana]-1)+asd.query(mapa[mediana],300000)-(s.size()-temp)*mediana>k)
        {
            s.erase(s.find_by_order(s.order_of_key(cad[z])));
            asd.update(mapa[cad[z]],-cad[z]);
            z++;
            mediana = *s.find_by_order((s.size()-1)/2);
            temp=s.order_of_key(mediana);
        }
        //cerr<<temp*mediana-asd.query(mapa[mediana]-1)+asd.query(mapa[mediana],300000)-(s.size()-temp)*mediana<<" ";
        //cerr<<z<<" "<<i<<"\n";
        bs=max(bs,(ll)s.size());
    }
    return (int)bs;
}

Compilation message

ricehub.cpp: In member function 'void st::update(ll, ll)':
ricehub.cpp:15:13: warning: statement has no effect [-Wunused-value]
   15 |         for(a; a<cad.size(); a+=(a&-a)) cad[a]+=b;
      |             ^
ricehub.cpp:15:17: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |         for(a; a<cad.size(); a+=(a&-a)) cad[a]+=b;
      |                ~^~~~~~~~~~~
ricehub.cpp: In member function 'll st::query(ll)':
ricehub.cpp:20:13: warning: statement has no effect [-Wunused-value]
   20 |         for(a; a>0; a-=(a&-a)) s+=cad[a];
      |             ^
ricehub.cpp: In function 'int besthub(int, int, int*, long long int)':
ricehub.cpp:50:110: warning: comparison of integer expressions of different signedness: 'long long unsigned int' and 'll' {aka 'long long int'} [-Wsign-compare]
   50 |         while(temp*mediana-asd.query(mapa[mediana]-1)+asd.query(mapa[mediana],300000)-(s.size()-temp)*mediana>k)
      |               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2640 KB Output is correct
2 Incorrect 1 ms 2640 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2640 KB Output is correct
2 Correct 1 ms 2808 KB Output is correct
3 Incorrect 2 ms 2640 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2808 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 19 ms 4300 KB Output isn't correct
2 Halted 0 ms 0 KB -