Submission #859962

#TimeUsernameProblemLanguageResultExecution timeMemory
859962Tenis0206The Potion of Great Power (CEOI20_potion)C++11
38 / 100
938 ms262144 KiB
#include <bits/stdc++.h>

using namespace std;

const int nmax = 1e5;
const int oo = 1e9;

int n;
int h[nmax + 5];

set<pair<int,int>> s;

vector<int> l;

/*struct Node
{
    Node *st, *dr;
    int val = 0;
    Node()
    {
        st = nullptr;
        dr = nullptr;
        val = 0;
    }
};

struct aint
{
    void update(Node *nod, int val, int nod, int a, int b)
    {
        if(a==b)
        {

        }
    }
    void update_per(int poz, int val, int nr)
    {
        pair<int, *Node> val = {nr, new Node};
        if(r.size())
        {
            val.second -> st = r.back() -> st;
            val.second -> dr = r.back() -> dr;
            val.second -> val = r.back() -> val;
        }
        r.push_back(val);
        update(r.back().second, val, 1,1,n);
    }
};

*/

struct idk
{
    vector<pair<int,set<int>>> r;
    void update_per(int poz, int val, int nr)
    {
        set<int> aux;
        pair<int, set<int> > cur = {nr, aux};
        if(r.size())
        {
            cur.second = r.back().second;
        }
        if(val==0)
        {
            auto it = cur.second.lower_bound(poz);
            cur.second.erase(it);
        }
        else
        {
            cur.second.insert(poz);
        }
        r.push_back(cur);
    }
    void find_friends(int v)
    {
        l.clear();
        int st = 0;
        int dr = r.size() - 1;
        int poz = -1;
        while(st<=dr)
        {
            int mij = (st + dr) >> 1;
            if(r[mij].first <= v)
            {
                poz = mij;
                st = mij + 1;
            }
            else
            {
                dr = mij - 1;
            }
        }
        if(poz==-1)
        {
            return;
        }
        for(auto it=r[poz].second.begin();it!=r[poz].second.end();it++)
        {
            l.push_back(*it);
        }
    }
} ai[nmax + 5];

void init(int N, int D, int H[])
{
    n = N;
    for(int i=0; i<n; i++)
    {
        h[i] = H[i];
    }
}

void curseChanges(int U, int A[], int B[])
{
    for(int i=0; i<U; i++)
    {
        int x = A[i];
        int y = B[i];
        if(x > y)
        {
            swap(x,y);
        }
        if(s.find({x,y})==s.end())
        {
            s.insert({x,y});
            ai[x].update_per(y,+1,i + 1);
            ai[y].update_per(x,+1,i + 1);
        }
        else
        {
            auto it = s.find({x,y});
            s.erase(it);
            ai[x].update_per(y,0,i + 1);
            ai[y].update_per(x,0,i + 1);
        }
    }
}

int question(int x, int y, int v)
{
    ai[x].find_friends(v);
    vector<int> vx;
    for(auto it : l)
    {
        vx.push_back(h[it]);
    }
    ai[y].find_friends(v);
    vector<int> vy;
    for(auto it : l)
    {
        vy.push_back(h[it]);
    }
    sort(vx.begin(),vx.end());
    sort(vy.begin(),vy.end());
    int rez = oo;
    int poz = 0;
    for(int i=0;i<vx.size();i++)
    {
        while(poz < vy.size() && vy[poz] < vx[i])
        {
            ++poz;
        }
        if(poz >= vy.size())
        {
            break;
        }
        rez = min(rez, vy[poz] - vx[i]);
    }
    poz = 0;
    for(int i=0;i<vy.size();i++)
    {
        while(poz < vx.size() && vx[poz] < vy[i])
        {
            ++poz;
        }
        if(poz >= vx.size())
        {
            break;
        }
        rez = min(rez, vx[poz] - vy[i]);
    }
    return rez;
}

Compilation message (stderr)

potion.cpp: In function 'int question(int, int, int)':
potion.cpp:157:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  157 |     for(int i=0;i<vx.size();i++)
      |                 ~^~~~~~~~~~
potion.cpp:159:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  159 |         while(poz < vy.size() && vy[poz] < vx[i])
      |               ~~~~^~~~~~~~~~~
potion.cpp:163:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  163 |         if(poz >= vy.size())
      |            ~~~~^~~~~~~~~~~~
potion.cpp:170:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  170 |     for(int i=0;i<vy.size();i++)
      |                 ~^~~~~~~~~~
potion.cpp:172:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  172 |         while(poz < vx.size() && vx[poz] < vy[i])
      |               ~~~~^~~~~~~~~~~
potion.cpp:176:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  176 |         if(poz >= vx.size())
      |            ~~~~^~~~~~~~~~~~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...