Submission #859962

# Submission time Handle Problem Language Result Execution time Memory
859962 2023-10-11T08:56:50 Z Tenis0206 The Potion of Great Power (CEOI20_potion) C++11
38 / 100
938 ms 262144 KB
#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

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 time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3156 KB Output is correct
2 Correct 3 ms 3160 KB Output is correct
3 Correct 2 ms 3160 KB Output is correct
4 Correct 10 ms 4160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 561 ms 100820 KB Output is correct
2 Correct 629 ms 101012 KB Output is correct
3 Correct 862 ms 205892 KB Output is correct
4 Runtime error 432 ms 262144 KB Execution killed with signal 9
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 590 ms 101008 KB Output is correct
2 Runtime error 460 ms 262144 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 43 ms 6492 KB Output is correct
2 Correct 93 ms 12532 KB Output is correct
3 Correct 131 ms 13904 KB Output is correct
4 Correct 938 ms 67724 KB Output is correct
5 Correct 884 ms 51468 KB Output is correct
6 Correct 122 ms 15080 KB Output is correct
7 Correct 753 ms 58176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 2 ms 3156 KB Output is correct
3 Correct 3 ms 3160 KB Output is correct
4 Correct 2 ms 3160 KB Output is correct
5 Correct 10 ms 4160 KB Output is correct
6 Correct 561 ms 100820 KB Output is correct
7 Correct 629 ms 101012 KB Output is correct
8 Correct 862 ms 205892 KB Output is correct
9 Runtime error 432 ms 262144 KB Execution killed with signal 9
10 Halted 0 ms 0 KB -